views:

132

answers:

1

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));  
}
+2  A: 

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

Matt Warren
Perfect! Just what I needed :-)
stiank81
For others which might need this - note that using this you need to use Arg<T> for all arguments. Which means I need to use on the first argument: Arg<int>.Equal(123).
stiank81
Oh yeah, I forgot about that, thanks for adding it in.
Matt Warren