Beispiel #1
0
        public ActionResult Create(Role role)
        {
            if (ViewData.ModelState.IsValid)
            {
                role.LastUpdateTimeStamp = DateTime.Now;
                role.LastUpdateUser      = GetCurrentUser().Id;
                ActionConfirmation saveOrUpdateConfirmation =
                    _roleManagementService.SaveOrUpdate(role);

                if (saveOrUpdateConfirmation.WasSuccessful)
                {
                    TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                        saveOrUpdateConfirmation.Message;
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                role = null;
            }

            RoleFormViewModel viewModel =
                _roleManagementService.CreateFormViewModelFor(role);

            return(View(viewModel));
        }
        public void CanCreateFormViewModelForRole()
        {
            // Establish Context
            var viewModelToExpect = new RoleFormViewModel();

            Role role =
                RoleInstanceFactory.CreateValidTransientRole();

            roleRepository.Expect(r => r.Get(1))
            .Return(role);

            // Act
            RoleFormViewModel viewModelRetrieved =
                roleManagementService.CreateFormViewModelFor(1);

            // Assert
            viewModelRetrieved.ShouldNotBeNull();
            viewModelRetrieved.Role.ShouldNotBeNull();
            viewModelRetrieved.Role.ShouldEqual(role);
        }