Mock repository

Instead of having mock objects creation code scattered across your tests, you can avoid repetitive code by using MockRepository, available in Moq for creating and verifying mocks in a single location, thereby ensuring that you can do mock configuration by setting CallBase, DefaultValue, and MockBehavior and verifying the the mocks in one place:

var mockRepository = new MockRepository(MockBehavior.Strict) { DefaultValue = DefaultValue.Mock };var loanRepository = repository.Create<ILoanRepository>(MockBehavior.Loose);var userRepository = repository.Create<IUserRepository>();mockRepository.Verify();

In the preceding code snippet, a mock repository is created with MockBehaviour.Strict, and two mock objects are created, each with ...

Get C# and .NET Core Test Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.