Beispiel #1
0
        public async Task GetProviderProfilePeriods_WhenLast4CharcatersAreNotAllIntegers_SetsDefaultYear()
        {
            //Arrange
            ProviderProfilingRequestModel requestModel = new ProviderProfilingRequestModel
            {
                AllocationValueByDistributionPeriod = new[]
                {
                    new Common.ApiClient.Profiling.Models.AllocationPeriodValue
                    {
                        AllocationValue    = 1200,
                        DistributionPeriod = "Period"
                    }
                },
                FundingStreamPeriod = "TEST"
            };

            MockProviderProfilingRepository repository = new MockProviderProfilingRepository();

            // Act
            ValidatedApiResponse <ProviderProfilingResponseModel> providerProfilingResponseModel = await repository.GetProviderProfilePeriods(requestModel);

            // Assert
            providerProfilingResponseModel
            .Should()
            .NotBeNull();

            providerProfilingResponseModel
            .Content
            .Should()
            .NotBeNull();

            providerProfilingResponseModel
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);

            providerProfilingResponseModel
            .Content
            .DeliveryProfilePeriods
            .ElementAt(0)
            .Year
            .Should()
            .Be(DateTime.Now.Year);

            providerProfilingResponseModel
            .Content
            .DeliveryProfilePeriods
            .ElementAt(1)
            .Year
            .Should()
            .Be(DateTime.Now.Year + 1);
        }
Beispiel #2
0
        public async Task GetProviderProfilePeriods_GivenValidAllocationDistributionPeriod_CalculatesAndReturnsResponseModel()
        {
            //Arrange
            ProviderProfilingRequestModel requestModel = new ProviderProfilingRequestModel
            {
                AllocationValueByDistributionPeriod = new[]
                {
                    new Common.ApiClient.Profiling.Models.AllocationPeriodValue
                    {
                        AllocationValue    = 1200,
                        DistributionPeriod = "Period"
                    }
                },
                FundingStreamPeriod = "TEST1819"
            };

            MockProviderProfilingRepository repository = new MockProviderProfilingRepository();

            // Act
            ValidatedApiResponse <ProviderProfilingResponseModel> providerProfilingResponseModel = await repository.GetProviderProfilePeriods(requestModel);

            // Assert
            providerProfilingResponseModel
            .Should()
            .NotBeNull();

            providerProfilingResponseModel
            .Content
            .Should()
            .NotBeNull();

            providerProfilingResponseModel
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);

            providerProfilingResponseModel.Content.AllocationProfileRequest.Should().BeEquivalentTo(requestModel);
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(0).DistributionPeriod.Should().Be("Period");
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(0).Occurrence.Should().Be(1);
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(0).Period.Should().Be("Oct");
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(0).Type.Should().Be("CalendarMonth");
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(0).Value.Should().Be(700);
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(0).Year.Should().Be(2018);

            providerProfilingResponseModel.Content.AllocationProfileRequest.Should().BeEquivalentTo(requestModel);
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(1).DistributionPeriod.Should().Be("Period");
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(1).Occurrence.Should().Be(1);
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(1).Period.Should().Be("Apr");
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(1).Type.Should().Be("CalendarMonth");
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(1).Value.Should().Be(500);
            providerProfilingResponseModel.Content.DeliveryProfilePeriods.ElementAt(1).Year.Should().Be(2019);
        }
Beispiel #3
0
        public void GetProviderProfilePeriods_GivenNullAllocationValueDistributiuonPeriod_ThrowsArgumentException()
        {
            //Arrange
            ProviderProfilingRequestModel requestModel = new ProviderProfilingRequestModel
            {
                FundingStreamPeriod = "TEST1819"
            };

            MockProviderProfilingRepository repository = new MockProviderProfilingRepository();

            //Act
            Func <Task> test = async() => await repository.GetProviderProfilePeriods(requestModel);

            //Assert
            test
            .Should()
            .ThrowExactly <ArgumentException>();
        }
