I am having trouble with NSubstitute when I am running a suite of tests. I intermittently receives the NSubstitute.Exceptions.RedundantArgumentMatcherException: Some argument specifications (e.g. Arg.Is, Arg.Any) were left over after the last call.
As this particular suite only contains the below two unit tests I cannot see i what way I can have these troubles.
public class MyResolverTests
{
private readonly MyResolver _sut;
private readonly IObjectClient _objectClientMock;
public MyResolverTests()
{
_objectClientMock = Substitute.For<IObjectClient>();
_sut = new MyResolver(_objectClientMock);
}
[Fact]
public void IsApplicable_when_something_then_return_true()
{
//Arrange
var myEnum = MyEnum.Value1;
//Act
var result = _sut.IsApplicable(myEnum);
//Assert
Assert.True(result);
}
[Fact]
public async Task GetSomething_then_return_myobject()
{
//Arrange
_objectClientMock
.GetAsync<MyObject>(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<bool>(),
Arg.Any<bool>()).Returns(new MyObject()));
//Act
var result = await _sut.GetRepresentation(Guid.NewGuid());
//Assert
Assert.IsType<MyObject>(result);
}
}
Have I misunderstood the way it should be used? Is there an incorrect implementation above? From that we have been using MOQ without these troubles to this intermittent problem is disturbing.