Mocking Frameworks

Moq

Moq is intended to be simple to use, strongly typed (no magic strings!, and therefore full compiler-verified and refactoring-friendly) and minimalistic (while still fully functional!).

Example

var mockClientRepository = new Mock<IClientRepository>();

mockClientRepository
.Setup(m => m.SelectList())
.Returns(new List<ClientModel> { new ClientModel("Name", "Surname") });

~ then to inject pass as `mockClientRepository.Object`

~ if you dont care about the values in the `.Returns` you can also use `It`
.Returns(new List<ClientModel> { new ClientModel(It.IsAny<string>(), It.IsAny<string>()) });

Others

Leave a Reply