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

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

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