NSubstitute is another mocking framework which performs similar purpose to Moq / FAkeItEasy and many more. The Good part of NSubstitute is , it avoids lambda expression in syntax where Moq , FakeItEasy family uses it.
Basically NSubstitute framework is best fit for TDD but you may use this at any point of unit testing. Let’s assume that here is our code which need to be test using NSubstitute.
public interface IService
public class Service : IService
public Service(IService service)
_tmpService = service;
public string MessageSend()
The code snippet is very simple, we are just injecting IService to Service class. Here is code for unit test.
public class UnitTestClass
public void Test_Function()
var substitute = Substitute.For<IService>();
Assert.AreEqual("fake data", substitute.MessageSend());
We are seeing that there is no lambda expression in code and very clean compare to other framework.