public void GetCalculationSummariesForSpecification_WhenGivenASpecificationIdInValidFormat_ShouldReturnResult()
        {
            // Arrange
            List <Common.ApiClient.Calcs.Models.CalculationSummary> summaryModels = new List <Common.ApiClient.Calcs.Models.CalculationSummary>()
            {
                new Common.ApiClient.Calcs.Models.CalculationSummary()
                {
                    Name            = "TestCalc",
                    CalculationType = Common.ApiClient.Calcs.Models.CalculationType.Template,
                    Id = "CalcId"
                }
            };

            ICalculationsApiClient mockApi = Substitute.For <ICalculationsApiClient>();

            mockApi
            .GetCalculationSummariesForSpecification(Arg.Any <string>())
            .Returns(new ApiResponse <IEnumerable <Common.ApiClient.Calcs.Models.CalculationSummary> >(HttpStatusCode.OK, summaryModels));

            CalculationsRepository calculationsRepository = new CalculationsRepository(mockApi, CreateMapper());

            // Act
            var configuredTaskAwaiter = calculationsRepository.GetCalculationSummariesForSpecification("Test").ConfigureAwait(false).GetAwaiter();
            List <CalculationSummaryModel> calculationSummaryModels = configuredTaskAwaiter.GetResult().ToList();

            // Assert
            calculationSummaryModels.Should().NotBeNull();
            calculationSummaryModels.Should().BeEquivalentTo(summaryModels);
            mockApi.Received(1).GetCalculationSummariesForSpecification(Arg.Any <string>());
        }
Пример #2
0
        public async Task <IActionResult> GetCalculationSummaryForSpecification([FromQuery] string specificationId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            ApiResponse <IEnumerable <CalculationSummary> > response = await _calcClient.GetCalculationSummariesForSpecification(specificationId);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(Ok(response.Content));
            }

            throw new InvalidOperationException($"An error occurred while retrieving calculation summary. Status code={response.StatusCode}");
        }
        public async Task <IEnumerable <CalculationSummaryModel> > GetCalculationSummariesForSpecification(string specificationId)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                throw new ArgumentNullException(nameof(specificationId));
            }

            ApiResponse <IEnumerable <Common.ApiClient.Calcs.Models.CalculationSummary> > apiResponse = await _apiClient.GetCalculationSummariesForSpecification(specificationId);

            return(_mapper.Map <IEnumerable <CalculationSummaryModel> >(apiResponse?.Content));
        }