Hand-rolled mock

We can hand-roll a mock object to test the LoanService class. The mock object to be created will implement the ILoanRepository interface and will be used for the purpose of unit testing only since it is not needed in the production code. The mock object will return a list of Loan objects, which will simulate the actual call to the database:

public class LoanRepositoryMock : ILoanRepository{    public List<Loan> GetCarLoans()    {        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 }        };        return loans;    }}

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.