Context is the enemy of testability. In this tip, I demonstrate how you can eliminate, once and for all, the HTTP Context from an ASP.NET MVC application.
A controller action that interacts only with the set of parameters passed to it is very easy to test. For example, consider the following simple controller action:
VB.NET Version
Public Function InsertCustomer(ByVal firstName As String, ByVal lastName As String, ByVal favoriteColor As String) As ActionResult
CustomerRepository.CreateCustomer(firstName, lastName, favoriteColor)
Return View()
End Function
C# Version
public ActionResult InsertCustomer(string firstName, string lastName, string favoriteColor)
{
CustomerRepository.CreateCustomer(firstName, lastName, favoriteColor); ...