Beispiel #4
0
        private ProviderProfilingRequestModel ConstructProfilingRequest(string fundingPeriodId,
                                                                        string fundingStreamId,
                                                                        string fundingLineCodes,
                                                                        decimal?fundingValue,
                                                                        string profilePatternKey = null,
                                                                        string providerType      = null,
                                                                        string providerSubType   = null)
        {
            ProviderProfilingRequestModel requestModel = new ProviderProfilingRequestModel
            {
                FundingPeriodId   = fundingPeriodId,
                FundingStreamId   = fundingStreamId,
                FundingLineCode   = fundingLineCodes,
                FundingValue      = fundingValue,
                ProfilePatternKey = profilePatternKey,
                ProviderType      = providerType,
                ProviderSubType   = providerSubType
            };

            return(requestModel);
        }
        public async Task <ValidatedApiResponse <ProviderProfilingResponseModel> > GetProviderProfilePeriods(ProviderProfilingRequestModel requestModel)
        {
            Guard.ArgumentNotNull(requestModel, nameof(requestModel));

            return(await ValidatedPostAsync <ProviderProfilingResponseModel, ProviderProfilingRequestModel>("profiling", requestModel));
        }
Beispiel #6
0
        public Task <ValidatedApiResponse <ProviderProfilingResponseModel> > GetProviderProfilePeriods(ProviderProfilingRequestModel requestModel)
        {
            Guard.ArgumentNotNull(requestModel, nameof(requestModel));
            Guard.IsNullOrWhiteSpace(requestModel.FundingStreamPeriod, nameof(requestModel.FundingStreamPeriod));

            if (requestModel.AllocationValueByDistributionPeriod.IsNullOrEmpty())
            {
                throw new ArgumentException("Null or empty allocation distribution period found", nameof(requestModel.AllocationValueByDistributionPeriod));
            }

            ProviderProfilingResponseModel providerProfilingResponseModel = new ProviderProfilingResponseModel
            {
                AllocationProfileRequest = requestModel,
                DeliveryProfilePeriods   = Enumerable.Empty <ProfilingPeriod>()
            };

            int startYear;
            int endYear;

            if (requestModel.FundingStreamPeriod.Length < 4)
            {
                startYear = DateTime.Now.Year;
                endYear   = DateTime.Now.Year + 1;
            }
            else
            {
                string yearsPart = requestModel.FundingStreamPeriod.Substring(requestModel.FundingStreamPeriod.Length - 4);

                if (!int.TryParse(yearsPart, out int yearsPartAsInteger))
                {
                    startYear = DateTime.Now.Year;
                    endYear   = DateTime.Now.Year + 1;
                }
                else
                {
                    startYear = int.Parse("20" + yearsPart.Substring(0, 2));
                    endYear   = int.Parse("20" + yearsPart.Substring(2, 2));
                }
            }


            AllocationPeriodValue periodValue = requestModel.AllocationValueByDistributionPeriod.First();


            providerProfilingResponseModel.DeliveryProfilePeriods = new[]
            {
                new ProfilingPeriod
                {
                    DistributionPeriod = periodValue.DistributionPeriod,
                    Occurrence         = 1,
                    Period             = "Oct",
                    Type  = "CalendarMonth",
                    Value = CalculateValue(periodValue.AllocationValue, 7),
                    Year  = startYear
                },
                new ProfilingPeriod
                {
                    DistributionPeriod = periodValue.DistributionPeriod,
                    Occurrence         = 1,
                    Period             = "Apr",
                    Type  = "CalendarMonth",
                    Value = CalculateValue(periodValue.AllocationValue, 5),
                    Year  = endYear,
                }
            };

            return(Task.FromResult(new ValidatedApiResponse <ProviderProfilingResponseModel>(System.Net.HttpStatusCode.OK, providerProfilingResponseModel)));
        }
