我有这样的界面
type IAppDatabase =
abstract Get<'T> : seq<Guid> -> Task<seq<'T>>
abstract Set<'T> : seq<'T> -> Task<bool>
abstract GetIds<'T> : unit -> Task<seq<Guid>>我试着像这样嘲弄
let results = seq [DT.Result (); DT.Result (); DT.Result ()]
let resultInfos = DT.Results results
let guids = seq [Guid.NewGuid(); Guid.NewGuid(); Guid.NewGuid()]
let taskGetIds = Task.Factory.StartNew<seq<Guid>>(fun () -> guids)
let taskSet = Task.Factory.StartNew<bool>(fun () -> true )
let taskGet = Task.Factory.StartNew<seq<DT.Result>>(fun () -> results)
let db = Mock<IAppDatabase>.With(fun x ->
<@
x.GetIds () --> taskGetIds
x.Get guids --> taskGet
x.Set results --> taskSet @>)我有这样的考试
let [<Test>] ``Set the resultInfos in de app database`` () =
let app = App (db) :> IApp
let res = app.Create resultInfos |> Async.RunSynchronously
verify <@db.Set results @> once
res |> should be Trueapp.Create函数用一个Async.AwaitTask调用db.Set。
这一切都很好,福克是伟大的。但是,验证会引发system.exception。Foq中的methodsMatch函数返回false,因为他expectedMethod有一个ParameterInfo.ParameterType of System.Collections.Generic.IEnumerable``1[Result],actual.Method有一个ParameterInfo.ParameterType of System.Collections.Generic.IEnumerable``1[T]。
我尝试过添加和删除类型参数,但没有效果。我需要接口中的paramenter (和Task)类型,因为它是由其他人在C#中实现的。
这是generateAddInvocation方法的问题,还是我调用了验证错误?
发布于 2013-09-30 21:38:54
这是当前Foq 1.1实现中的一个问题,因为针对泛型接口方法的验证失败。这个问题与generateAddInvocation方法有关,该方法在下面使用MethodBase.GetCurrentMethod记录每个被调用的方法。MethodBase.GetCurrentMethod返回泛型方法定义,当验证方法使用的代码引号接收类型参数时。
我已经应用了一个简单的修复程序:https://foq.codeplex.com/SourceControl/changeset/69435c83aabd
修复将是Foq 1.2的一部分。
https://stackoverflow.com/questions/19093585
复制相似问题