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 <bool> IsCrossLoadingEnabled(JobType jobType)
        {
            using (var context = _contextFactory())
            {
                var entity = await context.JobType.SingleOrDefaultAsync(x => x.JobTypeId == (short)jobType);

                return(entity != null && entity.IsCrossLoadingEnabled);
            }
        }
        public async Task <IEnumerable <ITopicItem> > GetTopicItems(JobType jobType, bool isFirstStage = true, CancellationToken cancellationToken = default(CancellationToken))
        {
            List <JobTopicSubscription> topicsData;

            using (var context = _contextFactory())
            {
                topicsData = await context.JobTopicSubscription.Where(x =>
                                                                      x.JobTypeId == (short)jobType &&
                                                                      (!x.IsFirstStage.HasValue || x.IsFirstStage == isFirstStage) &&
                                                                      x.Enabled == true)
                             .OrderBy(x => x.TopicOrder)
                             .Include(x => x.JobSubscriptionTask)
                             .ToListAsync(cancellationToken);
            }

            TaskItem emptyTaskItem = new TaskItem()
            {
                Tasks = new List <string>()
                {
                    string.Empty
                },
                SupportsParallelExecution = false
            };

            List <TopicItem> topics = new List <TopicItem>();

            if (!topicsData.Any())
            {
                return(topics);
            }

            foreach (JobTopicSubscription topicEntity in topicsData)
            {
                List <string> tasks             = new List <string>();
                var           topicTaskEntities = topicEntity.JobSubscriptionTask.Where(x => x.Enabled == true)
                                                  .OrderBy(x => x.TaskOrder).ToList();

                if (topicTaskEntities.Any())
                {
                    tasks.AddRange(topicTaskEntities.Select(x => x.TaskName));
                }

                var taskItem = new List <ITaskItem>()
                {
                    tasks.Any() ? new TaskItem(tasks, false) : emptyTaskItem
                };

                topics.Add(new TopicItem(topicEntity.SubscriptionName, topicEntity.TopicName, taskItem));
            }

            return(topics);
        }
        public async Task AddJob_Success_Values(JobType jobType)
        {
            var job = new Job
            {
                DateTimeSubmittedUtc = DateTime.UtcNow,
                DateTimeUpdatedUtc   = DateTime.UtcNow,
                JobId       = 0,
                Priority    = 1,
                RowVersion  = null,
                Status      = JobStatusType.Ready,
                SubmittedBy = "test user",
                JobType     = jobType,
                NotifyEmail = "*****@*****.**"
            };

            IContainer container = Registrations();
            Job        savedJob;

            using (var scope = container.BeginLifetimeScope())
            {
                IJobManager manager = scope.Resolve <IJobManager>();
                await manager.AddJob(job);

                var result = await manager.GetAllJobs();

                savedJob = result.SingleOrDefault();
            }

            savedJob.Should().NotBeNull();

            savedJob.JobId.Should().Be(1);
            savedJob.DateTimeSubmittedUtc.Should().BeOnOrBefore(DateTime.UtcNow);
            savedJob.DateTimeUpdatedUtc.Should().BeNull();
            savedJob.JobType.Should().Be(jobType);
            savedJob.Priority.Should().Be(1);
            savedJob.SubmittedBy.Should().Be("test user");
            savedJob.Status.Should().Be(JobStatusType.Ready);
            savedJob.NotifyEmail.Should().Be("*****@*****.**");
            savedJob.CrossLoadingStatus.Should().Be(null);
        }
 private JobTopicSubscription GetJobTopic(int id, JobType jobType, string topicName, string subscriptionName, string taskName, bool isFirstStage = false, bool topicEnabled = true, bool taskEnabled = true)
 {
     return(new JobTopicSubscription
     {
         JobTopicId = id,
         IsFirstStage = isFirstStage,
         Enabled = topicEnabled,
         JobTypeId = (short)jobType,
         TopicName = topicName,
         SubscriptionName = subscriptionName,
         TopicOrder = 1,
         JobSubscriptionTask = new List <JobSubscriptionTask>()
         {
             new JobSubscriptionTask
             {
                 JobTopicTaskId = id,
                 Enabled = taskEnabled,
                 JobTopicId = 1,
                 TaskName = taskName
             }
         }
     });
 }
 public async Task <string> GetTemplate(long jobId, JobStatusType status, JobType jobType, DateTime dateTimeJobSubmittedUtc)
 {
     return(await _emailTemplateManager.GetTemplate(jobId, status, jobType, dateTimeJobSubmittedUtc));
 }