public async void Should_return_result_with_error() { // Arrange var book = new Book { Title = "Dune", Author = TestAuthorTwo, Genre = TestGenreTwo, Rating = 7.7, YearPublished = new DateTime(1908, 1, 1), DateRead = DateTime.Today }; var result = new Result <Book>(); result.Errors.Add("there was an error"); BasicBookServiceMock .Setup(x => x.GetBookAsync(book.BookId)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.GetBook(book.BookId); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }
public async void Should_return_ok_with_book() { // Arrange var book = new Book { Title = "The Prisoner of Azkaban", Author = TestAuthorOne, Genre = TestGenreOne, Rating = 8.8, YearPublished = new DateTime(1999, 1, 1), DateRead = DateTime.Today }; var result = new Result <Book>(book); BasicBookServiceMock .Setup(x => x.GetBookAsync(book.BookId)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.GetBook(book.BookId); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }