I've got a controller class which accpets multiple parameters in the ctor which gets injected at runtime.
Example:
public ProductController(IProductRepositort productRepository,
IShippingService shippingService, IEmailProvider emailProvider)
{
...
}
I am finding that the Test methods are getting huge. I am setting up the methods as follows:
[Test]
public void CanSendProduct()
{
//Code to set up stub
List<Product> products = new List<Product>();
for (int i = 0; i < length; i++)
{
products.Add(new Product()));
}
var mockProductRepository = new Mock<IProductRepository>();
mockProductRepository.Setup(x => x.GetProducts()).Returns(products);
//Code to set up stub
....
....
var mockShippingService = new Mock<IShippingService>();
mockShippingService.Setup(x => x.GetShippers()).Returns(shippers);
//Code to set up stub
.....
.....
var mockEmailProvider = new Mock<IEmailProvider>();
mockEmailProvider.Setup(x => x.Send()).Returns(provider);
//Execute Test
....
....
//Assert
....
....
}
Obviously, it not practical to repeat the mock setup in every method of this test class.
How can i create rich mocking objects that enables me to do Behavioural verification of my tests and at the same time minimise the setup pain?
What are the TDD best practices to deal with this problem?
Thanks