Beispiel #1
0
        public async Task patch_author_contract_author_succeeds()
        {
            var author = new Author()
            {
                Id = 747, AuthorCode = "111-22-3333", FirstName = "A", LastName = "B", PhoneNumber = "1", Contract = false
            };
            var authorUpdated = new Author()
            {
                Id = 747, AuthorCode = "444-55-6666", FirstName = "Unit", LastName = "Test", PhoneNumber = "1", Contract = true
            };
            var authorDto = new AuthorUpdateContractDto()
            {
                AuthorId = 747, Contract = true
            };

            _mockAuthorRepository.Setup(s => s.GetAuthorAsync(It.IsAny <int>())).ReturnsAsync(author);
            _mockAuthorRepository.Setup(s => s.UpdateAsync(It.IsAny <Author>()));

            var sut = CreateAuthorController(_mockAuthorRepository, _mapper, _mockLogger);

            var result = await sut.PatchUpdateAuthorContract(747, authorDto);

            using (new AssertionScope())
            {
                result.GetObjectResult().Should().BeOfType <Author>();
                result.GetObjectResult().Contract.Should().Be(authorUpdated.Contract);
                result.GetObjectResult().Id.Should().Be(747);
            }
        }
Beispiel #2
0
        public void property_update_succeeds()
        {
            var sut = new AuthorUpdateContractDto()
            {
                AuthorId = 7,
                Contract = true
            };

            using (new AssertionScope())
            {
                sut.AuthorId.Should().Be(7);
                sut.Contract.Should().BeTrue();
            }
        }
Beispiel #3
0
        public async Task <ActionResult <Author> > PatchUpdateAuthorContract(int authorId, [FromBody] AuthorUpdateContractDto authorUpdateDto)
        {
            if (authorUpdateDto == null)
            {
                return(BadRequest());
            }

            if (authorId != authorUpdateDto.AuthorId)
            {
                return(BadRequest("The AuthorId parameter does not match the AuthorId in the request body."));
            }

            var existingAuthor = await _authorRepository.GetAuthorAsync(authorId);

            if (existingAuthor == null)
            {
                return(NotFound());
            }

            _mapper.Map(authorUpdateDto, existingAuthor);

            await _authorRepository.UpdateAsync(existingAuthor);

            _logger.LogInformation($"The author id:: {authorId} has been updated. The contract is :: {authorUpdateDto.Contract}");

            return(Ok(existingAuthor));
        }