private static List <PeriodDto> MapPeriods(string priceEpisodeIdentifier, DatalockEvent datalockEvent) { var nonPayablePeriods = datalockEvent.NonPayablePeriods .Where(d => d.PriceEpisodeIdentifier == priceEpisodeIdentifier) .SelectMany(nonPayablePeriod => nonPayablePeriod.Failures.GroupBy(failure => new PeriodDto { Period = nonPayablePeriod.DeliveryPeriod, IsPayable = false, AccountId = failure.Apprenticeship?.AccountId ?? 0, ApprenticeshipId = failure.ApprenticeshipId, ApprenticeshipEmployerType = failure.Apprenticeship?.ApprenticeshipEmployerType ?? 0, TransferSenderAccountId = failure.Apprenticeship?.TransferSendingEmployerAccountId ?? 0 }).Select(group => { var period = group.Key; period.DataLockFailures = group.Select(failure => (int)failure.DataLockFailureId).ToList(); return(period); })); var payablePeriods = datalockEvent.PayablePeriods .Where(d => d.PriceEpisodeIdentifier == priceEpisodeIdentifier) .Select(payablePeriod => new PeriodDto { Period = payablePeriod.DeliveryPeriod, IsPayable = true, AccountId = payablePeriod.Apprenticeship?.AccountId ?? 0, ApprenticeshipId = payablePeriod.ApprenticeshipId, ApprenticeshipEmployerType = payablePeriod.Apprenticeship?.ApprenticeshipEmployerType ?? 0, TransferSenderAccountId = payablePeriod.Apprenticeship?.TransferSendingEmployerAccountId ?? 0, }); return(payablePeriods.Union(nonPayablePeriods).ToList()); }
public void SetUp() { var fixture = new Fixture(); _ukprn = fixture.Create <long>(); _uln = fixture.Create <long>(); _jobId = fixture.Create <long>(); _academicYear = fixture.Create <short>(); _collectionPeriod = fixture.Create <byte>(); _datalockEvent = fixture.Create <DatalockEvent>(); _datalockEvent.PayablePeriods.Clear(); _datalockEvent.NonPayablePeriods.Clear(); _datalockEvent.PriceEpisodes.Clear(); _latestSuccessfulJob = fixture.Create <LatestSuccessfulJobModel>(); _latestSuccessfulJob.Ukprn = _ukprn; _latestSuccessfulJob.AcademicYear = _academicYear; _latestSuccessfulJob.CollectionPeriod = _collectionPeriod; _latestSuccessfulJob.DcJobId = _jobId; _datalockEventNonPayablePeriod = fixture.Create <DatalockEventNonPayablePeriod>(); _datalockEventPayablePeriod = fixture.Create <DatalockEventPayablePeriod>(); _datalockEventPriceEpisode = fixture.Create <DatalockEventPriceEpisode>(); _context = new PaymentsContext(new DbContextOptionsBuilder <PaymentsContext>() .UseInMemoryDatabase("TestDb", new InMemoryDatabaseRoot()) .Options); _sut = new PaymentsDataLockRepository(_context); }
private static List <PriceEpisodeDto> MapPriceEpisodes(DatalockEvent dataLockEvent) { return(dataLockEvent.PriceEpisodes.Select(priceEpisode => new PriceEpisodeDto { Identifier = priceEpisode.PriceEpisodeIdentifier, AgreedPrice = priceEpisode.AgreedPrice, StartDate = priceEpisode.StartDate, EndDate = priceEpisode.ActualEndDate, NumberOfInstalments = priceEpisode.NumberOfInstalments, InstalmentAmount = priceEpisode.InstalmentAmount, CompletionAmount = priceEpisode.CompletionAmount, Periods = MapPeriods(priceEpisode.PriceEpisodeIdentifier, dataLockEvent), }).ToList()); }