简体   繁体   中英

How to get the called parameters with NSubstitute? (or at least assert against their properties)

Context

I would like to check if some parameter property value was the expected when my substite's method was called with a single parameter.

It would be the simplest to having the instance which was the parameter, then checking some of its properties against the expected.

I've checked the page http://nsubstitute.github.io/help/received-calls/ but I can not find neither how to get the actual parameter, neither such a check condition.

Question

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"

Missed I something?

使用Received()断言和参数匹配来检查传递给OperationX的MyClass属性:

mySubstitute.Received().OperationX(Arg.Is<MyClass>(mc => mc.MyProperty == "Hello"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM