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 customization

When using the Moq framework, you can further customize mock object, to enhance the effective unit testing experience. The MockBehavior enum can be passed into Moq's Mock object constructor to specify the behavior of the mock. The enum members are Default, Strict, and Loose:

loanRepository= new Mock<ILoanRepository>(MockBehavior.Loose);

When a Loose member is selected, the mock will not throw any exceptions. The default values will always be returned. This means null will be returned for reference types, and zero or empty arrays and enumerables will be returned for value types:

loanRepository= new Mock<ILoanRepository>(MockBehavior.Strict);

Selecting a Strict member will make the mock throw exceptions for every call on ...

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