g.p*_*dou 3 c# unit-testing mocking nsubstitute
语境
我想检查当使用单个参数调用我的替代方法时,某些参数属性值是否是预期的。
最简单的方法是拥有作为参数的实例,然后根据预期检查其某些属性。
我已经检查了页面http://nsubstitute.github.io/help/received-calls/,但我既找不到如何获取实际参数,也找不到这样的检查条件。
问题
var sut = new MyObject(myNSubstitue)
sut.Execute()
// Let suppose mySubstitute has an OperationX(MyClass parameter) method
// Now I would like to check OperationX was called, and called with
// a parameter which's parameter.MyPropery == "Hello"
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
使用Received()断言和参数匹配来检查传递给OperationX的MyClass的属性:
mySubstitute.Received().OperationX(Arg.Is<MyClass>(mc => mc.MyProperty == "Hello"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1593 次 |
| 最近记录: |