[ Web Proxy ]
URL:
Viewing: https://nsubstitute.github.io/ [Back]  [Original]

A friendly substitute for .NET mocking libraries | NSubstitute
NSubstitute [NSubstitute] NSubstitute

Simple, succinct, pleasant to use

//Create:
var calculator = Substitute.For<ICalculator>();

//Set a return value:
calculator.Add(1, 2).Returns(3);
Assert.That(calculator.Add(1, 2), Is.EqualTo(3));

//Check received calls:
calculator.Received().Add(1, Arg.Any<int>());
calculator.DidNotReceive().Add(2, 2);

//Raise events
calculator.PoweringUp += Raise.Event();

Helpful exceptions

ReceivedCallsException : Expected to receive a call matching:
    Add(1, 2)
Actually received no matching calls.
Received 2 non-matching calls (non-matching arguments indicated with '*' characters):
    Add(*4*, *7*)
    Add(1, *5*)
Edit this page
Made with docfx

Web Proxy Viewer  |  New URL  |  Original Page