Beispiel #7
0
        public async Task <IEnumerable <ProfilePatternKey> > ProfileFundingLines(IEnumerable <FundingLine> fundingLines,
                                                                                 string fundingStreamId,
                                                                                 string fundingPeriodId,
                                                                                 IEnumerable <ProfilePatternKey> profilePatternKeys = null,
                                                                                 string providerType    = null,
                                                                                 string providerSubType = null)
        {
            Guard.ArgumentNotNull(fundingLines, nameof(fundingLines));
            Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId));
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));

            List <ProfilePatternKey> profilePatternKeysToReturn = new List <ProfilePatternKey>();

            Dictionary <decimal?, ProviderProfilingResponseModel> response =
                new Dictionary <decimal?, ProviderProfilingResponseModel>();

            Dictionary <string, Dictionary <decimal?, ProviderProfilingResponseModel> > profilingResponses =
                new Dictionary <string, Dictionary <decimal?, ProviderProfilingResponseModel> >();

            if (fundingLines.IsNullOrEmpty())
            {
                throw new ArgumentNullException($"Null or empty publsihed profiling fundingLines.");
            }

            //Change the key to FundingLineCode + ProfilePatternKey + ProviderType + ProviderSubType
            var fundingValues = fundingLines
                                .Where(_ => _.Value != null)
                                .Select(k => new { k.FundingLineCode, k.Value })
                                .Distinct()
                                .ToList();

            if (fundingValues.IsNullOrEmpty() || fundingValues.Count == 0)
            {
                string errorMessage = "No Funding Values of Type Payment in the Funding Totals for updating.";

                _logger.Error(errorMessage);

                return(profilePatternKeysToReturn);
            }

            foreach (var value in fundingValues)
            {
                ProviderProfilingRequestModel requestModel = ConstructProfilingRequest(fundingPeriodId,
                                                                                       fundingStreamId,
                                                                                       value.FundingLineCode,
                                                                                       value.Value,
                                                                                       profilePatternKey: profilePatternKeys?.FirstOrDefault(x => x.FundingLineCode == value.FundingLineCode)?.Key,
                                                                                       providerType: providerType,
                                                                                       providerSubType: providerSubType);

                ValidatedApiResponse <ProviderProfilingResponseModel> providerProfilingResponse = await GetProviderProfilePeriods(requestModel);

                if (providerProfilingResponse?.Content == null)
                {
                    string errorMessage = $"Failed to Get Profile Periods for updating for Requested FundingPeriodId: '{fundingPeriodId}' and FundingStreamId: '{fundingStreamId}'";

                    _logger.Error(errorMessage);

                    throw new NonRetriableException(errorMessage);
                }

                if (profilePatternKeysToReturn.All(x => x.FundingLineCode != value.FundingLineCode))
                {
                    profilePatternKeysToReturn.Add(new ProfilePatternKey()
                    {
                        FundingLineCode = value.FundingLineCode, Key = providerProfilingResponse.Content.ProfilePatternKey
                    });
                }

                AddOrUpdateResponseDictionary(ref response, value.Value, providerProfilingResponse.Content);

                AddOrUpdateDictionaryProfilingResponses(profilingResponses, value.FundingLineCode, response);
            }

            SaveFundingLineTotals(ref fundingLines, profilingResponses);

            return(profilePatternKeysToReturn);
        }
Beispiel #8
0
        private async Task <ValidatedApiResponse <ProviderProfilingResponseModel> > GetProviderProfilePeriods(ProviderProfilingRequestModel requestModel)
        {
            ValidatedApiResponse <ProviderProfilingResponseModel> providerProfilingResponseModel;

            try
            {
                providerProfilingResponseModel = await _profilingApiClient.GetProviderProfilePeriods(requestModel);
            }
            catch (Exception ex)
            {
                string errorMessage = $"Failed to Get Profile Periods on :' {requestModel}' from published providers.";

                _logger.Error(ex, errorMessage);

                throw new RetriableException(errorMessage, ex);
            }

            return(providerProfilingResponseModel);
        }