Matching parameters

When using Moq to create mock objects, you can match arguments to ensure that the expected parameters are passed during a test. Using this feature, you can ascertain the validity of the arguments passed into a method while the method is called while being tested. This is applicable only to methods that have arguments and the matching will be done during the method setup.

Using Moq's It keyword, you can specify different expressions and validations for the method parameter during setup. Let's add a GetCarLoanDefaulters method definition to the ILoanRepository interface. The implementation in the LoanRepository class accepts an integer parameter, which is the service year for a loan and returns a list of car loan defaulters. ...

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.