public void CreateAccount_WithDoctor_HappyPath() { using (var disposer = new Disposer()) { AuthenticationController controller; var hasBeenSaved = false; CreateAccountViewModel vm; try { var mr = new MockRepository(); var mve = mr.SetupViewEngine(disposer); mve.SetViewContent( "ConfirmationEmail", vc => vc.ViewData.Model.ConvertObjectToString("<div>{0}={1}</div>")); mr.SetRouteData_ControllerAndActionOnly("Home", "Index"); mr.SetupHttpContext(disposer); controller = mr.CreateController<AuthenticationController>( setupNewDb: db2 => db2.SavingChanges += (s, e) => { hasBeenSaved = true; }); mr.SetupUrlHelper(controller); controller.EmailSender = mm => { // Do nothing, instead of sending a REAL e-mail. // Don't need to test if this has been called... another test already does this. }; // Creating ViewModel, and setting the ModelState of the controller. var me = Firestarter.GetMedicalEntity_Psicologia(this.db); var ms = Firestarter.GetMedicalSpecialty_Psiquiatra(this.db); vm = new CreateAccountViewModel { UserName = "******", PracticeName = "consultoriodrhouse_08sd986", Password = "******", ConfirmPassword = "******", DateOfBirth = new DateTime(1984, 05, 04), EMail = "*****@*****.**", FullName = "André", Gender = (short)TypeGender.Male, IsDoctor = true, MedicCRM = "98237", MedicalEntityId = me.Id, MedicalSpecialtyId = ms.Id, MedicalSpecialtyName = ms.Name, MedicalEntityJurisdiction = (int)TypeEstadoBrasileiro.RJ, }; Mvc3TestHelper.SetModelStateErrors(controller, vm); } catch (Exception ex) { InconclusiveInit(ex); return; } // Creating a new user without an e-mail. // This must be ok, no exceptions, no validation errors. ActionResult actionResult; { actionResult = controller.CreateAccount(vm); } // Getting the user that was saved. var savedUser = this.db.Users.Single(u => u.UserName == "andré-01"); // Assertions. Assert.IsNotNull(actionResult, "The result of the controller method is null."); Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult)); var redirectResult = (RedirectToRouteResult)actionResult; Assert.AreEqual(redirectResult.RouteValues["action"], "CreateAccountCompleted"); Assert.IsTrue(controller.ModelState.IsValid, "ModelState should be valid."); Assert.IsTrue(hasBeenSaved, "The database should be changed, but it was not."); Assert.AreEqual(savedUser.UserNameNormalized, "andre01"); // Assert user is logged-in: this is already done in CreateAccount_HappyPath. // Assertion for email: this is already done in CreateAccount_HappyPath. } }