Ejemplo n.º 1
0
        public Task <IEnumerable <CalculationSummaryModel> > GetCalculationSummariesForSpecification(string specificationId)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                throw new ArgumentNullException(nameof(specificationId));
            }

            string url = $"calcs/calculation-summaries-for-specification?specificationId={specificationId}";

            return(_apiClient.GetAsync <IEnumerable <CalculationSummaryModel> >(url));
        }
Ejemplo n.º 2
0
        public async Task <BuildProject> GetBuildProjectBySpecificationId(string specificationId)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                throw new ArgumentNullException(nameof(specificationId));
            }

            string url = $"{buildProjectsUrl}{specificationId}";

            return(await _apiClient.GetAsync <BuildProject>(url));
        }
        public void GetCalculationSummariesForSpecification_WhenGivenASpecificationIdInValidFormat_ShouldReturnResult()
        {
            // Arrange
            List <CalculationSummaryModel> summaryModels = new List <CalculationSummaryModel>()
            {
                new CalculationSummaryModel()
                {
                    Name            = "TestCalc",
                    CalculationType = CalculationType.Funding,
                    Id = "CalcId"
                }
            };

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

            mockApi
            .GetAsync <IEnumerable <CalculationSummaryModel> >(Arg.Any <string>())
            .Returns(summaryModels);

            CalculationsRepository calculationsRepository = new CalculationsRepository(mockApi);
            ArgumentNullException  exception = null;

            // 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).GetAsync <IEnumerable <CalculationSummaryModel> >(Arg.Any <string>());
        }
Ejemplo n.º 4
0
        public async Task <Calculation> GetCalculationById(string calculationId)
        {
            Guard.ArgumentNotNull(calculationId, nameof(calculationId));

            string url = $"{calcsUrl}{calculationId}";

            return(await _calcsApiClient.GetAsync <Calculation>(url));
        }
Ejemplo n.º 5
0
        public Task <byte[]> GetAssemblyBySpecificationId(string specificationId)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                throw new ArgumentNullException(nameof(specificationId));
            }

            string url = $"calcs/{specificationId}/assembly";

            return(_apiClient.GetAsync <byte[]>(url));
        }
Ejemplo n.º 6
0
        public async Task <IEnumerable <CalculationCurrentVersion> > GetCurrentCalculationsBySpecificationId(string specificationId)
        {
            if (string.IsNullOrWhiteSpace(specificationId))
            {
                throw new ArgumentNullException(nameof(specificationId));
            }

            string url = $"{calculationsUrl}{specificationId}";

            return(await _apiClient.GetAsync <IEnumerable <CalculationCurrentVersion> >(url));
        }
Ejemplo n.º 7
0
        public async Task <bool> IsCalculationNameValid(string specificationId, string calculationName, string existingCalculationId = null)
        {
            string url = string.Format(validateCalculationNameUrl, specificationId, calculationName, existingCalculationId);

            HttpStatusCode result = await _apiClientProxy.GetAsync(url);

            if (result == HttpStatusCode.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void GetBuildProjectBySpecificationId_WhenSpeficationIdIsInValidFormat_ShouldReturnResult()
        {
            // Arrange
            ICalcsApiClientProxy mockApi = Substitute.For <ICalcsApiClientProxy>();

            mockApi
            .GetAsync <BuildProject>(Arg.Any <string>())
            .Returns(new BuildProject());

            CalculationsRepository calculationsRepository = new CalculationsRepository(mockApi);
            ArgumentNullException  exception = null;

            // Act
            var          configuredTaskAwaiter = calculationsRepository.GetBuildProjectBySpecificationId("Test").ConfigureAwait(false).GetAwaiter();
            BuildProject buildProject          = configuredTaskAwaiter.GetResult();

            // Assert
            buildProject.Should().NotBeNull();
            mockApi.Received(1).GetAsync <BuildProject>(Arg.Any <string>());
        }