Ejemplo n.º 1
0
        public async Task UpdateReader_LibrarianUser_OkStatusCode()
        {
            // Arrange
            var claimsProvider = TestClaimsProvider.WithLibrarianClaims();
            var client         = Factory.CreateClientWithTestAuth(claimsProvider);
            var reader         = await CreateReader(client);

            var newName = "FirstName2";

            // Act
            var content = new UpdateReaderCommand()
            {
                UserId    = reader.Id,
                FirstName = newName,
                LastName  = "LastName2",
                Email     = "*****@*****.**",
                Password  = "******"
            };
            var response = await client.PutAsJsonAsync("api/readers/", content);

            var responseUser = await response.Content.ReadFromJsonAsync <UserDTO>();

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            responseUser.FirstName.Should().Be(newName);
        }
        public async Task Handle_ValidCommand_ReaderUpdated()
        {
            // Arrange
            var userId  = 1;
            var newName = "NewFirstName";

            var user = new User("FirstName", "LastName", new Email("*****@*****.**"), UserRolesConsts.Reader);

            _userRepositoryMock.Setup(x => x.GetAsync(userId))
            .ReturnsAsync(user);

            var command = new UpdateReaderCommand()
            {
                UserId    = userId,
                FirstName = newName,
                LastName  = "LastName",
                Email     = "*****@*****.**",
                Password  = "******"
            };

            // Act
            await _sut.Handle(command, CancellationToken.None);

            // Assert
            _userRepositoryMock.Verify(x => x.Update(user));
            user.FirstName.Should().Be(newName);
        }
Ejemplo n.º 3
0
        public void Validate_ValidCommand_NoErrors()
        {
            var command = new UpdateReaderCommand()
            {
                UserId    = 1,
                FirstName = "FirstName",
                LastName  = "LastName",
                Password  = "******",
                Email     = "*****@*****.**"
            };

            var result = _sut.Validate(command);

            result.IsValid.Should().BeTrue();
            result.Errors.Should().BeEmpty();
        }
Ejemplo n.º 4
0
        public async Task UpdateReader_ReaderUser_Forbidden()
        {
            // Arrange
            var claimsProvider = TestClaimsProvider.WithReaderClaims();
            var client         = Factory.CreateClientWithTestAuth(claimsProvider);

            // Act
            var content = new UpdateReaderCommand()
            {
                UserId    = 1,
                FirstName = "FirstName",
                LastName  = "LastName",
                Email     = "*****@*****.**",
                Password  = "******"
            };
            var response = await client.PutAsJsonAsync("api/readers/", content);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <UserDTO> > UpdateReader(UpdateReaderCommand command)
        {
            var user = await _mediator.Send(command);

            return(Ok(user));
        }