Ejemplo n.º 1
0
        public async Task <IActionResult> EditUser(string id, EditUserProfileFormModel profile)
        {
            if (!ModelState.IsValid)
            {
                return(View(profile));
            }

            if (!this.users.UserExists(id) || this.userManager.GetUserId(User) != id)
            {
                return(BadRequest());
            }

            var errors = await this.users.EditRegularUserAsync(id, profile.Username, profile.Email, profile.NewPassword, profile.Password);

            if (errors.Count() != 0)
            {
                foreach (var error in errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View(profile));
            }

            this.GenerateAlertMessage(WebConstants.Message.ProfileEdited, Alert.Success);

            return(RedirectToAction(nameof(Profile), new { id = id }));
        }
Ejemplo n.º 2
0
        public void Get_EditUserShouldReturnViewWithUserInfoWithCorrectData()
        {
            //Arrange
            var controller = new UsersController(this.userService.Object, null, this.fixture.UserManagerMockInstance.Object, null, null);

            this.userService.Setup(u => u.UserExists(It.IsAny <string>()))
            .Returns(true);

            this.userService.Setup(u => u.GetRegularUserProfileToEdit(It.IsAny <string>()))
            .Returns(this.GetUserProfile());

            //Act
            var result = controller.EditUser(UserId);

            //Assert
            result.Should().BeOfType <ViewResult>();
            EditUserProfileFormModel model = result.As <ViewResult>().Model.As <EditUserProfileFormModel>();

            model.Email.Should().Be(UserEmail);
            model.Username.Should().Be(UserUsername);
        }