I have just started using NSubstitute
. I mostly worked with Moq
, and this is what i was doing:
// In my unit test on menter code herey mock:
HasLogMessage(Is.EqualTo("expected value"));
private void HasLogMessage(EqualConstraint s)
{
log.Verify(y => y.Error(It.Is<string>(v => Verify(v, s))));
}
private bool Verify(string s, EqualConstraint equalConstraint)
{
Assert.That(s, equalConstraint);
return true;
}
Output when unit test is run. Note that it tells what expected and real value is:
Expected string length 14 but was 116. Strings differ at index 0.
Expected: "expected value"
But was: "real value..."
-----------^
at NUnit.Framework.Assert.That(Object actual,
IResolveConstraint expression, String message, Object[] args)
I want to be able to use that with NSubstitute
mocks, and here's my attempt at this:
HasLogMessage(Is.EqualTo("Expected value"));
private void HasLogMessage(EqualConstraint s)
{
log.Received().Log(LogLevel.Error, Arg.Is<Func<string>>(x => Verify(x,
}
private bool Verify(Func<string> s, EqualConstraint equalConstraint)
{
Assert.That(s(), equalConstraint);
return true;
}
But this does not output NUnit
assertion error
NSubstitute.Exceptions.ReceivedCallsException : Expected to receive a call matching:
Log(Error, x => value(IdentityServer3.Saml2Bearer.Tests.Saml2BearerGrantValidatorTest)
.Verify(x, value(IdentityServer3.Saml2Bearer.Tests.Saml2BearerGrantValidatorTest+<>c__DisplayClass21_0).s), <null>, )
Actually received no matching calls.
Received 2 non-matching calls (non-matching arguments indicated
with '*' characters)
Am I missing something here?