Show actual calls when expected call is missing?

16 views
Skip to first unread message

Justin Chase

unread,
Feb 22, 2024, 9:43:03 AMFeb 22
to NSubstitute
I have a matcher for an expected call such as:

_logger.Received(1).Log(
LogLevel.Information,
Arg.Is<string>(x => x.Contains("has been disabled")),
Arg.Any<Exception?>()
);

But its throwing an error saying...

Error Message:
   NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching:
        Log(Information, x => x.Contains("has been disabled"), any Exception)
Actually received no matching calls.

The question / request here is that this is a fairly common failure scenario, something changes and the matcher no longer matches, but unlike an equality check there is no output printed about the actual value here, which would be incredibly useful. It would be very nice if in this scenario when no calls are matched, if a count actual calls was emitted (knowing if there was 0 calls or not is very useful) but if there was at least one calls to emit a sample of actual values, perhaps first last and random from the middle...

Just saying its very difficult to debug the issue in some cases where you don't have the actual values recieved to contrast the test with.

If its possible to configure this in NSubsitute already I would love to hear about it! Thanks.

David Tchepak

unread,
Apr 30, 2024, 9:03:46 AMApr 30
to NSubstitute
Hi Justin,

If there are actual calls to that member the actual value should be displayed.

For example:

    [Test]
    public void SampleOutput() {
        _something.Say("hello");
        _something.Received().Say(Arg.Is<string>(x => x.Contains("hi")));
    }
/*

  Error Message:
   NSubstitute.Exceptions.ReceivedCallsException : Expected to receive a call matching:
        Say(x => x.Contains("hi"))

Actually received no matching calls.
Received 1 non-matching call (non-matching arguments indicated with '*' characters):
        Say(*"hello"*)
*/
Reply all
Reply to author
Forward
0 new messages