问题标签 [machine.fakes]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 如何使用 Machine.Fakes (Moq) 模拟 Func<>?
我正在尝试测试我编写的一些代码在尝试使用 Machine.Fakes (在后台使用 Moq)模拟 func 时遇到问题。有关示例,请参见下面的代码。
测试就在这里
我得到了一个不受支持的上述表达式,所以我将 where 方法更改IMessageRouters
为以下内容:
现在我得到这个错误
对象实例不是由 Moq 创建的。
参数名称:模拟
有任何想法吗?
编辑
所以我尝试编写另一个没有 machine.fakes 的测试,根据Mocking 方法使用 Expression<Func<T,bool>> 参数使用 Moq。事实证明这是一个明显的问题。真实 RoutingEngine 中使用的 func 未被模拟
以上与在运行时执行的 Where 无关,并且不能因为 func 在编译时被编译为私有方法。似乎要模拟函数,我需要将其推送到界面。闻起来,因为我纯粹为了测试而推动内部行为。
entity-framework-6 - 使用 machine.fakes 模拟多个接口
我怎样才能获得相当于
用 machine.fakes?我尝试使用
但我得到以下 NotImplementedException:
myFake.WhenToldTo(m => ((IQueryable)m).Provider).Return(whatever); 引发相同的异常。
这是一个用最少的代码重现问题的类。您需要为实体框架、Machine.Specifications、Machie.Specifications.Should、Machine.Fakes、Machine.Fakes.NSubstitute、NSubstitute(或任何其他 Mock Framework 插件)添加包