Ejemplo n.º 1
0
        public async Task HasAllTemplateCalculationsBeenApproved_GivenResponseIsSuccess_ReturnsValue(bool expectedValue)
        {
            //Arrange
            BooleanResponseModel booleanResponseModel = new BooleanResponseModel {
                Value = expectedValue
            };

            ApiResponse <BooleanResponseModel> apiResponse = new ApiResponse <BooleanResponseModel>(HttpStatusCode.OK, booleanResponseModel);

            ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient();

            calculationsApiClient
            .CheckHasAllApprovedTemplateCalculationsForSpecificationId(Arg.Is(specificationId))
            .Returns(apiResponse);

            CalculationsService calculationsService = CreateCalculationsService(calculationsApiClient);

            //Act
            bool responseValue = await calculationsService.HaveAllTemplateCalculationsBeenApproved(specificationId);

            //Assert
            responseValue
            .Should()
            .Be(expectedValue);
        }
Ejemplo n.º 2
0
        public void HasAllTemplateCalculationsBeenApproved_GivenFailedResponseCheckingForApprovedTemplateCalcs_ThrowsRetriableException()
        {
            //Arrange
            ApiResponse <BooleanResponseModel> apiResponse = new ApiResponse <BooleanResponseModel>(HttpStatusCode.NotFound);

            ICalculationsApiClient calculationsApiClient = CreateCalculationsApiClient();

            calculationsApiClient
            .CheckHasAllApprovedTemplateCalculationsForSpecificationId(Arg.Is(specificationId))
            .Returns(apiResponse);

            ILogger logger = CreateLogger();

            string errorMessage = $"Failed to check spoecification with id '{specificationId}' " +
                                  $"for all approved template calculations with status code '{HttpStatusCode.NotFound}'";

            CalculationsService calculationsService = CreateCalculationsService(calculationsApiClient, logger);

            //Act
            Func <Task> test = async() => await calculationsService.HaveAllTemplateCalculationsBeenApproved(specificationId);

            //Assert
            test
            .Should()
            .ThrowExactly <RetriableException>()
            .Which
            .Message
            .Should()
            .Be(errorMessage);

            logger
            .Received(1)
            .Error(Arg.Is(errorMessage));
        }
        public async Task <bool> HaveAllTemplateCalculationsBeenApproved(string specificationId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            ApiResponse <BooleanResponseModel> apiResponse = await _calcsApiClientPolicy.ExecuteAsync(
                () => _calculationsApiClient.CheckHasAllApprovedTemplateCalculationsForSpecificationId(specificationId));

            if (!apiResponse.StatusCode.IsSuccess())
            {
                string errorMessage = $"Failed to check spoecification with id '{specificationId}' " +
                                      $"for all approved template calculations with status code '{apiResponse.StatusCode}'";

                _logger.Error(errorMessage);

                throw new RetriableException(errorMessage);
            }

            return(apiResponse.Content.Value);
        }