"Cannot call Isolate.Verify.WasCalledWithArguments without a closing Matching function"

0 votes
I have read everything that popped up in Google on the forum here for this exception: "Cannot call Isolate.Verify.WasCalledWithArguments without a closing Matching function". However, I think I did everything described in the documentation.
The exception is thrown only when I run all of my tests. One by one they are passing. Initially, I forgot to include the Isolated attribute. However, all of my classes have it now. I tried different combinations- I set it on all methods, on all classes, instead of it I called Isolate.CleanUp at the beginning of the test or the end. However, the result is the same from 45 tests always from 3-5 are failing.
There are tests that I use Isolate.Verify.WasCalledWithAnyArguments but half of them call simple NUnit Asserts. Almost all of the tests are mocking static methods. I guess it is possible the problem to come from there.
Any help will be much appreciated.  We are still evaluating the framework, and if I cannot execute the most simple our scenarios, I don't see a point to purchase it.
Example for one of the failing tests:
public void PassSameParametersToSomeMethod_WhenMessageNotNull()
    var status = Fixture.Create<int>(); //generates random int
    var message = Fixture.Create<string>();
    var fake = Isolate.Fake.NextInstance<SomeOfMyClasses1>();
    SomeOfMyClasses2.InsertIncorrectName(tenant, message); // calls a static method that creates an instance from SomeOfMyClasses1 and calls a method
    Isolate.Verify.WasCalledWithArguments(() => fake.SomeMethod(status, message));
asked May 31 by angelovstanton (160 points)

1 Answer

+1 vote
Best answer

Hi Anton,

The API you probrably need is
Or use
Isolate.Verify.WasCalledWithArgument(()=>...).Matching(a => ...)
See here
answered Jun 4 by Daniel (1,340 points)
selected Jun 5 by angelovstanton
You are correct. The problem was with this method. However, I think it is a poor design in the framework. Since the exception was thrown in a different test where I didn't use the aftermentioned method. Anyway, I managed to fix my tests.