public async void Should_return_result_with_error_message() { // Arrange var book = new Book { Title = "Pachinko", Author = TestAuthorOne, Genre = TestGenreTwo, Rating = 4.4, YearPublished = new DateTime(1919, 1, 1), DateRead = DateTime.Now }; var result = new Result(); result.Errors.Add("an error happened"); BasicBookServiceMock .Setup(x => x.AddBookAsync(book)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddBook(book); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Equal(result, okResult.Value); }
public async void Should_return_ok_with_book() { // Arrange var book = new Book { Title = "The Bible", Author = TestAuthorOne, Genre = TestGenreOne, Rating = 0, YearPublished = new DateTime(1, 1, 1), DateRead = DateTime.Today }; var result = new Result(); BasicBookServiceMock .Setup(x => x.AddBookAsync(book)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddBook(book); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode); Assert.Equal(result, okResult.Value); }
public async void Should_return_bad_request() { // Arrange var book = new Book(); ControllerUnderTest.ModelState.AddModelError("key", "there is an error"); // Act var result = await ControllerUnderTest.AddBook(book); // Assert var badRequest = Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <SerializableError>(badRequest.Value); }