public async Task PostAsync_Succeeds() { //Arrange var request = ApportionmentControllerTestsDataGenerator.GetValidRequestWithDataExampleOne(); var response = ApportionmentControllerTestsDataGenerator.GetValidResponseForExampleOne(); _service.Setup(m => m.PerformApportionmentCalculationAsync(request, _confOptions)).ReturnsAsync(response); var controller = new ApportionmentController(_service.Object, _mockLogger.Object, _confOptions); //Act var result = await controller.PostAsync(request); //Assert var okObjectRequest = result.Should().BeOfType <OkObjectResult>().Subject; okObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.OK); }
public async Task PostAsync_FailsWithBadRequest_WhenThereIsAValidationError(ApportionmentCalculationRequestModel request, string expectedErrorMessage) { //Arrange var controller = new ApportionmentController(_service.Object, _mockLogger.Object, _confOptions); //Act var result = await controller.PostAsync(request); //Assert var badRequestObjectRequest = result.Should().BeOfType <BadRequestObjectResult>().Subject; badRequestObjectRequest.StatusCode.Should().Be((int)System.Net.HttpStatusCode.BadRequest); _mockLogger.Verify(x => x.Log( LogLevel.Error, It.IsAny <EventId>(), It.Is <object>(v => v.ToString().Contains(expectedErrorMessage)), null, It.IsAny <Func <object, Exception, string> >() )); }