Exemplo n.º 1
0
        public ActionResult Create( RoleManagerCreateInputModel input )
        {
            if (!this.ModelState.IsValid)
                return View(CreateOutputModel);

            SaveOrUpdate.Execute(new Role
            {
                Name = input.Role.Name,
                Description = input.Role.Description
            });
            TempData.Add("info", "Your Role has been saved");

            return RedirectToAction("List");
        }
Exemplo n.º 2
0
        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"));
        }