public async void Should_return_error_with_message() { // Arrange var authorDoesNotExist = new Author { Name = "Schrödinger's Cat", Nationality = new Nationality { Name = "Austria" } }; var result = new Result(); result.AddError("there was an error"); AuthorServiceMock .Setup(x => x.UpdateAuthorAsync(authorDoesNotExist)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.UpdateAuthor(authorDoesNotExist); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }
public void Should_return_result_with_error() { // Arrange var authors = new List <AuthorListItem> { new AuthorListItem { Name = "Peter Piper", Nationality = "Austrian" }, new AuthorListItem { Name = "Spiderman", Nationality = "American" } }; var result = new Result <IList <AuthorListItem> >(); result.AddError("there was an error"); AuthorServiceMock .Setup(x => x.ListAllAuthorsAsync()) .ReturnsAsync(result); // Act var requestResult = ControllerUnderTest.ListAllAuthors(); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult.Result); Assert.Same(result, okResult.Value); }
public async void Should_return_error_with_message() { // Arrange var duplicateAuthor = new Author { Name = "Katherine Man", Nationality = new Nationality { Name = "Mountains" } }; var result = new Result(); result.AddError("there was an error"); AuthorServiceMock .Setup(x => x.AddAuthorAsync(duplicateAuthor)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddAuthor(duplicateAuthor); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }
public async void Should_return_OK_with_author() { // Arrange var expectedAuthor = new Author { Name = "Katherine Man", Nationality = new Nationality { Name = "Mountains" } }; var result = new Result(); AuthorServiceMock .Setup(x => x.AddAuthorAsync(expectedAuthor)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddAuthor(expectedAuthor); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }