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); }
public async Task <IActionResult> UpdateAuthor(int authorId, [FromBody] AuthorPut authorPut) { var authorEntity = await _service.UpdateAuthorAsync(authorId, authorPut); if (!authorEntity) { return(NotFound()); } return(NoContent()); }
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); }
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); }