1

Given an interface as follows:

interface ISomething
{
  void Method(int arg1, string arg2, double arg3, OtherType arg4);
}

Used in mocking with RhinoMocks

ISomething something = MockRepository.GenerateMock<ISomething>();

The only way I know to check this is never called in my test is as follows:

something.Expect(_ => _.Method(
 Arg<int>.Is.Anything,
 Arg<string>.Is.Anything,
 Arg<double>.Is.Anything,
 Arg<OtherType>.Is.Anything)
).Repeat.Never();

This is pretty ugly. Is there a shorter way to do this for the special case a method is not called at all?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • 2
    You could stub it to throw an exception. – Gabriel Negut Nov 10 '16 at 16:44
  • `someting.AssertWasNotCalled(s => s.Method(...))`? – Lee Nov 10 '16 at 16:59
  • There is no getting away of using the `Arg`. If having too many arguments is the problem then that mean that the problem is with the design of the method (Code smell). Issues with tests tend to reveal problems with code design. Clean code leads to clean unit tests – Nkosi Nov 10 '16 at 17:01
  • Possible duplicate of [RhinoMocks - Not specifying all parameters in AssertWasCalled](http://stackoverflow.com/questions/1946904/rhinomocks-not-specifying-all-parameters-in-assertwascalled) – Amittai Shapira Nov 30 '16 at 17:20

1 Answers1

0

Using IgnoreArguments() is faster than specifying each argument individually:

something.Expect(_ => _.Method(0, "", 0, null)).IgnoreArguments().Repeat.Never();
Pedro
  • 12,032
  • 4
  • 32
  • 45