I have a data access interface looking roughly like this:
public interface IDataRepository
{
DatabaseResult<Customer> GetAllCustomers();
DatabaseResult<Report> GetAllReports();
DatabaseResult<Order> GetAllOrders();
[..] (there are many methods like this)
}
DatabaseResult
is a public class
that is used to attach some metadata to the returned information.
When I mock this interface I want every single method (I probably have > 100) to return an instance of DatabaseResult<WhatEverType>
. Currently I need to call SetReturnsDefault
for each type, e.g.
var mockDb = new Mock<IDataProvider>();
mockDb.SetReturnsDefault(new DatabaseResult<Customer>());
mockDb.SetReturnsDefault(new DatabaseResult<Report>());
mockDb.SetReturnsDefault(new DatabaseResult<Order>());
Is there a way to just tell Moq that when the return type of a method is DatabaseResult<SomeType>
then always return a new instance DatabaseResult<SomeType>
, regardless of what SomeType
is?