public async void Should_return_bad_request() { // Arrange var nationality = new Nationality { Name = "China" }; ControllerUnderTest.ModelState.TryAddModelError("key", "there is an error"); // Act var result = await ControllerUnderTest.AddNationality(nationality); // Assert var badRequest = Assert.IsType <BadRequestObjectResult>(result); Assert.IsType <SerializableError>(badRequest.Value); }
public async void Should_return_OK() { // Arrange var nationality = new Nationality { Name = "England" }; var result = new Result(); NationalityServiceMock .Setup(x => x.AddNationalityAsync(nationality)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddNationality(nationality); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }
public async void Should_return_error_with_message() { // Arrange var nationality = new Nationality { Name = "Austria" }; var result = new Result(); result.AddError("there was an error"); NationalityServiceMock .Setup(x => x.AddNationalityAsync(nationality)) .ReturnsAsync(result); // Act var requestResult = await ControllerUnderTest.AddNationality(nationality); // Assert var okResult = Assert.IsType <OkObjectResult>(requestResult); Assert.Same(result, okResult.Value); }