public void GET_Create_UsesCreateOutputModel() { // Arrange var roleManager = new RoleManagerController(); var builder = new TestControllerBuilder(); builder.InitializeController(roleManager); roleManager.CreateOutputModel = new RoleManagerCreateOutputModel( ); // act var result = roleManager.Create(); // Assert Assert.IsInstanceOf<ViewResult>(result); var viewResult = result as ViewResult; var model = viewResult.ViewData.Model; Assert.IsInstanceOf<RoleManagerCreateOutputModel>(model); }
public void POST_Create_Saves_NewRole() { const string ROLE_DESCRIPTION = " The glorious user role"; const string ROLE_NAME = "Glorious"; const string INFO_KEY = "info"; // Arrange var saveOrUpdateCommand = MockRepository.GenerateMock<ISaveOrUpdateCommand<Role>>(); saveOrUpdateCommand .Expect(c => c.Execute(Arg<Role>.Matches( p => p.Description == ROLE_DESCRIPTION && p.Name == ROLE_NAME))); var roleManager = new RoleManagerController(); var builder = new TestControllerBuilder(); builder.InitializeController(roleManager); roleManager.CreateOutputModel = new RoleManagerCreateOutputModel( ); roleManager.SaveOrUpdate = saveOrUpdateCommand; var inputModel = new RoleManagerCreateInputModel { Role = new RoleManagerCreateInputModel.RoleModel { Description = ROLE_DESCRIPTION, Name = ROLE_NAME } }; // act var result = roleManager.Create(inputModel); // Assert Assert.IsInstanceOf<RedirectToRouteResult>(result); var viewResult = result as RedirectToRouteResult; Assert.AreEqual("List", viewResult.RouteValues["Action"]); saveOrUpdateCommand.VerifyAllExpectations(); Assert.IsTrue(builder.TempDataDictionary.ContainsKey(INFO_KEY)); Assert.IsTrue( builder.TempDataDictionary[INFO_KEY].ToString().Contains("Role")); }