Exemplo n.º 1
0
        public void UsersController_Update_ShouldReturnBadRequestNotValid()
        {
            // Arrange
            var UserFixture     = new UsersTestsFixture();
            var PasswordFixture = new PasswordTestsFixture();

            var controller   = Fixture.GetUsersController();
            var userToUpdate = Fixture.GenerateValidUserToUpdate();
            var salt         = PasswordFixture.GenerateSalt("0xF2AAE5AB737144A57EC78745C82F7433");
            var hashPassword = new HashPassword
            {
                Password = "******",
                Salt     = salt
            };

            Fixture.UserAppServiceMock.Setup(c => c.GetById(1)).Returns(Fixture.GenerateValidUserToQuery());
            Fixture.UserAppServiceMock.Setup(c => c.IsValid(It.IsAny <User>()))
            .Returns(new EntityValidationResult
            {
                Status = false
            });

            Fixture.UserAppServiceMock.Setup(c => c.GetById(1)).Returns(UserFixture.GenerateValidUserToQuery());
            Fixture.PasswordAppServiceMock.Setup(c => c.SetCriptoPassword("admin")).Returns(hashPassword);

            // Act
            var response = controller.Update(1, userToUpdate) as ObjectResult;

            // Assert Fluent Assertions
            response.StatusCode.Should().Be(400);
            var apiResponse = response.Value as ApiResponse;

            apiResponse.Message.Should().Be("Validation failed, please see details");
        }
Exemplo n.º 2
0
        public void UsersController_Update_ShouldUpdateUser()
        {
            var UserFixture     = new UsersTestsFixture();
            var PasswordFixture = new PasswordTestsFixture();

            // Arrange
            var controller   = Fixture.GetUsersController();
            var userToUpdate = Fixture.GenerateValidUserToUpdate();
            var salt         = PasswordFixture.GenerateSalt("0xF2AAE5AB737144A57EC78745C82F7433");
            var hashPassword = new HashPassword
            {
                Password = "******",
                Salt     = salt
            };

            Fixture.UserAppServiceMock.Setup(c => c.GetById(1)).Returns(Fixture.GenerateValidUserToQuery());
            Fixture.UserAppServiceMock.Setup(c => c.IsValid(It.IsAny <User>()))
            .Returns(new EntityValidationResult
            {
                Status = true
            });

            Fixture.UserAppServiceMock.Setup(c => c.GetById(1)).Returns(UserFixture.GenerateValidUserToQuery());
            Fixture.PasswordAppServiceMock.Setup(c => c.SetCriptoPassword("admin")).Returns(hashPassword);

            // Act
            var response = controller.Update(1, userToUpdate) as NoContentResult;

            // Assert Fluent Assertions
            response.StatusCode.Should().Be(204);
        }