Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

c# - RhinoMocks - Not specifying all parameters in AssertWasCalled

I am using RhinoMocks. Now I want to assert that some function was called, but I only care about one of the arguments. Can I do a AssertWasCalled where I only specify one argument?

In the following example I'd like the ignore what was sent to the second argument of SomeOtherFunction(). I.e. I want to check that SomeOtherFunction was called with first parameter 123 and I don't care what the second parameter was.

[Test]
public void SomeTest()
{
    var myMock = MockRepository.GenerateMock<ISomeInterface>();    
    var myObj = new MyClass(myMock); 
    myObj.foo()

    myMock.AssertWasCalled(factory => factory.SomeOtherFunction(123, null));  
}
question from:https://stackoverflow.com/questions/1946904/rhinomocks-not-specifying-all-parameters-in-assertwascalled

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can specify the 2nd argument as Arg<T>.Is.Anything, then the actual value gets ignored.

However note that using this you need to use Arg for all arguments. Which means you need to use on the first argument: Arg<int>.Is.Equal(123).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...