为什么从F#调用Moq会引发异常?

为什么从F#调用Moq会引发异常?,f#,moq,F#,Moq,我相信这与Verify()上的times参数的使用有关 打开NUnit.Framework 开放式最小起订量 类型IService=抽象成员DoStuff:unit->unit [] 让``为什么这会引发异常?`()= 让mockService=Mock() mockService.Verify(fun s->s.DoStuff(),Times.Never()) 异常消息: System.ArgumentException:类型为“System.Void”的表达式不能用于类型为“Microso

我相信这与
Verify()
上的
times
参数的使用有关

打开NUnit.Framework
开放式最小起订量
类型IService=抽象成员DoStuff:unit->unit
[]
让``为什么这会引发异常?`()=
让mockService=Mock()
mockService.Verify(fun s->s.DoStuff(),Times.Never())
异常消息:

System.ArgumentException:类型为“System.Void”的表达式不能用于类型为“Microsoft.FSharp.Core.Unit”的构造函数参数


Moq的
Verify
方法有许多重载,并且在没有注释的情况下,F#将默认解析指定给重载的表达式,期望使用
func。我想您的意思是nuget包添加了VerifyFunc和VerifyAction扩展方法,而不是重载。
open NUnit.Framework
open Moq

type IService = abstract member DoStuff : unit -> unit

[<Test>]
let ``Why does this throw an exception?``() =
    let mockService = Mock<IService>()
    mockService.Verify(fun s -> s.DoStuff(), Times.Never())
open NUnit.Framework
open Moq
open Moq.FSharp.Extensions

type IService = abstract member DoStuff : unit -> unit

[<Test>]
let ``Why does this throw an exception?``() =
   let mockService = Mock<IService>()
   mockService.VerifyAction((fun s -> s.DoStuff()), Times.Never())
open Foq

[<Test>]
let ``No worries`` () =
  let mock = Mock.Of<IService>()
  Mock.Verify(<@ mock.DoStuff() @>, never)