I was reading an article by Dino Esposito on how to test AsyncConrollers in ASP.NET MVC and in there he uses the \"Humble Object\" pattern, without going into much detail.>
I'd usually implement this kind of this as an Interface
- then you can use a mocking framework to stub it for testing, and an IoC framework to inject the correct implementation at runtime.
Here's an example from my current project:
public interface IUserInterface
{
string AskUserWhereToSaveFile(
string title,
FileType defaultFileType,
string defaultFileName = null,
params FileType[] otherOptions
);
string AskUserToSelectFileToLoad(
string title,
FileType defaultFileType,
params FileType[] fileTypes
);
void ShowError(string title, string details);
bool AskUserIfTheyWantToRetryAfter(string errorMessage);
}
My Controller then has a dependancy on IUserInterface rather than a concrete view, which allow me to replace user interactions with a stub for testing.