title: ASP.NET MVC tests with MSpec. Is this correct or needs refactoring?
body: <p>I'm new to MSpec and would like to know if the way I wrote my test for ASP.NET MVC is correct. The test passes but I don't really like the way it's written and it seems awkward. I'm certainly missing something.</p>
  
  <pre><code>public class AccountControllerTests3
  {
      protected static AccountController controller;
      static IFormsAuthenticationService formsService;
      static IMembershipService membershipService;
      protected static ActionResult result;
      protected static LogOnModel model;
  
      Establish context = () =&gt;
      {
          var controllerBuilder = new TestControllerBuilder();
  
          formsService = MockRepository.GenerateStub&lt;IFormsAuthenticationService&gt;();
          membershipService = MockRepository.GenerateStub&lt;IMembershipService&gt;();
          model = MockRepository.GenerateStub&lt;LogOnModel&gt;();
  
          controller =
              controllerBuilder.CreateController&lt;AccountController&gt;(new object[]
                                                                      {
                                                                          formsService,
                                                                          membershipService
                                                                      });
      };
  
      Because user_logs = () =&gt;
      {
          bool rememberMe = false;
  
          membershipService.Stub(
              x =&gt; x.ValidateUser("bdd", "mspec")).Return(true);
          formsService.Stub(x =&gt; x.SignIn("bdd", rememberMe));
  
          controller.ModelState.IsValid.ShouldBeTrue();
      };
  }
  
  [Subject(typeof(AccountController), "LogInTests")]
  public class When_logging_into_application_with_good_login_and_password : AccountControllerTests3
  {
      private It user_should_be_redirected_to_the_home_page = () =&gt;
                                                                  {
                                                                      model.UserName = "bdd";
                                                                      model.Password = "mspec";
  
                                                                      result = controller.LogOn(model, string.Empty);
  
                                                                      result.AssertActionRedirect().ToAction&lt;HomeController&gt;(
                                                                          x =&gt; x.Index());
                                                                  };
  }
  
  [Subject(typeof(AccountController), "LogInTests")]
  public class When_logging_into_application_with_bad_login_and_password : AccountControllerTests3
  {
      It The_error_message_should_be_shown = () =&gt;
                                              {
                                                  model.UserName = "BAD";
                                                  model.Password = "BAD";
  
                                                  result = controller.LogOn(model, string.Empty);
  
                                                  controller.ModelState[""].Errors[0].ErrorMessage.ShouldEqual(
                                                      "The user name or password provided is incorrect.");
                                              };
  }
  </code></pre>
  
  <p>Thanks in advance,</p>
  
  <p>Thomas</p>