Properties

If you have a dependency that has properties to be set which are used in the method calls, you can set dummy values for such properties using the Moq SetupProperty method. Let's add two properties to the ILoanRepository interface, LoanType and Rate:

public interface ILoanRepository{   LoanType LoanType{get;set;}   float Rate {get;set;}       List<LoanType> GetLoanTypes();   List<Loan> GetCarLoans();}

With the Moq SetupProperty method, you can specify that the property should have a behavior, which in essence implies that whenever the property is requested, the value set in the SetupProperty method will be returned:

Mock<ILoanRepository> loanRepository = new Mock<ILoanRepository>();loanRepository.Setup(x => x.LoanType, LoanType.CarLoan);

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.