Simple, succinct, pleasant to use
//Create: var calculator = Substitute.For<ICalculator>(); //Set a return value: calculator.Add(1, 2).Returns(3); Assert.AreEqual(3, calculator.Add(1, 2)); //Check received calls: calculator.Received().Add(1, Arg.Any<int>()); calculator.DidNotReceive().Add(2, 2); //Raise events calculator.PoweringUp += Raise.Event();
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*)
Don’t sweat the small stuff
Mock, stub, fake, spy, test double? Strict or loose? Nah, just substitute for the type you need!
NSubstitute is designed for Arrange-Act-Assert (AAA) testing, so you just need to arrange how it should work, then assert it received the calls you expected once you're done. Because you've got more important code to write than whether you need a mock or a stub.