Пример #1
0
        public async Task TransformsPublishedFundingForSpecificationInBatchesAndCreatesCsvWithResults()
        {
            string specificationId = NewRandomString();
            string fundingPeriodId = NewRandomString();
            string fundingLineCode = NewRandomString();
            string fundingStreamId = NewRandomString();

            string expectedInterimFilePath = NewRandomString();

            IEnumerable <PublishedFundingVersion> publishedFundingVersionsOne = new[]
            {
                NewPublishedFundingVersion()
            };
            IEnumerable <PublishedFundingVersion> publishedFundingVersionsTwo = new[]
            {
                NewPublishedFundingVersion(), NewPublishedFundingVersion(), NewPublishedFundingVersion()
            };

            ExpandoObject[] transformedRowsOne =
            {
                new ExpandoObject(), new ExpandoObject(), new ExpandoObject(), new ExpandoObject()
            };
            ExpandoObject[] transformedRowsTwo =
            {
                new ExpandoObject(), new ExpandoObject(), new ExpandoObject(), new ExpandoObject()
            };

            string expectedCsvOne = NewRandomString();
            string expectedCsvTwo = NewRandomString();

            GivenTheCsvRowTransformation(publishedFundingVersionsOne, transformedRowsOne, expectedCsvOne, true);
            AndTheCsvRowTransformation(publishedFundingVersionsTwo, transformedRowsTwo, expectedCsvTwo, false);

            PublishedFunding.Setup(_ => _.PublishedFundingVersionBatchProcessing(specificationId,
                                                                                 fundingStreamId,
                                                                                 fundingPeriodId,
                                                                                 It.IsAny <Func <List <PublishedFundingVersion>, Task> >(),
                                                                                 100))
            .Callback <string, string, string, Func <List <PublishedFundingVersion>, Task>, int>((spec,
                                                                                                  stream,
                                                                                                  period,
                                                                                                  batchProcessor,
                                                                                                  batchSize) =>
            {
                batchProcessor(publishedFundingVersionsOne.ToList())
                .GetAwaiter()
                .GetResult();

                batchProcessor(publishedFundingVersionsTwo.ToList())
                .GetAwaiter()
                .GetResult();
            })
            .Returns(Task.CompletedTask);

            bool processedResults = await WhenTheCsvIsGenerated(FundingLineCsvGeneratorJobType.HistoryOrganisationGroupValues,
                                                                specificationId,
                                                                fundingPeriodId,
                                                                expectedInterimFilePath,
                                                                fundingLineCode,
                                                                fundingStreamId);

            processedResults
            .Should()
            .BeTrue();

            FileSystemAccess
            .Verify(_ => _.Append(expectedInterimFilePath,
                                  expectedCsvOne,
                                  default),
                    Times.Once);

            FileSystemAccess
            .Verify(_ => _.Append(expectedInterimFilePath,
                                  expectedCsvTwo,
                                  default),
                    Times.Once);
        }
