Search code examples
c#unit-testingrhino-mocks

AssertWasCalled in rhino mocks


I have an object under test that makes a fairly complicated call to a data access object. IT looks something like

object.DoSomething(somestring,someObject,someOtherObject,someOtherOtherObject)

In my test structure I have a mocked version of object and I want to test that Dosomething got called with somestring == "value1" and someObject.porpertyA == "value2".

I can't use the simple AssertWasCalled() overload because I don;t know about (or care about) someOtherObject. I notice another overload that takes an an action for setup constraints, but I've never seen it used.


Solution

  • Piece of cake:

    yourstub.AssertWasCalled(
                 x => x.DoSomething(
                    Arg<string>.Is.Equal("value1"), 
                    Arg<someObjectType>.Is.Equal(value2), 
                    Arg<someOtherObjectType>.Is.Anything,   <======== NOTE THIS!
                    Arg<someOtherOtherObjectType>.Is.Equal(value3)
                 )
    );