public async Task GetTopicTasks_Task_NotEnabled_Success(JobType jobType)
        {
            IContainer        container = Registrations();
            List <ITopicItem> result;

            using (var scope = container.BeginLifetimeScope())
            {
                // Create the schema in the database
                var options = scope.Resolve <DbContextOptions <JobQueueDataContext> >();
                using (var context = new JobQueueDataContext(options))
                {
                    context.Database.EnsureCreated();
                    context.JobTopicSubscription.Add(GetJobTopic(1, jobType, "TopicA", "Validation", "GenerateReport"));
                    context.JobTopicSubscription.Add(GetJobTopic(2, jobType, "TopicA", "Funding", "NotEnabledTask", false, true, false));
                    context.SaveChanges();

                    var jobTopicTaskService = scope.Resolve <IJobTopicTaskService>();
                    result = (await jobTopicTaskService.GetTopicItems(jobType, false)).ToList();
                }

                result.Should().NotBeNull();
                result.Count.Should().Be(2);
                result.Single(x => x.SubscriptionName == "Validation").Tasks.Count.Should().Be(1);
                result.Single(x => x.SubscriptionName == "Funding").Tasks.Any(x => x.Tasks.Contains("NotEnabledTask")).Should().BeFalse();
            }
        }
        public async Task IsCrossLoadingEnabled_Success()
        {
            IContainer container = Registrations();

            using (var scope = container.BeginLifetimeScope())
            {
                // Create the schema in the database
                var options = scope.Resolve <DbContextOptions <JobQueueDataContext> >();
                using (var context = new JobQueueDataContext(options))
                {
                    context.Database.EnsureCreated();
                    context.JobTypeGroup.Add(new JobTypeGroup
                    {
                        JobTypeGroupId           = 1,
                        Description              = "Collection Submission",
                        ConcurrentExecutionCount = 25
                    });
                    context.JobType.Add(new Data.Entities.JobType
                    {
                        IsCrossLoadingEnabled = true,
                        Title          = "Title",
                        Description    = "Description",
                        JobTypeId      = 1,
                        JobTypeGroupId = 1
                    });
                    context.SaveChanges();
                }

                var manager = scope.Resolve <IJobManager>();
                (await manager.IsCrossLoadingEnabled(JobType.IlrSubmission)).Should().BeTrue();
            }
        }
        public async Task GetTopicTasks_OneTaskTopic_Success()
        {
            IContainer        container = Registrations();
            List <ITopicItem> result;

            using (var scope = container.BeginLifetimeScope())
            {
                // Create the schema in the database
                var options = scope.Resolve <DbContextOptions <JobQueueDataContext> >();
                using (var context = new JobQueueDataContext(options))
                {
                    context.Database.EnsureCreated();
                    context.JobTopicSubscription.Add(GetJobTopic(1, JobType.IlrSubmission, "TopicA", "Validation", "GenerateReport"));
                    context.SaveChanges();
                }

                var jobTopicTaskService = scope.Resolve <IJobTopicTaskService>();
                result = (await jobTopicTaskService.GetTopicItems(JobType.IlrSubmission, false)).ToList();
            }

            result.Should().NotBeNull();
            result.Count.Should().Be(1);

            var topicItem = result.First();

            topicItem.SubscriptionSqlFilterValue.Should().Be("TopicA");
            topicItem.SubscriptionName.Should().Be("Validation");
            topicItem.Tasks.Count.Should().Be(1);
            topicItem.Tasks.Any(x => x.Tasks.Contains("GenerateReport")).Should().BeTrue();
        }
        private void SetupData(DbContextOptions dbContextOptions)
        {
            using (var cmContext = new JobQueueDataContext(dbContextOptions))
            {
                var collection = new CollectionEntity()
                {
                    CollectionId     = 1,
                    CollectionTypeId = 1,
                    IsOpen           = true,
                    Name             = "ILR1718"
                };
                cmContext.Collections.Add(collection);

                cmContext.ReturnPeriods.Add(new ReturnPeriodEntity()
                {
                    CalendarMonth    = 8,
                    CalendarYear     = 2018,
                    ReturnPeriodId   = 2,
                    PeriodNumber     = 1,
                    StartDateTimeUtc = new System.DateTime(2018, 08, 22),
                    EndDateTimeUtc   = new System.DateTime(2018, 09, 04),
                    CollectionEntity = collection,
                    CollectionId     = 1,
                });

                cmContext.ReturnPeriods.Add(new ReturnPeriodEntity()
                {
                    CalendarMonth    = 7,
                    CalendarYear     = 2018,
                    ReturnPeriodId   = 1,
                    PeriodNumber     = 12,
                    StartDateTimeUtc = System.DateTime.UtcNow.AddSeconds(-60),
                    EndDateTimeUtc   = System.DateTime.UtcNow.AddSeconds(60),
                    CollectionEntity = collection,
                    CollectionId     = 1
                });

                cmContext.ReturnPeriods.Add(new ReturnPeriodEntity()
                {
                    CalendarMonth    = 9,
                    CalendarYear     = 2018,
                    ReturnPeriodId   = 3,
                    PeriodNumber     = 3,
                    StartDateTimeUtc = System.DateTime.UtcNow.AddDays(1),
                    EndDateTimeUtc   = System.DateTime.UtcNow.AddDays(10),
                    CollectionEntity = collection,
                    CollectionId     = 1
                });

                cmContext.SaveChanges();
            }
        }
        public async Task UpdateCrossLoadingStatus_Success_EmailSent()
        {
            var emailTemplateManager = new Mock <IEmailTemplateManager>();

            emailTemplateManager.Setup(x => x.GetTemplate(It.IsAny <long>(), It.IsAny <JobStatusType>(), It.IsAny <JobType>(), It.IsAny <DateTime>())).Returns(Task.FromResult("template"));
            var emailNotifier = new Mock <IEmailNotifier>();

            emailNotifier.Setup(x => x.SendEmail(It.IsAny <string>(), "test", It.IsAny <Dictionary <string, dynamic> >()));

            IContainer container = Registrations(emailTemplateManager.Object, emailNotifier.Object);

            using (var scope = container.BeginLifetimeScope())
            {
                // Create the schema in the database
                var options = scope.Resolve <DbContextOptions <JobQueueDataContext> >();
                using (var context = new JobQueueDataContext(options))
                {
                    context.Database.EnsureCreated();
                    context.JobTypeGroup.Add(new JobTypeGroup
                    {
                        JobTypeGroupId           = 1,
                        Description              = "Collection Submission",
                        ConcurrentExecutionCount = 25
                    });
                    context.JobType.Add(new Data.Entities.JobType
                    {
                        IsCrossLoadingEnabled = true,
                        Title          = "Title",
                        Description    = "Description",
                        JobTypeId      = 1,
                        JobTypeGroupId = 1
                    });
                    context.SaveChanges();
                }

                var manager = scope.Resolve <IJobManager>();
                await manager.AddJob(new Job
                {
                    Status             = JobStatusType.Ready,
                    JobType            = JobType.IlrSubmission,
                    CrossLoadingStatus = JobStatusType.MovedForProcessing
                });

                await manager.UpdateCrossLoadingStatus(1, JobStatusType.Completed);

                var updatedJob = await manager.GetJobById(1);

                updatedJob.CrossLoadingStatus.Should().Be(JobStatusType.Completed);
                emailNotifier.Verify(x => x.SendEmail(It.IsAny <string>(), "template", It.IsAny <Dictionary <string, dynamic> >()), Times.Never);
            }
        }
        public void GetTemplate_Success(bool isClose)
        {
            var returnCalendarMock = new Mock <IReturnCalendarService>();

            returnCalendarMock.Setup(x => x.GetPeriodAsync("ILR1819", It.IsAny <DateTime>())).ReturnsAsync(() => isClose ? null : new ReturnPeriod());

            IContainer container = Registrations(returnCalendarMock.Object);

            using (var scope = container.BeginLifetimeScope())
            {
                var templateManager = scope.Resolve <IEmailTemplateManager>();
                var options         = scope.Resolve <DbContextOptions <JobQueueDataContext> >();

                // Create the schema in the database
                using (var context = new JobQueueDataContext(options))
                {
                    context.Database.EnsureCreated();
                    context.JobEmailTemplate.Add(new JobEmailTemplate()
                    {
                        JobType             = (short)JobType.IlrSubmission,
                        JobStatus           = (short)JobStatusType.Completed,
                        Active              = true,
                        TemplateOpenPeriod  = "template_open",
                        TemplateClosePeriod = "template_close"
                    });
                    context.FileUploadJobMetaData.Add(new FileUploadJobMetaData()
                    {
                        Job = new Job()
                        {
                            JobId   = 1,
                            JobType = (short)JobType.IlrSubmission
                        },
                        CollectionName   = "ILR1819",
                        PeriodNumber     = 1,
                        FileName         = "test",
                        FileSize         = 100,
                        IsFirstStage     = false,
                        StorageReference = "test"
                    });
                    context.SaveChanges();
                }

                var template =
                    templateManager.GetTemplate(1, JobStatusType.Completed, JobType.IlrSubmission, DateTime.Now).Result;
                template.Should().NotBeNull();
                template.Should().Be(isClose ? "template_close" : "template_open");
            }
        }
Exemple #7
0
        private void SetupData(DbContextOptions dbContextOptions)
        {
            using (var cmContext = new JobQueueDataContext(dbContextOptions))
            {
                cmContext.Organisations.Add(new OrganisationEntity()
                {
                    Ukprn          = 1000,
                    OrgId          = "test_org1",
                    OrganisationId = 1
                });

                cmContext.Collections.Add(new CollectionEntity()
                {
                    CollectionId     = 1,
                    CollectionTypeId = 1,
                    IsOpen           = true,
                    Name             = "test coll"
                });

                cmContext.Collections.Add(new CollectionEntity()
                {
                    CollectionId     = 2,
                    CollectionTypeId = 1,
                    IsOpen           = true,
                    Name             = "test coll2"
                });

                cmContext.CollectionTypes.Add(new CollectionTypeEntity()
                {
                    CollectionTypeId = 1,
                    Description      = "ILR collection",
                    Type             = "ILR"
                });

                cmContext.OrganisationCollections.Add(new OrganisationCollectionEntity()
                {
                    CollectionId   = 1,
                    OrganisationId = 1
                });

                cmContext.SaveChanges();
            }
        }