public async Task <bool> UpdateCrossLoadingStatus(long jobId, JobStatusType status)
        {
            if (jobId == 0)
            {
                throw new ArgumentException("Job id can not be 0");
            }

            using (IJobQueueDataContext context = _contextFactory())
            {
                var entity = await context.Job.SingleOrDefaultAsync(x => x.JobId == jobId);

                if (entity == null)
                {
                    throw new ArgumentException($"Job id {jobId} does not exist");
                }

                entity.CrossLoadingStatus   = (short)status;
                entity.DateTimeUpdatedUtc   = _dateTimeProvider.GetNowUtc();
                context.Entry(entity).State = EntityState.Modified;

                await context.SaveChangesAsync();

                return(true);
            }
        }
        public async Task RemoveJobFromQueue_Fail_InvalidJobStatus(JobStatusType status)
        {
            IContainer container = Registrations();

            using (var scope = container.BeginLifetimeScope())
            {
                var manager = scope.Resolve <IJobManager>();
                await manager.AddJob(new Job
                {
                    Status = status
                });

                await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => manager.RemoveJobFromQueue(1));
            }
        }
        public async Task <bool> UpdateJobStatus(long jobId, JobStatusType status)
        {
            if (jobId == 0)
            {
                throw new ArgumentException("Job id can not be 0");
            }

            using (IJobQueueDataContext context = _contextFactory())
            {
                var entity = await context.Job.SingleOrDefaultAsync(x => x.JobId == jobId);

                if (entity == null)
                {
                    throw new ArgumentException($"Job id {jobId} does not exist");
                }

                var statusChanged = entity.Status != (short)status;

                entity.Status               = (short)status;
                entity.DateTimeUpdatedUtc   = _dateTimeProvider.GetNowUtc();
                context.Entry(entity).State = EntityState.Modified;

                if (status == JobStatusType.Ready)
                {
                    context.JobSubmission.Add(new JobSubmission()
                    {
                        DateTimeUtc = _dateTimeProvider.GetNowUtc(),
                        JobId       = jobId
                    });
                }

                await context.SaveChangesAsync();

                if (statusChanged)
                {
                    await SendEmailNotification(jobId);
                }

                return(true);
            }
        }
        public async Task UpdateJobStatus_Ready(JobStatusType existingStatus)
        {
            IContainer container = Registrations();
            Job        updatedJob;

            using (var scope = container.BeginLifetimeScope())
            {
                var manager = scope.Resolve <IJobManager>();
                await manager.AddJob(new Job
                {
                    Status = existingStatus
                });

                await manager.UpdateJobStatus(1, JobStatusType.Ready);

                updatedJob = await manager.GetJobById(1);

                var context = scope.Resolve <IJobQueueDataContext>();
                updatedJob.Status.Should().Be(JobStatusType.Ready);
                context.JobSubmission.FirstOrDefault(x => x.JobId == 1).Should().NotBeNull();
            }
        }
 public async Task <string> GetTemplate(long jobId, JobStatusType status, JobType jobType, DateTime dateTimeJobSubmittedUtc)
 {
     return(await _emailTemplateManager.GetTemplate(jobId, status, jobType, dateTimeJobSubmittedUtc));
 }