AllocationModel CreateAllocation(PublishedProviderResult publishedProviderResult) { ProviderVariation providerVariation = new ProviderVariation(); PublishedAllocationLineResult allocationLineResult = publishedProviderResult.FundingStreamResult.AllocationLineResult; if (!allocationLineResult.Current.VariationReasons.IsNullOrEmpty()) { providerVariation.VariationReasons = new Collection <string>(allocationLineResult.Current.VariationReasons.Select(vr => vr.ToString()).ToList()); } if (allocationLineResult.Current.Provider.Successor != null) { providerVariation.Successors = new Collection <ProviderInformationModel> { new ProviderInformationModel() { Ukprn = allocationLineResult.Current.Provider.Successor } }; } if (!allocationLineResult.Current.Predecessors.IsNullOrEmpty()) { List <ProviderInformationModel> providerModelsForPredecessor = allocationLineResult.Current.Predecessors.Select(fi => new ProviderInformationModel() { Ukprn = fi }).ToList(); providerVariation.Predecessors = new Collection <ProviderInformationModel>(providerModelsForPredecessor); } providerVariation.OpenReason = allocationLineResult.Current.Provider.ReasonEstablishmentOpened; providerVariation.CloseReason = allocationLineResult.Current.Provider.ReasonEstablishmentClosed; return(new AllocationModel { AllocationResultTitle = $"Allocation {publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.Name} was {publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Status}", AllocationResultId = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.FeedIndexId, AllocationAmount = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Value.HasValue ? publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Value.Value : 0, AllocationMajorVersion = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Major, AllocationMinorVersion = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Minor, AllocationLine = new AllocationLine { Id = publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.Id, Name = publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.Name, ShortName = publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.ShortName, FundingRoute = publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.FundingRoute.ToString(), ContractRequired = publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.IsContractRequired ? "Y" : "N" }, AllocationStatus = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Status.ToString(), FundingStream = new AllocationFundingStreamModel { Id = publishedProviderResult.FundingStreamResult.FundingStream.Id, Name = publishedProviderResult.FundingStreamResult.FundingStream.Name, ShortName = publishedProviderResult.FundingStreamResult.FundingStream.ShortName, PeriodType = new AllocationFundingStreamPeriodTypeModel { Id = publishedProviderResult.FundingStreamResult.FundingStream.PeriodType.Id, Name = publishedProviderResult.FundingStreamResult.FundingStream.PeriodType.Id, StartDay = publishedProviderResult.FundingStreamResult.FundingStream.PeriodType.StartDay, StartMonth = publishedProviderResult.FundingStreamResult.FundingStream.PeriodType.StartMonth, EndDay = publishedProviderResult.FundingStreamResult.FundingStream.PeriodType.EndDay, EndMonth = publishedProviderResult.FundingStreamResult.FundingStream.PeriodType.EndMonth, } }, Period = new Period { Id = publishedProviderResult.FundingPeriod.Id, Name = publishedProviderResult.FundingPeriod.Name, StartYear = publishedProviderResult.FundingPeriod.StartYear, EndYear = publishedProviderResult.FundingPeriod.EndYear }, Provider = new AllocationProviderModel { Name = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.Name, LegalName = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.LegalName, UkPrn = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.UKPRN, Upin = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.UPIN, Urn = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.URN, DfeEstablishmentNumber = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.DfeEstablishmentNumber, EstablishmentNumber = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.EstablishmentNumber, LaCode = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.LACode, LocalAuthority = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.Authority, Type = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.ProviderType, SubType = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.ProviderSubType, OpenDate = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.DateOpened, CloseDate = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.DateClosed, CrmAccountId = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.CrmAccountId, NavVendorNo = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.NavVendorNo, Status = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.Status, ProviderId = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.Id, ProviderVariation = providerVariation }, ProfilePeriods = publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.ProfilingPeriods != null ? new List <ProfilePeriod>(publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.ProfilingPeriods .Select(m => new ProfilePeriod { DistributionPeriod = m.DistributionPeriod, Occurrence = m.Occurrence, Period = m.Period, PeriodType = m.Type, PeriodYear = m.Year.ToString(), ProfileValue = m.Value }) .ToArraySafe()) : new List <ProfilePeriod>(), }); }
public async Task ReIndexAllocationNotificationFeeds_GivenResultHasProviderDataChange_AndHasNotBeenVariedInAnyOtherWay_IndexesAndReturnsNoContentResult() { //Arrange Message message = new Message(); const string specificationId = "spec-1"; IEnumerable <PublishedProviderResult> results = CreatePublishedProviderResultsWithDifferentProviders(); foreach (PublishedProviderResult result in results) { result.FundingStreamResult.AllocationLineResult.Current.Status = AllocationLineStatus.Approved; result.FundingStreamResult.AllocationLineResult.Current.ProfilingPeriods = new[] { new ProfilingPeriod() }; result.FundingStreamResult.AllocationLineResult.Current.FinancialEnvelopes = new[] { new FinancialEnvelope() }; result.FundingStreamResult.AllocationLineResult.Current.Calculations = new[] { new PublishedProviderCalculationResult { CalculationSpecification = new Common.Models.Reference("calc-id-1", "calc1"), Policy = new PolicySummary("policy-id-1", "policy1", "desc") }, new PublishedProviderCalculationResult { CalculationSpecification = new Common.Models.Reference("calc-id-2", "calc2"), Policy = new PolicySummary("policy-id-1", "policy1", "desc") }, new PublishedProviderCalculationResult { CalculationSpecification = new Common.Models.Reference("calc-id-3", "calc3"), Policy = new PolicySummary("policy-id-2", "policy2", "desc") }, }; } PublishedAllocationLineResult publishedAllocationLineResult = results.First().FundingStreamResult.AllocationLineResult; publishedAllocationLineResult.HasResultBeenVaried = false; publishedAllocationLineResult.Current.VariationReasons = new[] { VariationReason.AuthorityFieldUpdated, VariationReason.NameFieldUpdated }; IPublishedProviderResultsRepository repository = CreatePublishedProviderResultsRepository(); repository .GetAllNonHeldPublishedProviderResults() .Returns(results); IEnumerable <PublishedAllocationLineResultVersion> history = results.Select(m => m.FundingStreamResult.AllocationLineResult.Current); history.ElementAt(0).Status = AllocationLineStatus.Approved; history.ElementAt(1).Status = AllocationLineStatus.Approved; history.ElementAt(2).Status = AllocationLineStatus.Published; foreach (var providerVersion in history.GroupBy(c => c.PublishedProviderResultId)) { if (providerVersion.Any()) { IEnumerable <PublishedAllocationLineResultVersion> providerHistory = providerVersion.AsEnumerable(); string providerId = providerHistory.First().ProviderId; providerId .Should() .NotBeNullOrWhiteSpace(); repository .GetAllNonHeldPublishedProviderResultVersions(Arg.Is(providerVersion.Key), Arg.Is(providerId)) .Returns(providerHistory); } } ILogger logger = CreateLogger(); ISearchRepository <AllocationNotificationFeedIndex> searchRepository = CreateAllocationNotificationFeedSearchRepository(); SpecificationCurrentVersion specification = CreateSpecification(specificationId); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(); specificationsRepository .GetCurrentSpecificationById(Arg.Is(specificationId)) .Returns(specification); IEnumerable <AllocationNotificationFeedIndex> resultsBeingSaved = null; await searchRepository .Index(Arg.Do <IEnumerable <AllocationNotificationFeedIndex> >(r => resultsBeingSaved = r)); PublishedResultsService resultsService = CreateResultsService( logger, publishedProviderResultsRepository: repository, allocationNotificationFeedSearchRepository: searchRepository, specificationsRepository: specificationsRepository); //Act await resultsService.ReIndexAllocationNotificationFeeds(message); //Assert await searchRepository .Received(1) .Index(Arg.Is <IEnumerable <AllocationNotificationFeedIndex> >(m => m.Count() == 3)); AllocationNotificationFeedIndex feedResult = resultsBeingSaved.FirstOrDefault(m => m.ProviderId == "1111"); feedResult.ProviderId.Should().Be("1111"); feedResult.Title.Should().Be("Allocation test allocation line 1 was Approved"); feedResult.Summary.Should().Be("UKPRN: 1111, version 0.1"); feedResult.DatePublished.HasValue.Should().Be(false); feedResult.FundingStreamId.Should().Be("fs-1"); feedResult.FundingStreamName.Should().Be("funding stream 1"); feedResult.FundingPeriodId.Should().Be("1819"); feedResult.ProviderUkPrn.Should().Be("1111"); feedResult.ProviderUpin.Should().Be("2222"); feedResult.AllocationLineId.Should().Be("AAAAA"); feedResult.AllocationLineName.Should().Be("test allocation line 1"); feedResult.AllocationVersionNumber.Should().Be(1); feedResult.AllocationAmount.Should().Be(50.0); feedResult.ProviderProfiling.Should().Be("[{\"period\":null,\"occurrence\":0,\"periodYear\":0,\"periodType\":null,\"profileValue\":0.0,\"distributionPeriod\":null}]"); feedResult.ProviderName.Should().Be("test provider name 1"); feedResult.LaCode.Should().Be("77777"); feedResult.Authority.Should().Be("London"); feedResult.ProviderType.Should().Be("test type"); feedResult.SubProviderType.Should().Be("test sub type"); feedResult.EstablishmentNumber.Should().Be("es123"); feedResult.FundingPeriodStartYear.Should().Be(DateTime.Now.Year); feedResult.FundingPeriodEndYear.Should().Be(DateTime.Now.Year + 1); feedResult.FundingStreamStartDay.Should().Be(1); feedResult.FundingStreamStartMonth.Should().Be(8); feedResult.FundingStreamEndDay.Should().Be(31); feedResult.FundingStreamEndMonth.Should().Be(7); feedResult.FundingStreamPeriodName.Should().Be("period-type 1"); feedResult.FundingStreamPeriodId.Should().Be("pt1"); feedResult.AllocationLineContractRequired.Should().Be(true); feedResult.AllocationLineFundingRoute.Should().Be("LA"); feedResult.AllocationLineShortName.Should().Be("tal1"); feedResult.PolicySummaries.Should().Be("[{\"policy\":{\"description\":\"test decscription\",\"parentPolicyId\":null,\"id\":\"policy-1\",\"name\":\"policy one\"},\"policies\":[{\"policy\":{\"description\":\"test decscription\",\"parentPolicyId\":null,\"id\":\"subpolicy-1\",\"name\":\"sub policy one\"},\"policies\":[],\"calculations\":[]}],\"calculations\":[]}]"); feedResult.Calculations.Should().Be("[{\"calculationName\":\"calc1\",\"calculationDisplayName\":\"calc1\",\"calculationVersion\":0,\"calculationType\":\"Number\",\"calculationAmount\":null,\"allocationLineId\":\"AAAAA\",\"policyId\":\"policy-id-1\",\"policyName\":\"policy1\"},{\"calculationName\":\"calc2\",\"calculationDisplayName\":\"calc2\",\"calculationVersion\":0,\"calculationType\":\"Number\",\"calculationAmount\":null,\"allocationLineId\":\"AAAAA\",\"policyId\":\"policy-id-1\",\"policyName\":\"policy1\"},{\"calculationName\":\"calc3\",\"calculationDisplayName\":\"calc3\",\"calculationVersion\":0,\"calculationType\":\"Number\",\"calculationAmount\":null,\"allocationLineId\":\"AAAAA\",\"policyId\":\"policy-id-2\",\"policyName\":\"policy2\"}]"); feedResult.OpenReason.Should().BeNull(); feedResult.CloseReason.Should().BeNull(); feedResult.Predecessors.Should().BeNull(); feedResult.Successors.Should().BeNull(); }