Skip to Content
C# and .NET Core Test-Driven Development
book

C# and .NET Core Test-Driven Development

by Ayobami Adewole
May 2018
Intermediate to advanced content levelIntermediate to advanced
300 pages
7h 35m
English
Packt Publishing
Content preview from C# and .NET Core Test-Driven Development

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Design Patterns with C# and .NET Core

Hands-On Design Patterns with C# and .NET Core

Gaurav Aroraa, Jeffrey Chilberto
.NET Core in Action

.NET Core in Action

Dustin Metzgar

Publisher Resources

ISBN: 9781788292481Supplemental Content