Exemple #1
0
 private Dictionary <string, string> JobProperties(FundingLineCsvGeneratorJobType jobType,
                                                   string fundingLineCode,
                                                   string fundingStreamId,
                                                   string fundingPeriodId)
 {
     return(new Dictionary <string, string>
     {
         { "job-type", jobType.ToString() },
         { "funding-line-code", fundingLineCode },
         { "funding-stream-id", fundingStreamId },
         { "funding-period-id", fundingPeriodId },
     });
 }
Exemple #2
0
 private void ThenTheJobWasCreated(string specificationId,
                                   string correlationId,
                                   Reference user,
                                   FundingLineCsvGeneratorJobType jobType,
                                   string fundingLineCode,
                                   string fundingStreamId)
 {
     CreateGeneratePublishedFundingCsvJobs.Verify(_ => _.CreateJob(specificationId, user, correlationId,
                                                                   It.Is <Dictionary <string, string> >(props
                                                                                                        => props.ContainsKey(JobType) &&
                                                                                                        props[JobType] == jobType.ToString() &&
                                                                                                        props.ContainsKey(FundingLineCode) &&
                                                                                                        props[FundingLineCode] == fundingLineCode &&
                                                                                                        props.ContainsKey(FundingStreamId) &&
                                                                                                        props[FundingStreamId] == fundingStreamId),
                                                                   null,
                                                                   null,
                                                                   false),
                                                  Times.Once);
 }
Exemple #3
0
        public async Task TransformsPublishedProvidersForSpecificationInBatchesAndCreatesCsvWithResultsOrFailJob(
            FundingLineCsvGeneratorJobType jobType,
            string specificationId,
            string fundingLineCode,
            string fundingStreamId,
            string fundingPeriodId,
            string expectedFileName,
            string expectedContentDisposition,
            bool throwException)
        {
            string jobId = NewRandomString();
            string expectedInterimFilePath = Path.Combine(_rootPath, expectedFileName);

            MemoryStream incrementalFileStream = new MemoryStream();

            string predicate = NewRandomString();

            GivenTheMessageProperties(("specification-id", specificationId),
                                      ("job-type", jobType.ToString()),
                                      ("jobId", jobId),
                                      ("funding-line-code", fundingLineCode),
                                      ("funding-period-id", fundingPeriodId),
                                      ("funding-stream-id", fundingStreamId));
            AndTheCloudBlobForFileName(expectedFileName);
            AndTheFileStream(expectedInterimFilePath, incrementalFileStream);
            AndTheFileExists(expectedInterimFilePath);
            AndTheTransformForJobType(jobType);
            AndThePredicate(jobType, predicate);
            AndTheJobExists(jobId);
            AndTheBatchProcessorForJobType(jobType);
            AndTheBatchProcessorProcessedResults(jobType, specificationId, fundingPeriodId, expectedInterimFilePath, fundingLineCode, fundingStreamId);

            string errorMessage = "Unable to complete funding line csv generation job.";

            if (throwException)
            {
                AndTheBlobThrowsError(incrementalFileStream, new NonRetriableException(errorMessage));

                Func <Task> test = async() => await WhenTheCsvIsGenerated();

                test
                .Should()
                .ThrowExactly <NonRetriableException>()
                .Which
                .Message
                .Should()
                .Be(errorMessage);
            }
            else
            {
                await WhenTheCsvIsGenerated();
            }

            _jobManagement.Verify(_ => _.UpdateJobStatus(jobId, 0, 0, null, null),
                                  Times.Once);

            _fileSystemAccess
            .Verify(_ => _.Delete(expectedInterimFilePath),
                    Times.Once);

            _blobProperties?.ContentDisposition
            .Should()
            .StartWith($"attachment; filename={expectedContentDisposition} {DateTimeOffset.UtcNow:yyyy-MM-dd}")
            .And
            .NotContain(":");

            _blobClient
            .Verify(_ => _.UploadFileAsync(_cloudBlob.Object, incrementalFileStream),
                    Times.Once);

            if (throwException)
            {
                _jobManagement.Verify(_ => _.UpdateJobStatus(jobId, 0, 0, false, errorMessage),
                                      Times.Once);
            }
            else
            {
                _jobManagement.Verify(_ => _.UpdateJobStatus(jobId, 0, 0, true, null),
                                      Times.Once);
            }
        }
Exemple #4
0
        public async Task ExitsEarlyIfNoProvidersMatchForTheJobTypePredicate()
        {
            string specificationId                 = NewRandomString();
            string fundingLineCode                 = NewRandomString();
            string jobId                           = NewRandomString();
            string expectedInterimFilePath         = Path.Combine(_rootPath, $"funding-lines-{specificationId}-Released-{fundingLineCode}.csv");
            FundingLineCsvGeneratorJobType jobType = FundingLineCsvGeneratorJobType.Released;

            GivenTheMessageProperties(("specification-id", specificationId), ("job-type", jobType.ToString()), ("jobId", jobId), ("funding-line-code", fundingLineCode));
            AndTheFileExists(expectedInterimFilePath);
            AndTheJobExists(jobId);
            AndTheTransformForJobType(jobType);
            AndTheBatchProcessorForJobType(jobType);

            await WhenTheCsvIsGenerated();

            _jobManagement.Verify(_ => _.UpdateJobStatus(jobId, 0, 0, null, null),
                                  Times.Once);

            _fileSystemAccess
            .Verify(_ => _.Delete(expectedInterimFilePath),
                    Times.Once);

            _fileSystemAccess
            .Verify(_ => _.Append(expectedInterimFilePath,
                                  It.IsAny <string>(),
                                  default),
                    Times.Never);

            _blobClient
            .Verify(_ => _.UploadFileAsync(_cloudBlob.Object, It.IsAny <Stream>()),
                    Times.Never);

            _jobManagement.Verify(_ => _.UpdateJobStatus(jobId, 0, 0, true, null),
                                  Times.Once);
        }