Пример #2
0
        public async Task TransformsPublishedGroupsForSpecificationInBatchesAndCreatesCsvWithResults(
            FundingLineCsvGeneratorJobType jobType)
        {
            string specificationId = NewRandomString();
            string fundingPeriodId = NewRandomString();
            string fundingLineCode = NewRandomString();
            string fundingStreamId = NewRandomString();

            string expectedInterimFilePath = NewRandomString();

            IEnumerable <PublishedFunding> publishedFundingOne = new List <PublishedFunding>
            {
                NewPublishedFunding(_ => _.WithCurrent(
                                        NewPublishedFundingVersion(ppv => ppv.WithFundingId("f-id")
                                                                   .WithProviderFundings(new List <string>())))),
            };

            IEnumerable <PublishedFunding> publishedFundingWithProviderTwo = new[]
            {
                NewPublishedFunding(_ => _.WithCurrent(
                                        NewPublishedFundingVersion(ppv => ppv.WithFundingId("f-id1")))),
                NewPublishedFunding(_ => _.WithCurrent(
                                        NewPublishedFundingVersion(ppv => ppv.WithFundingId("f-id2")))),
                NewPublishedFunding(_ => _.WithCurrent(
                                        NewPublishedFundingVersion(ppv => ppv.WithFundingId("f-id3"))))
            };

            ExpandoObject[] transformedRowsOne =
            {
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
            };
            ExpandoObject[] transformedRowsTwo =
            {
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
            };

            string expectedCsvOne = NewRandomString();
            string expectedCsvTwo = NewRandomString();

            string predicate     = NewRandomString();
            string joinPredicate = NewRandomString();

            GivenTheCsvRowTransformation(publishedFundingOne, transformedRowsOne, expectedCsvOne, true);
            AndTheCsvRowTransformation(publishedFundingWithProviderTwo, transformedRowsTwo, expectedCsvTwo, false);
            AndThePredicate(jobType, predicate);
            AndTheJoinPredicate(jobType, joinPredicate);

            PublishedFunding.Setup(_ => _.PublishedGroupBatchProcessing(specificationId,
                                                                        It.IsAny <Func <List <PublishedFunding>, Task> >(),
                                                                        100))
            .Callback <string, Func <List <PublishedFunding>, Task>, int>((spec,
                                                                           batchProcessor, batchSize) =>
            {
                batchProcessor(publishedFundingOne.ToList())
                .GetAwaiter()
                .GetResult();
            })
            .Returns(Task.CompletedTask);

            bool processedResults = await WhenTheCsvIsGenerated(jobType, specificationId, fundingPeriodId, expectedInterimFilePath, fundingLineCode, fundingStreamId);

            processedResults
            .Should()
            .BeTrue();
        }
        public async Task TransformsPublishedProvidersForSpecificationInBatchesAndCreatesCsvWithResults(
            FundingLineCsvGeneratorJobType jobType)
        {
            string specificationId = NewRandomString();
            string fundingPeriodId = NewRandomString();
            string fundingLineCode = NewRandomString();
            string fundingStreamId = NewRandomString();

            string expectedInterimFilePath = NewRandomString();

            IEnumerable <PublishedProvider> publishProvidersOne = new []
            {
                NewPublishedProvider(),
            };
            IEnumerable <PublishedProvider> publishedProvidersTwo = new []
            {
                NewPublishedProvider(),
                NewPublishedProvider(),
                NewPublishedProvider()
            };

            ExpandoObject[] transformedRowsOne =
            {
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
            };
            ExpandoObject[] transformedRowsTwo =
            {
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
                new ExpandoObject(),
            };

            string expectedCsvOne = NewRandomString();
            string expectedCsvTwo = NewRandomString();

            string predicate     = NewRandomString();
            string joinPredicate = NewRandomString();

            GivenTheCsvRowTransformation(publishProvidersOne, transformedRowsOne, expectedCsvOne, true);
            AndTheCsvRowTransformation(publishedProvidersTwo, transformedRowsTwo, expectedCsvTwo, false);
            AndThePredicate(jobType, predicate);
            AndTheJoinPredicate(jobType, joinPredicate);

            PublishedFunding.Setup(_ => _.PublishedProviderBatchProcessing(predicate,
                                                                           specificationId,
                                                                           It.IsAny <Func <List <PublishedProvider>, Task> >(),
                                                                           100,
                                                                           joinPredicate,
                                                                           fundingLineCode))
            .Callback <string, string, Func <List <PublishedProvider>, Task>, int, string, string>((pred, spec,
                                                                                                    batchProcessor, batchSize, joinPred, flc) =>
            {
                batchProcessor(publishProvidersOne.ToList())
                .GetAwaiter()
                .GetResult();

                batchProcessor(publishedProvidersTwo.ToList())
                .GetAwaiter()
                .GetResult();
            })
            .Returns(Task.CompletedTask);

            bool processedResults = await WhenTheCsvIsGenerated(jobType, specificationId, fundingPeriodId, expectedInterimFilePath, fundingLineCode, fundingStreamId);

            processedResults
            .Should()
            .BeTrue();

            FileSystemAccess
            .Verify(_ => _.Append(expectedInterimFilePath,
                                  expectedCsvOne,
                                  default),
                    Times.Once);

            FileSystemAccess
            .Verify(_ => _.Append(expectedInterimFilePath,
                                  expectedCsvTwo,
                                  default),
                    Times.Once);
        }