5

I'm using NUnit mocks and would like to specify that I expect a call but without saying what the arguments will be for example:

mock.ExpectAndReturn("Equals", true, ANY_ARGUMENT);

Obviously filling in the correct syntax instead of ANY_ARGUMENT.

Is there a way to do this?

If I specify no arguments - NUnit fails the test because it expected 0 arguments but received 1.

Nosrama
  • 14,530
  • 13
  • 49
  • 58

4 Answers4

2

Looking at version 2.5.2 of nunit.mocks.dll in Reflector, it doesn't appear there is a method that does what you are looking for. NUnit is open source, so one option is to get the code and add the feature.

Pedro
  • 12,032
  • 4
  • 32
  • 45
2

Yes there is a such a function in NUnit Mocks.

Instead of the ExpectAndReturn use SetReturnValue. First function, as it names tell you, you specify input object and return object. Last function just specify a return object for the specific function.

Use: interfaceMock.SetReturnValue("SomeRetrunFunction", someReturnFunction);

Peter Stegnar
  • 12,615
  • 12
  • 62
  • 80
1

Have you tried:

mock.SetReturnValue(true);
mock.Expect("Equals");
arzer
  • 11
  • 1
0

You can implement a new instance of IResolveConstraint that accepts anything and use that as a parameter in your test. NUnit treats instances of IResolveConstraint differently than any other object, using Assert.That, instead of Assert.AreEqual to verify its correctness.

Eg.

myMock.ExpectAndReturn("mockedMethod", argument1, new AcceptsAnythingConstraint())