Ejemplo n.º 1
0
        public void DeactivateOrDeleteAdmin_does_not_deactivate_admin_user_without_confirmation()
        {
            // Given
            const string expectedErrorMessage = "You must confirm before deactivating this account";
            var          adminUser            = UserTestHelper.GetDefaultAdminUser(8);
            var          loggedInAdminUser    = UserTestHelper.GetDefaultAdminUser();

            A.CallTo(() => userDataService.GetAdminUserById(adminUser.Id)).Returns(adminUser);
            A.CallTo(() => userDataService.GetAdminUserById(loggedInAdminUser.Id)).Returns(loggedInAdminUser);

            var deactivateViewModel =
                Builder <DeactivateAdminViewModel> .CreateNew().With(vm => vm.Confirm = false).Build();

            administratorController.ModelState.AddModelError(
                nameof(DeactivateAdminViewModel.Confirm),
                expectedErrorMessage
                );

            // When
            var result = administratorController.DeactivateOrDeleteAdmin(adminUser.Id, deactivateViewModel);

            // Then
            using (new AssertionScope())
            {
                result.Should().BeViewResult().WithDefaultViewName().ModelAs <DeactivateAdminViewModel>();
                administratorController.ModelState[nameof(DeactivateAdminViewModel.Confirm)].Errors[0].ErrorMessage
                .Should()
                .BeEquivalentTo(expectedErrorMessage);
                A.CallTo(() => userDataService.DeactivateAdmin(adminUser.Id)).MustNotHaveHappened();
            }
        }
Ejemplo n.º 2
0
        public IActionResult DeactivateAdmin(int adminId, DeactivateAdminViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            userDataService.DeactivateAdmin(adminId);

            return(View("DeactivateAdminConfirmation"));
        }