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!).

1
2
3
4
5
6
7
8
9
using Moq;

var mockClientRepository = new Mock<IClientRepository>();

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

// then inject as `mockClientRepository.Object`

If the method being mocked (SelectList) has parameters you don’t care about then you can mock them with It.IsAny

1
2
It.IsAny<string>()
It.IsAny<int>()

Others