I want to write a TaskController for an ASP.NET MVC 3 application to perform some lengthy tasks, such as sending out a newsletter to site users. I thought using AsyncController would be appropriate since sending emails might take some time, and I want to keep some state in the database when the task completes.
Being a properly trained developer who I (: รพ), and being really in BDD, I naturally want to start with the specification using MSpec.
Imagine my controller looks like this:
public class TaskController : AsyncController { readonly ISession _session; public TaskController(ISession session) { _session = session; } public void SendMailAsync() {
How can I write specifications for AsyncControllers? Imagine starting with the following specification:
public class TaskControllerContext { protected static Mock<ISession> session; protected static TaskController controller; protected static ActionResult result; } [Subject(typeof(TaskController), "sending email")] public class When_there_is_mail_to_be_sent : TaskControllerContext { Establish context = () => { session = new Mock<ISession>(); controller = new TaskController(session.Object); };
Should I call the SendMailAsync method for the test? I actually feel yucky. How can I get the result from SendMailCompleted ?
source share