Mocking methods, properties, and callback

Before the methods of the mock objects can be used in the test, they need to be set up. This setup is preferably done in the constructor of the test class after the mock object is created and before the object is injected into the class that requires the dependency.

First, the data to be returned by the method to be set up will have to be created; this is the dummy data to be used in the test:

List<Loan> loans = new List<Loan>{    new Loan{Amount = 120000, Rate = 12.5, ServiceYear = 5, HasDefaulted = false },    new Loan {Amount = 150000, Rate = 12.5, ServiceYear = 4, HasDefaulted = true },    new Loan { Amount = 200000, Rate = 12.5, ServiceYear = 5, HasDefaulted = false }};

At the point of setting up the ...

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.