I'm familiar with unit testing, but am still learning about mocks and mocking frameworks. I get the ideas (I think), but the syntax still seems a little foreign. I'm considering creating some T4 templates that automatically generate mock implementations of interfaces and classes. Using a combination of generics and extension methods, this would let me do things like this:
var service = new MockCustomerService(); //code-generated and implements ICustomerService, has a method named 'Insert'
var target = new CustomerController(service);
var item = new Customer();
target.Insert(item);
service.InsertMethod.Assert.WasLastCalledWith(item);
or:
var service = new MockCustomerService(); //code-generated and implements ICustomerService, has a method named 'GetById'
var target = new CustomerController(service);
var item = new Customer();
target.GetByIdMethod.ShouldReturn(item);
var actual = target.Edit(1);
service.GetByIdMethod.Assert.WasLastCalledWith(1);
Assert.AreEqual(actual.ViewData.Model, item);
First, is this even really "mocking", or am I missing something fundamental. Second, does this seem like it would be a sound approach, or are there reasons for using a framework beyond not having to manually create similar classes? Third, is there anything else out there that does similar? I've looked around and haven't found much...