Exemplo n.º 1
0
        public async Task QueueCsvGenerationMessages_GivenSpecificationSummariesFoundButNoResults_DoesNotCreateNewMessages()
        {
            //Arrange
            IEnumerable <SpecModel.SpecificationSummary> specificationSummaries = new[]
            {
                new SpecModel.SpecificationSummary {
                    Id = "spec-1"
                }
            };

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaries()
            .Returns(new ApiResponse <IEnumerable <SpecModel.SpecificationSummary> >(HttpStatusCode.OK, specificationSummaries));

            ICalculationResultsRepository calculationResultsRepository = CreateResultsRepository();

            calculationResultsRepository
            .ProviderHasResultsBySpecificationId(
                Arg.Is("spec-1"))
            .Returns(false);

            IBlobClient blobClient = CreateBlobClient();

            blobClient
            .DoesBlobExistAsync($"{CalculationResultsReportFilePrefix}-spec-1", CalcsResultsContainerName)
            .Returns(false);

            ILogger logger = CreateLogger();

            IJobManagement jobManagement = CreateJobManagement();

            ResultsService resultsService = CreateResultsService(
                logger,
                specificationsApiClient: specificationsApiClient,
                resultsRepository: calculationResultsRepository,
                jobManagement: jobManagement,
                blobClient: blobClient);

            //Act
            await resultsService.QueueCsvGenerationMessages();

            //Assert
            await
            jobManagement
            .DidNotReceive()
            .QueueJob(Arg.Any <JobCreateModel>());

            logger
            .DidNotReceive()
            .Information($"Found new calculation results for specification id 'spec-1'");
        }
        public async Task CreateInstructGenerateAggregationsAllocationJob_GivenJobNotSucceeeded_DoesNotCreateNewJob()
        {
            //Arrange
            JobSummary jobNotification = CreateJobSummary();

            jobNotification.CompletionStatus = CompletionStatus.Cancelled;

            string json = JsonConvert.SerializeObject(jobNotification);

            Message message = new Message(Encoding.UTF8.GetBytes(json));

            IJobManagement jobManagement = CreateJobManagement();

            JobService jobService = CreateJobService();

            //Act
            await jobService.Process(message);

            //Assert
            await
            jobManagement
            .DidNotReceive()
            .QueueJob(Arg.Any <JobCreateModel>());
        }
        public async Task CreateInstructGenerateAggregationsAllocationJob_GivenNotCorrectJobType_DoesNotCreateNewJob()
        {
            //Arrange
            JobSummary jobNotification = CreateJobSummary();

            jobNotification.JobType = JobConstants.DefinitionNames.GenerateCalculationAggregationsJob;

            string json = JsonConvert.SerializeObject(jobNotification);

            Message message = new Message(Encoding.UTF8.GetBytes(json));

            IJobManagement jobManagement = CreateJobManagement();

            JobService jobService = CreateJobService(jobManagement);

            //Act
            await jobService.Process(message);

            //Assert
            await
            jobManagement
            .DidNotReceive()
            .QueueJob(Arg.Any <JobCreateModel>());
        }
        public async Task ProcessDeadLetteredMessage_GivenMessageButNoJobId_LogsAnErrorAndDoesNotUpdadeJobLog()
        {
            // Arrange
            Message message = new Message();

            IJobManagement jobManagement = CreateJobManagement();

            ILogger logger = CreateLogger();

            IDeadletterService service = CreateJobHelperService(jobManagement, logger);

            // Act
            await service.Process(message);

            // Assert
            logger
            .Received(1)
            .Error(Arg.Is("Missing job id from dead lettered message"));

            await
            jobManagement
            .DidNotReceive()
            .AddJobLog(Arg.Any <string>(), Arg.Any <JobLogUpdateModel>());
        }