示例#1
0
        public async Task UpdateAuthorAsync_ShouldReturnTrue_WhenAuthorUpdated()
        {
            //Arrange
            var authorId   = new Random().Next(1, int.MaxValue);
            var authorName = "Author Name created";
            var author     = new Author()
            {
                AuthorId = new Random().Next(1, int.MaxValue), Name = authorName
            };


            repoWrapperMock.Setup(p => p.Author.GetAuthorByIdAsync(authorId))
            .ReturnsAsync(author);

            var authorForUpdated = new AuthorPut()
            {
                Name = "Author Name Update"
            };

            repoWrapperMock.Setup(p => p.Author.UpdateAuthorAsync(author));

            //Act
            var isAuthorUpdated = await authorService.UpdateAuthorAsync(authorId, authorForUpdated);

            //Assert
            Assert.True(isAuthorUpdated);
        }
示例#2
0
        public async Task <IActionResult> UpdateAuthor(int authorId, [FromBody] AuthorPut authorPut)
        {
            var authorEntity = await _service.UpdateAuthorAsync(authorId, authorPut);

            if (!authorEntity)
            {
                return(NotFound());
            }

            return(NoContent());
        }
示例#3
0
        public async Task <bool> UpdateAuthorAsync(int Id, AuthorPut AuthorPut)
        {
            var AuthorEntity = await _repository.Author.GetAuthorByIdAsync(Id);

            if (AuthorEntity == null)
            {
                _logger.LogError($"Author with id: {Id}, not found in db.");
                return(false);
            }

            _mapper.Map(AuthorPut, AuthorEntity);

            await _repository.Author.UpdateAuthorAsync(AuthorEntity);

            return(true);
        }
示例#4
0
        public async Task UpdateAuthorAsync_ShouldReturnFalse_WhenAuthorNotFound()
        {
            //Arrange
            var authorId         = new Random().Next(1, int.MaxValue);
            var authorForUpdated = new AuthorPut()
            {
                Name = "Author Name Update"
            };

            repoWrapperMock.Setup(p => p.Author.GetAuthorByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(() => null);

            //Act
            var isAuthorUpdated = await authorService.UpdateAuthorAsync(authorId, authorForUpdated);

            //Assert
            Assert.False(isAuthorUpdated);
        }