我正在尝试模拟这种方法
Task<TResult> GetResultAsync<TResult>(Func<string, TResult> transformFunc)
Run Code Online (Sandbox Code Playgroud)
像这样
iMock.Setup(m => m.GetResultAsync(It.IsAny<Func<string, object>>())).ReturnsAsync(new { isPair = false });
Run Code Online (Sandbox Code Playgroud)
测试调用方法,将匿名类型传递给通用参数,例如:
instance.GetResultAsync(u => new {isPair = u == "something" }) //dont look at the function return because as generic could have diferent implementations in many case
Run Code Online (Sandbox Code Playgroud)
Moq从未将我的GetResultAsync方法与发送的参数匹配。
我正在使用Moq 4