public async Task UpdateBookAsync_WhenUpdatesInStorage_ReturnsSuccess() { //Arrange var expectedBookId = Guid.NewGuid().ToString(); var expectedBookModel = new BookModel { BookId = expectedBookId, AuthorId = "1", Name = "1" }; //strict matching to make sure mapping is done correctly BookItem updatedBookItem = null; _booksRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <BookItem>())) .Callback <BookItem>(x => updatedBookItem = x) .ReturnsAsync(Result.Success <Unit, Error>(Unit.Instance)); //Act var result = await _sut.UpdateBookAsync(expectedBookId, expectedBookModel); //Assert result.IsSuccess.Should().BeTrue(); updatedBookItem.Should().BeEquivalentTo(expectedBookModel, config => config.Excluding(bi => bi.BookId)); updatedBookItem.BookId.Should().BeEquivalentTo(expectedBookId); }
public async Task CreateBookAsync_WhenStoredInStorage_ReturnsSuccess() { //Arrange var expectedBookModel = new BookModel { BookId = "1", AuthorId = "1", Name = "1" }; //strict matching to make sure mapping is done correctly BookItem storedBookItem = null; _booksRepositoryMock.Setup(x => x.InsertAsync(It.IsAny <BookItem>())) .Callback <BookItem>(x => storedBookItem = x) .ReturnsAsync(Result.Success <Unit, Error>(Unit.Instance)); //Act var result = await _sut.CreateBookAsync(expectedBookModel); //Assert result.IsSuccess.Should().BeTrue(); storedBookItem.Should().BeEquivalentTo(expectedBookModel); }