Search code examples
c#.netunit-testingtddrhino-mocks

Can I set a user friendly message to be shown when AssertWasCalled fails, in Rhino Mocks?


Can I write the following assert on the mock object, in a way that it shows "UnBookFlight was not called with proper parameters or not even called" in case the assert fails?

mockBookingService
              .AssertWasCalled(ms=>ms.UnBookFlight(Arg<DateTime>.Is.Equal(dummyDate)));

Solution

  • According to this article, you can specify a message in the method options passed to AssertWasCalled():

    mockBookingService.AssertWasCalled(
        ms => ms.UnBookFlight(Arg<DateTime>.Is.Equal(dummyDate)),
        options => {
            options.Message("UnBookFlight was not called with proper parameters or not even called");
        });