Search code examples
c#unit-testingtddrhino-mocks

How to remove parameter constraint definitons to a variable so that Asserts become less crowded in Rhino.Mocks?


How can I exlude the parameter constraints

Arg<DateTime>.Is.Equal(departureConstraint)
    Arg<DateTime>.Is.Equal(arrivalConstraint)

from the assert below

mockBookingService.AssertWasCalled(
                m =>
                m.BookShuttle(Arg<DateTime>.Is.Equal(departure)

, Arg<DateTime>.Is.Equal(arrival)));

so that I can re-write it in a more friendly way like:

mockBookingService.AssertWasCalled(
                m =>
                m.BookShuttle(departureConstraint, arrivalConstraint));

Solution

  • There's a more succinct syntax you can use:

    Arg.Is(departureConstraint)
    
    mockBookingService.AssertWasCalled(m =>
                m.BookShuttle(Arg.Is(departure), Arg.Is(arrivalConstraint)));
    

    Or, since you have actual values for all of your parameters, You can just remove the parameter constraints altogether.

    mockBookingService.AssertWasCalled(m =>
                m.BookShuttle(departure, arrivalConstraint));