public async Task GetEdit_ReturnsEditView_WhenCanEditUserIsTrue()
        {
            var controller = new UserController(apiClient, A.Fake<IWeeeCache>(), A.Fake<BreadcrumbService>());

            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetUserData>._))
                .Returns(new ManageUserData
                {
                    UserStatus = UserStatus.Active,
                    OrganisationId = Guid.NewGuid(),
                    Id = Guid.NewGuid(),
                    UserId = Guid.NewGuid().ToString(),
                    FirstName = "Firstname",
                    LastName = "Lastname",
                    Email = "*****@*****.**",
                    IsCompetentAuthorityUser = true,
                    OrganisationName = "test ltd.",
                    CanEditUser = true
                });

            var result = await controller.Edit(Guid.NewGuid());

            var model = ((ViewResult)result).Model;

            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetUserData>._))
                .MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetRoles>._))
                .MustHaveHappened(Repeated.Exactly.Once);

            Assert.NotNull(result);
            Assert.IsType<ViewResult>(result);
            Assert.IsType<EditUserViewModel>(model);
        }
        public async Task PostIndex_WithValidModel_RedirectsToViewAction()
        {
            // Arrange
            UserController controller = new UserController(
                apiClient,
                A.Fake<IWeeeCache>(),
                A.Fake<BreadcrumbService>());

            // Act
            Guid selectedUserId = Guid.NewGuid();

            ActionResult result = await controller.Index(new ManageUsersViewModel { SelectedUserId = selectedUserId });

            // Assert
            Assert.NotNull(result);
            Assert.IsType<RedirectToRouteResult>(result);

            var redirectValues = ((RedirectToRouteResult)result).RouteValues;
            Assert.Equal("View", redirectValues["action"]);
            Assert.Equal(selectedUserId, redirectValues["id"]);
        }
        public async Task GetEdit_ReturnsHttpForbiddenResult_WhenCanEditUserIsFalse()
        {
            var controller = new UserController(apiClient, A.Fake<IWeeeCache>(), A.Fake<BreadcrumbService>());

            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<GetUserData>._))
                .Returns(new ManageUserData
                {
                    CanEditUser = false
                });

            var result = await controller.Edit(Guid.NewGuid());

            Assert.NotNull(result);
            Assert.IsType<HttpForbiddenResult>(result);
        }
        public async Task PostEdit_WithCompetentAuthorityUserAndValidModelAndUserBeingUpdatedIsCurrentUser_UpdatesUserAndDoesNotUpdateCompetentAuthorityUserRoleAndStatusAndRedirectsToViewAction()
        {
            var controller = new UserController(apiClient, A.Fake<IWeeeCache>(), A.Fake<BreadcrumbService>());

            var model = new EditUserViewModel
            {
                UserStatus = UserStatus.Active,
                OrganisationId = Guid.NewGuid(),
                UserId = controller.User.GetUserId(),
                FirstName = "Firstname",
                LastName = "Lastname",
                Email = "*****@*****.**",
                IsCompetentAuthorityUser = true,
                OrganisationName = "test ltd."
            };

            Guid id = Guid.NewGuid();
            var result = await controller.Edit(id, model);

            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<UpdateUser>._))
                .MustHaveHappened(Repeated.Exactly.Once);

            A.CallTo(() => weeeClient.SendAsync(A<string>._, A<UpdateCompetentAuthorityUserRoleAndStatus>._))
                .MustNotHaveHappened();

            Assert.NotNull(result);
            Assert.IsType<RedirectToRouteResult>(result);

            var redirectValues = ((RedirectToRouteResult)result).RouteValues;
            Assert.Equal("View", redirectValues["action"]);
            Assert.Equal(id, redirectValues["id"]);
        }