public void Should_return_result_with_error() { // Arrange var genres = new List <Genre> { new Genre { Name = "Horror" }, new Genre { Name = "Fantasy" } }; var result = new Result <IList <Genre> >(); result.AddError("there was an error"); GenreServiceMock .Setup(x => x.ListAllGenresAsync()) .ReturnsAsync(result); // Act var requestResult = ControllerUnderTest.ListAllGenres(); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult.Result); Assert.Same(result, okResult.Value); }
public async void Should_return_ok() { // Arrange var genre = new Genre { Name = "Horror" }; var result = new Result(); GenreServiceMock .Setup(x => x.AddGenreAsync(genre)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddGenre(genre); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }
public async void Should_return_error_with_message() { // Arrange var genre = new Genre { Name = "Where am I?" }; var result = new Result(); result.AddError("there was an error"); GenreServiceMock .Setup(x => x.UpdateGenreAsync(genre)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.UpdateGenre(genre); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }