public async Task TestRegistrations()
        {
            try
            {
                JobContextMessage jobContextMessage =
                    new JobContextMessage(
                        1,
                        new ITopicItem[] { new TopicItem("SubscriptionName", new List <ITaskItem>()) },
                        0,
                        DateTime.UtcNow);
                jobContextMessage.KeyValuePairs[JobContextMessageKey.Container] = "Container";
                CancellationTokenSource cts = new CancellationTokenSource();
                cts.Cancel();

                ContainerBuilder containerBuilder = DIComposition.BuildContainer(new TestConfigurationHelper());

                IContainer c = containerBuilder.Build();
                using (var lifeTime = c.BeginLifetimeScope())
                {
                    var  messageHandler = lifeTime.Resolve <IMessageHandler <JobContextMessage> >();
                    bool ret            = await messageHandler.HandleAsync(jobContextMessage, cts.Token);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Assert.Null(ex);
            }
        }
Пример #2
0
        private static JobContextMessage CreatePeriodEndJobContextMessage(PeriodEndTaskType taskType)
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    taskType.ToString()
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object>
                {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 }
                }
            };

            return(jobContextMessage);
        }
        public async Task Waits_For_Job_To_Complete(string task, int numberOfTimes)
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    task
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 }
                }
            };
            var handler   = mocker.Create <PeriodEndJobContextMessageHandler>();
            var completed = await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            mocker.Mock <IJobStatusService>()
            .Verify(svc => svc.WaitForJobToFinish(It.Is <long>(jobId => jobId == 1), CancellationToken.None), Times.Exactly(numberOfTimes));
        }
        public async Task Fails_If_No_Collection_Year()
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "Some Task"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 }
                }
            };

            var handler = mocker.Create <PeriodEndJobContextMessageHandler>();

            Assert.ThrowsAsync <InvalidOperationException>(() => handler.HandleAsync(jobContextMessage, CancellationToken.None));
        }
        public async Task Records_Period_End_Started_Job_From_Period_End_Start_Task()
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "PeriodEndStart"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 }
                }
            };

            var handler = mocker.Create <PeriodEndJobContextMessageHandler>();
            await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            mocker.Mock <IPeriodEndJobClient>()
            .Verify(x => x.RecordPeriodEndStart(It.Is <long>(jobId => jobId == 1), It.Is <short>(collectionYear => collectionYear == 1819), It.Is <byte>(period => period == 10),
                                                It.Is <List <GeneratedMessage> >(msgs => msgs.Any(msg => msg.MessageName.Equals(typeof(PeriodEndStartedEvent).FullName)))), Times.Once);
        }
Пример #6
0
        private async Task <bool> Callback(JobContextMessage jobContextMessage, CancellationToken cancellationToken)
        {
            try
            {
                await _auditor.AuditStartAsync(jobContextMessage);

                T obj = _mapper.MapTo(jobContextMessage);
                if (!await _callback.Invoke(obj, cancellationToken))
                {
                    await _auditor.AuditJobFailAsync(jobContextMessage);

                    return(false);
                }

                jobContextMessage = _mapper.MapFrom(obj);
                jobContextMessage.TopicPointer++;
                await _auditor.AuditEndAsync(jobContextMessage);

                if (jobContextMessage.TopicPointer >= jobContextMessage.Topics.Count)
                {
                    return(true);
                }

                await _queuePublishService.PublishAsync(jobContextMessage);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception thrown in JobManager callback", ex);
                await _auditor.AuditJobFailAsync(jobContextMessage);

                return(false);
            }

            return(true);
        }
        public async Task <MessageParameters> CreateMessageParametersAsync(long jobId)
        {
            FileUploadJob job = await _fileUploadJobManager.GetJobById(jobId);

            List <ITopicItem> topics = (await _jobTopicTaskService.GetTopicItems(job.JobType, job.IsFirstStage)).ToList();

            JobContextMessage contextMessage = new JobContextMessage(
                job.JobId,
                topics,
                job.Ukprn.ToString(),
                job.StorageReference,
                job.FileName,
                job.SubmittedBy,
                0,
                job.DateTimeSubmittedUtc);

            contextMessage.KeyValuePairs.Add("CollectionName", job.CollectionName);
            contextMessage.KeyValuePairs.Add("ReturnPeriod", job.PeriodNumber);

            AddExtraKeys(contextMessage, job);

            MessageParameters message = new MessageParameters(job.JobType)
            {
                JobContextMessage = contextMessage,
                SubscriptionLabel = topics[0].SubscriptionName,
                TopicParameters   = new Dictionary <string, object>
                {
                    {
                        "To", topics[0].SubscriptionName
                    }
                }
            };

            return(message);
        }
Пример #8
0
 public async Task SendMessageAsync(MessageParameters messageParameters)
 {
     JobContextMessage jobContextMessage = (JobContextMessage)messageParameters.JobContextMessage;
     await             _topicPublishServices[messageParameters.JobType].PublishAsync(
         _jobContextMapper.MapFrom(jobContextMessage),
         messageParameters.TopicParameters,
         messageParameters.SubscriptionLabel);
 }
        public async Task Uses_Correct_Filename_For_In_Period_Submission()
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "GenerateFM36Payments",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    JobContextMessageConstants.Tasks.ProcessSubmission
                                }
                            }
                        }
                    },
                    new TopicItem
                    {
                        SubscriptionName = "Other Task",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "Something else"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 },
                    { JobContextMessageConstants.KeyValuePairs.Ukprn, 2123 },
                    { JobContextMessageConstants.KeyValuePairs.FundingFm36Output, "valid path" },
                    { JobContextMessageConstants.KeyValuePairs.FundingFm36OutputPeriodEnd, "invalid path" },
                    { JobContextMessageConstants.KeyValuePairs.Container, "container" },
                    { JobContextMessageConstants.KeyValuePairs.Filename, "filename" },
                }
            };

            var handler = mocker.Create <JobContextMessageHandler>();
            await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            mocker.Mock <IFileService>().Verify(svc => svc.OpenReadStreamAsync(
                                                    It.Is <string>(file => file.Equals("valid path")),
                                                    It.Is <string>(containerName => containerName.Equals("container")),
                                                    It.IsAny <CancellationToken>()));
        }
        public async Task HandlesSubmissionWhenJobFailureAlsoPresent()
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId        = 1,
                TopicPointer = 1,
                Topics       = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "GenerateFM36Payments",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    JobContextMessageConstants.Tasks.JobFailure
                                }
                            }
                        }
                    },
                    new TopicItem
                    {
                        SubscriptionName = "Other Task",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "Something else"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 },
                    { JobContextMessageConstants.KeyValuePairs.Ukprn, 2123 },
                    { JobContextMessageConstants.KeyValuePairs.FundingFm36Output, "invalid path" },
                    { JobContextMessageConstants.KeyValuePairs.FundingFm36OutputPeriodEnd, "valid path" },
                    { JobContextMessageConstants.KeyValuePairs.Container, "container" },
                    { JobContextMessageConstants.KeyValuePairs.Filename, "filename" },
                }
            };

            var handler = mocker.Create <JobContextMessageHandler>();
            await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            mocker.Mock <IEndpointInstance>().Verify(x => x.Publish(It.IsAny <object>(), It.IsAny <PublishOptions>()), Times.Once);

            mocker.Mock <ITelemetry>().Verify(x => x.TrackEvent("Sent All ProcessLearnerCommand Messages", It.IsAny <Dictionary <string, string> >(), It.IsAny <Dictionary <string, double> >()));
        }
Пример #11
0
        public void TestJobContextSerialise()
        {
            DateTime dateTime = DateTime.UtcNow;

            var taskItems = new List <ITaskItem>
            {
                new TaskItem(
                    new List <string>
                {
                    "Task 1",
                    "Task 2"
                },
                    true)
            };

            IReadOnlyList <ITopicItem> topics = new List <ITopicItem>
            {
                new TopicItem(
                    "Subscription A",
                    "SqlFilter A",
                    taskItems)
            };

            var jobContextMessage = new JobContextMessage(
                9999, topics, "UkPrn", "Container", "Filename", "Username", 12, dateTime);

            var settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            };

            var serialised = JsonConvert.SerializeObject(jobContextMessage, settings);

            var deserialised = JsonConvert.DeserializeObject <JobContextMessage>(serialised, settings);

            deserialised.JobId.Should().Be(9999);
            deserialised.SubmissionDateTimeUtc.Should().Be(dateTime);
            deserialised.TopicPointer.Should().Be(12);
            deserialised.Topics.Should().BeEquivalentTo(topics);
            deserialised.KeyValuePairs.Should().ContainKey(JobContextMessageKey.UkPrn);
            deserialised.KeyValuePairs[JobContextMessageKey.UkPrn].Should().Be("UkPrn");
            deserialised.KeyValuePairs.Should().ContainKey(JobContextMessageKey.Filename);
            deserialised.KeyValuePairs[JobContextMessageKey.Filename].Should().Be("Filename");
            deserialised.KeyValuePairs.Should().ContainKey(JobContextMessageKey.Container);
            deserialised.KeyValuePairs[JobContextMessageKey.Container].Should().Be("Container");
            deserialised.KeyValuePairs.Should().ContainKey(JobContextMessageKey.Username);
            deserialised.KeyValuePairs[JobContextMessageKey.Username].Should().Be("Username");
        }
        public void AddExtraKeys_Test(bool isFirstStage)
        {
            var message = new JobContextMessage()
            {
                KeyValuePairs = new Dictionary <string, object>()
            };

            var job = new FileUploadJob()
            {
                FileSize             = 123,
                Ukprn                = 999,
                JobId                = 100,
                StorageReference     = "ref",
                FileName             = "filename.xml",
                SubmittedBy          = "test user",
                DateTimeSubmittedUtc = new DateTime(2018, 10, 10),
                IsFirstStage         = isFirstStage,
            };

            message.KeyValuePairs.Add("Filename", job.FileName);

            var factory = GetFactory(isFirstStage, job);

            factory.AddExtraKeys(message, job);

            message.KeyValuePairs[JobContextMessageKey.FileSizeInBytes].Should().Be(123);

            if (isFirstStage)
            {
                message.KeyValuePairs[JobContextMessageKey.PauseWhenFinished].Should().Be("1");
            }
            else
            {
                message.KeyValuePairs.ContainsKey(JobContextMessageKey.PauseWhenFinished).Should().Be(false);
            }

            message.KeyValuePairs.ContainsKey(JobContextMessageKey.InvalidLearnRefNumbers).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.ValidLearnRefNumbers).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.ValidationErrors).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.ValidationErrorLookups).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.FundingAlbOutput).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.FundingFm35Output).Should().BeTrue();
            message.KeyValuePairs.ContainsKey(JobContextMessageKey.FundingFm25Output).Should().BeTrue();
        }
Пример #13
0
        public void TestJobContextMappingDtoToInterface()
        {
            DateTime now = DateTime.UtcNow;

            JobContextDto jobContextDto = new JobContextDto
            {
                SubmissionDateTimeUtc = now,
                JobId         = 12,
                KeyValuePairs = new Dictionary <string, object>
                {
                    { JobContextMessageKey.UkPrn, 12345 }
                },
                TopicPointer = 3,
                Topics       = new List <TopicItemDto>
                {
                    new TopicItemDto
                    {
                        Tasks = new List <TaskItemDto>
                        {
                            new TaskItemDto
                            {
                                Tasks = new List <string>
                                {
                                    "Task A"
                                },
                                SupportsParallelExecution = true
                            }
                        },
                        SubscriptionName = "Subscription A"
                    }
                }
            };

            JobContextMapper  mapper  = new JobContextMapper();
            JobContextMessage message = mapper.MapTo(jobContextDto);

            message.SubmissionDateTimeUtc.Should().Be(now);
            message.JobId.Should().Be(12);
            message.KeyValuePairs.Should().BeEquivalentTo(jobContextDto.KeyValuePairs);
            message.Topics.Should().BeEquivalentTo(jobContextDto.Topics);
            message.TopicPointer.Should().Be(3);
        }
Пример #14
0
        public void TestJobContextMappingInterfaceToDto()
        {
            DateTime now = DateTime.UtcNow;

            List <ITaskItem> tasks = new List <ITaskItem>()
            {
                new TaskItem
                {
                    Tasks = new List <string>
                    {
                        "Task A"
                    },
                    SupportsParallelExecution = true
                }
            };
            var topicItem = new TopicItem("Topic A", "SqlFilter A", tasks);

            JobContextMessage jobContextMessage = new JobContextMessage
            {
                JobId         = 12,
                KeyValuePairs = new Dictionary <string, object>
                {
                    { JobContextMessageKey.UkPrn, 12345 }
                },
                SubmissionDateTimeUtc = now,
                TopicPointer          = 3,
                Topics = new List <ITopicItem>
                {
                    topicItem
                }
            };

            JobContextMapper mapper = new JobContextMapper();
            JobContextDto    dto    = mapper.MapFrom(jobContextMessage);

            dto.SubmissionDateTimeUtc.Should().Be(now);
            dto.JobId.Should().Be(12);
            dto.KeyValuePairs.Should().BeEquivalentTo(jobContextMessage.KeyValuePairs);
            dto.Topics.Should().BeEquivalentTo(jobContextMessage.Topics);
            dto.TopicPointer.Should().Be(3);
        }
Пример #15
0
        public void GetIlrTasks()
        {
            var jobContextMessage = new JobContextMessage
            {
                TopicPointer = 0,
                Topics       = new ITopicItem[]
                {
                    new TopicItem
                    {
                        SubscriptionName = "ReferenceDataRetrieval",
                        Tasks            = new ITaskItem[]
                        {
                            new TaskItem
                            {
                                Tasks = new List <string>
                                {
                                    "DesktopReferenceData",
                                    "IlrMessage",
                                    "LearnerReferenceData",
                                    "FrmReferenceData"
                                },
                                SupportsParallelExecution = false
                            },
                        }
                    }
                }
            };

            var expectedTasks = new List <TaskKeys>
            {
                TaskKeys.IlrMessage,
                TaskKeys.LearnerReferenceData,
                TaskKeys.FrmReferenceData
            };

            var tasks = NewHandler().GetIlrTasks(jobContextMessage);

            tasks.Should().BeEquivalentTo(expectedTasks);
        }
        public async Task Publishes_Period_End_Started_Event_From_Period_End_Start_Task()
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "PeriodEndStart"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 }
                }
            };

            var handler = mocker.Create <PeriodEndJobContextMessageHandler>();
            await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            mocker.Mock <IEndpointInstance>()
            .Verify(x => x.Publish(It.Is <PeriodEndStartedEvent>(startedEvent => startedEvent.JobId == 1 &&
                                                                 startedEvent.CollectionPeriod.Period == 10 &&
                                                                 startedEvent.CollectionPeriod.AcademicYear == 1819),
                                   It.IsAny <PublishOptions>()), Times.Once);
        }
        public async Task Returns_True_Even_If_Job_Not_Completed()
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "PeriodEndStop"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10 },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819 }
                }
            };

            mocker.Mock <IJobStatusService>()
            .Setup(svc => svc.WaitForJobToFinish(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(false);

            var handler   = mocker.Create <PeriodEndJobContextMessageHandler>();
            var completed = await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            completed.Should().BeTrue();
        }
Пример #18
0
        private static JobContextMessage CreateJobContextMessage(string task, bool CreateReturnPeriod = true, bool CreateCollectionYear = true)
        {
            var jobContextMessage = new JobContextMessage
            {
                JobId  = 1,
                Topics = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "PeriodEnd",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    task
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object>()
            };

            if (CreateReturnPeriod)
            {
                jobContextMessage.KeyValuePairs.Add(JobContextMessageConstants.KeyValuePairs.ReturnPeriod, 10);
            }

            if (CreateCollectionYear)
            {
                jobContextMessage.KeyValuePairs.Add(JobContextMessageConstants.KeyValuePairs.CollectionYear, 1819);
            }

            return(jobContextMessage);
        }
 public JobContextMessageSummarisationContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
 public ReportServiceContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
Пример #21
0
        public async Task Job_Submission_Failed_Notifies_Monitoring_To_Record_Job_Status()
        {
            long ukprn             = 2123;
            var  collectionYear    = 1920;
            var  collectionPeriod  = 10;
            var  jobContextMessage = new JobContextMessage
            {
                JobId        = 1,
                TopicPointer = 0,
                Topics       = new List <ITopicItem>
                {
                    new TopicItem
                    {
                        SubscriptionName = "GenerateFM36Payments",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string>
                                {
                                    JobContextMessageConstants.Tasks.JobFailure
                                }
                            }
                        }
                    },
                    new TopicItem
                    {
                        SubscriptionName = "Other Task",
                        Tasks            = new List <ITaskItem>
                        {
                            new TaskItem
                            {
                                SupportsParallelExecution = false,
                                Tasks = new List <string> {
                                    "Something else"
                                }
                            }
                        }
                    }
                },
                KeyValuePairs = new Dictionary <string, object> {
                    { JobContextMessageConstants.KeyValuePairs.ReturnPeriod, collectionPeriod },
                    { JobContextMessageConstants.KeyValuePairs.CollectionYear, collectionYear },
                    { JobContextMessageConstants.KeyValuePairs.Ukprn, ukprn },
                    { JobContextMessageConstants.KeyValuePairs.FundingFm36Output, "invalid path" },
                    { JobContextMessageConstants.KeyValuePairs.FundingFm36OutputPeriodEnd, "valid path" },
                    { JobContextMessageConstants.KeyValuePairs.Container, "container" },
                    { JobContextMessageConstants.KeyValuePairs.Filename, "filename" },
                }
            };

            var handler = mocker.Create <JobContextMessageHandler>();
            await handler.HandleAsync(jobContextMessage, CancellationToken.None);

            mocker.Mock <IEarningsJobClient>()
            .Verify(x => x.RecordJobFailure(It.Is <long>(jobId => jobId == jobContextMessage.JobId),
                                            It.Is <long>(provider => provider == ukprn),
                                            It.Is <DateTime>(submissionTime => submissionTime == jobContextMessage.SubmissionDateTimeUtc),
                                            It.Is <short>(year => year == collectionYear),
                                            It.Is <byte>(period => period == collectionPeriod)), Times.Once);
        }
 public FundingServiceContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
Пример #23
0
 public DesktopReferenceDataJobContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
Пример #24
0
 public FileValidationJobContextMessageContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
 public EasJobContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
 public IlrMessageJobContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
        public async Task TestEntryPointZipGeneration()
        {
            string csv = $"A,B,C,D{Environment.NewLine}1,2,3,4";

            byte[] zipBytes = null;

            ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks();

            Mock <ILogger> logger = new Mock <ILogger>();
            Mock <IStreamableKeyValuePersistenceService> streamableKeyValuePersistenceService =
                new Mock <IStreamableKeyValuePersistenceService>();

            streamableKeyValuePersistenceService.Setup(x =>
                                                       x.SaveAsync(It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <CancellationToken>()))
            .Callback <string, Stream, CancellationToken>((s, m, c) =>
            {
                zipBytes = new byte[m.Length];
                m.Seek(0, SeekOrigin.Begin);
                m.Read(zipBytes, 0, (int)m.Length);
            })
            .Returns(Task.CompletedTask);
            Mock <IReport> report = new Mock <IReport>();

            report.SetupGet(x => x.ReportTaskName).Returns(topicsAndTasks.TopicReports_TaskGenerateAllbOccupancyReport);
            report.Setup(x =>
                         x.GenerateReport(It.IsAny <IReportServiceContext>(), It.IsAny <ZipArchive>(), It.IsAny <bool>(), It.IsAny <CancellationToken>()))
            .Callback <IReportServiceContext, ZipArchive, bool, CancellationToken>((j, z, b, c) =>
            {
                ZipArchiveEntry archivedFile = z.CreateEntry("ExampleReport.csv", CompressionLevel.Optimal);
                using (var sw = new StreamWriter(archivedFile.Open()))
                {
                    sw.Write(csv);
                }
            })
            .Returns(Task.CompletedTask);
            report.Setup(x => x.IsMatch(It.IsAny <string>())).Returns(true);

            JobContextMessage jobContextMessage =
                new JobContextMessage(
                    1,
                    new ITopicItem[] { new TopicItem("SubscriptionName", new List <ITaskItem> {
                    new TaskItem(new List <string> {
                        topicsAndTasks.TopicReports_TaskGenerateAllbOccupancyReport
                    }, false)
                }) },
                    0,
                    DateTime.UtcNow);

            jobContextMessage.KeyValuePairs.Add(JobContextMessageKey.UkPrn, 1234);

            EntryPoint entryPoint = new EntryPoint(
                logger.Object,
                streamableKeyValuePersistenceService.Object,
                new[] { report.Object });

            await entryPoint.Callback(new ReportServiceJobContextMessageContext(jobContextMessage), CancellationToken.None);

            string zipContents;

            using (MemoryStream ms = new MemoryStream(zipBytes))
            {
                using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Read))
                {
                    ZipArchiveEntry entry = archive.GetEntry("ExampleReport.csv");
                    entry.Should().NotBeNull();
                    using (StreamReader reader = new StreamReader(entry.Open()))
                    {
                        zipContents = reader.ReadToEnd();
                    }
                }
            }

            zipContents.Should().NotBeNullOrEmpty();
            zipContents.Should().Be(csv);
        }
 public MessageParameters(JobType jobType)
 {
     JobType           = jobType;
     JobContextMessage = new JobContextMessage();
 }
 public OperationsReportServiceContext(JobContextMessage jobContextMessage)
 {
     _jobContextMessage = jobContextMessage;
 }
Пример #30
0
        public async Task <bool> Handle(JobContextMessage jobContextMessage, CancellationToken cancellationToken)
        {
            using (var childLifeTimeScope = _parentLifeTimeScope
                                            .BeginLifetimeScope(c =>
            {
                var fileName = jobContextMessage.KeyValuePairs[JobContextMessageKey.Filename].ToString();
                if (fileName.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
                {
                    c.RegisterType <AzureStorageCompressedFileContentStringProviderService>()
                    .As <IMessageStreamProviderService>();
                }
                else
                {
                    c.RegisterType <AzureStorageFileContentStringProviderService>()
                    .As <IMessageStreamProviderService>();
                }

                c.RegisterInstance(
                    new PreValidationContext
                {
                    JobId = jobContextMessage.JobId.ToString(),
                    Input = fileName,
                    InvalidLearnRefNumbersKey = jobContextMessage
                                                .KeyValuePairs[JobContextMessageKey.InvalidLearnRefNumbers].ToString(),
                    ValidLearnRefNumbersKey =
                        jobContextMessage.KeyValuePairs[JobContextMessageKey.ValidLearnRefNumbers].ToString(),
                    ValidationErrorsKey = jobContextMessage.KeyValuePairs[JobContextMessageKey.ValidationErrors]
                                          .ToString(),
                    ValidationErrorMessageLookupKey = jobContextMessage
                                                      .KeyValuePairs[JobContextMessageKey.ValidationErrorLookups].ToString()
                }).As <IPreValidationContext>();
            }))
            {
                var executionContext = (ExecutionContext)childLifeTimeScope.Resolve <IExecutionContext>();
                executionContext.JobId = jobContextMessage.JobId.ToString();
                var logger = childLifeTimeScope.Resolve <ILogger>();

                try
                {
                    var azureStorageModel = childLifeTimeScope.Resolve <AzureStorageModel>();
                    azureStorageModel.AzureContainerReference =
                        jobContextMessage.KeyValuePairs[JobContextMessageKey.Container].ToString();

                    logger.LogDebug("inside process message validate");

                    var preValidationOrchestrationService = childLifeTimeScope
                                                            .Resolve <IPreValidationOrchestrationService <IValidationError> >();

                    var validationContext = childLifeTimeScope.Resolve <IPreValidationContext>();

                    await preValidationOrchestrationService.ExecuteAsync(validationContext, cancellationToken);

                    // Update the file name, as it could have been a zip which we have extracted now so needs updating in the message
                    jobContextMessage.KeyValuePairs[JobContextMessageKey.Filename] = validationContext.Input;

                    // populate the keys into jobcontextmessage
                    jobContextMessage.KeyValuePairs[JobContextMessageKey.InvalidLearnRefNumbersCount] =
                        validationContext.InvalidLearnRefNumbersCount;
                    jobContextMessage.KeyValuePairs[JobContextMessageKey.ValidLearnRefNumbersCount] =
                        validationContext.ValidLearnRefNumbersCount;
                    jobContextMessage.KeyValuePairs[JobContextMessageKey.ValidationTotalErrorCount] =
                        validationContext.ValidationTotalErrorCount;
                    jobContextMessage.KeyValuePairs[JobContextMessageKey.ValidationTotalWarningCount] =
                        validationContext.ValidationTotalWarningCount;

                    logger.LogDebug("Validation complete");
                    ServiceEventSource.Current.ServiceMessage(_context, "Validation complete");
                    return(true);
                }
                catch (Exception ex)
                {
                    ServiceEventSource.Current.ServiceMessage(_context, "Exception-{0}", ex.ToString());
                    logger.LogError("Error while processing job", ex);
                    throw;
                }
            }
        }