Пример #1
0
        public async Task PostAsync_Succeeds()
        {
            //Arrange
            var request  = BasicAwardControllerTestsDataGenerator.GetValidRequest();
            var response = BasicAwardControllerTestsDataGenerator.GetValidResponse();

            _service.Setup(m => m.PerformBasicAwardCalculationAsync(request, _confOptions)).ReturnsAsync(response);

            var controller = new BasicAwardController(_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);
        }
Пример #2
0
        public async Task PostAsync_FailsWithBadRequest_WhenThereIsAValidationError(BasicAwardCalculationRequestModel request, string expectedErrorMessage)
        {
            //Arrange
            var controller = new BasicAwardController(_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> >()
                                   ));
        }