public WorkerFacts() { _context = new BackgroundProcessContextMock(); _queues = new[] {"critical"}; _performer = new Mock<IBackgroundJobPerformer>(); _connection = new Mock<IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _fetchedJob = new Mock<IFetchedJob>(); _fetchedJob.Setup(x => x.JobId).Returns(JobId); _connection .Setup(x => x.FetchNextJob(_queues, It.IsNotNull<CancellationToken>())) .Returns(_fetchedJob.Object); _connection.Setup(x => x.GetJobData(JobId)) .Returns(new JobData { Job = Job.FromExpression(() => Method()), }); _stateChanger = new Mock<IBackgroundJobStateChanger>(); _stateChanger.Setup(x => x.ChangeState(It.IsAny<StateChangeContext>())) .Returns<StateChangeContext>(ctx => ctx.NewState); }
public RecurringJobSchedulerFacts() { _context = new BackgroundProcessContextMock(); _throttler = new Mock<IThrottler>(); // Setting up the successful path _instant = new Mock<IScheduleInstant>(); _instant.Setup(x => x.GetNextInstants(It.IsAny<DateTime?>())).Returns(new[] { _instant.Object.NowInstant }); var timeZone1 = TimeZoneInfo.Local; _instantFactory = (schedule, timeZone) => _instant.Object; _recurringJob = new Dictionary<string, string> { { "Cron", "* * * * *" }, { "Job", JobHelper.ToJson(InvocationData.Serialize(Job.FromExpression(() => Console.WriteLine()))) }, { "TimeZoneId", timeZone1.Id } }; _connection = new Mock<IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _connection.Setup(x => x.GetAllItemsFromSet("recurring-jobs")) .Returns(new HashSet<string> { RecurringJobId }); _connection.Setup(x => x.GetAllEntriesFromHash(String.Format("recurring-job:{0}", RecurringJobId))) .Returns(_recurringJob); _backgroundJobMock = new BackgroundJobMock(); _factory = new Mock<IBackgroundJobFactory>(); _factory.Setup(x => x.Create(It.IsAny<CreateContext>())).Returns(_backgroundJobMock.Object); }
public ServerHeartbeatFacts() { _context = new BackgroundProcessContextMock(); _connection = new Mock<IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); }
public AutomaticRetryProcessFacts() { _process = new Mock<IBackgroundProcess>(); _delay = TimeSpan.Zero; _maxRetryAttempts = 3; _context = new BackgroundProcessContextMock(); }
public ServerWatchdogFacts() { _checkInterval = Timeout.InfiniteTimeSpan; _serverTimeout = TimeSpan.FromSeconds(5); _context = new BackgroundProcessContextMock(); _context.CancellationTokenSource.Cancel(); _connection = new Mock<IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); }
public RecurringDateTimeJobSchedulerFacts() { _context = new BackgroundProcessContextMock(); _throttler = new Mock <IThrottler>(); // Setting up the successful path _instant = new Mock <IScheduleInstant>(); _instant.Setup(x => x.GetNextInstants(It.IsAny <DateTime>(), null)).Returns(new[] { _instant.Object.NowInstant }); _instant.Setup(x => x.GetNextInstants(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns(new[] { _instant.Object.NowInstant }); _instant.Setup(x => x.NowInstant).Returns(DateTime.UtcNow); _instant.Setup(x => x.NextInstant).Returns(_instant.Object.NowInstant); var timeZone1 = TimeZoneInfo.Local; _instantFactory = (schedule, timeZone) => _instant.Object; _recurringJob = new Dictionary <string, string> { { "Cron", "* * * * *" }, { "Job", JobHelper.ToJson(InvocationData.Serialize(Job.FromExpression(() => Console.WriteLine()))) }, { "TimeZoneId", timeZone1.Id }, { "StartDate", null }, { "EndDate", null } }; _connection = new Mock <IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _connection.Setup(x => x.GetAllItemsFromSet(PluginConstants.JobSet)) .Returns(new HashSet <string> { RecurringJobId }); _connection.Setup(x => x.GetAllEntriesFromHash($"{PluginConstants.JobType}:{RecurringJobId}")) .Returns(_recurringJob); _backgroundJobMock = new BackgroundJobMock(); _factory = new Mock <IBackgroundJobFactory>(); _factory.Setup(x => x.Create(It.IsAny <CreateContext>())).Returns(_backgroundJobMock.Object); }
public DelayedJobSchedulerFacts() { _context = new BackgroundProcessContextMock(); _context.CancellationTokenSource.Cancel(); _connection = new Mock <IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _stateChanger = new Mock <IBackgroundJobStateChanger>(); _transaction = new Mock <IWriteOnlyTransaction>(); _connection.Setup(x => x.CreateWriteTransaction()).Returns(_transaction.Object); _distributedLock = new Mock <IDisposable>(); _connection .Setup(x => x.AcquireDistributedLock("locks:schedulepoller", It.IsAny <TimeSpan>())) .Returns(_distributedLock.Object); _connection.Setup(x => x.GetFirstByLowestScoreFromSet( "schedule", 0, It.Is <double>(time => time > 0))).Returns(JobId); }
public DelayedJobSchedulerFacts() { _context = new BackgroundProcessContextMock(); _context.CancellationTokenSource.Cancel(); _connection = new Mock<IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _stateChanger = new Mock<IBackgroundJobStateChanger>(); _transaction = new Mock<IWriteOnlyTransaction>(); _connection.Setup(x => x.CreateWriteTransaction()).Returns(_transaction.Object); _distributedLock = new Mock<IDisposable>(); _connection .Setup(x => x.AcquireDistributedLock("locks:schedulepoller", It.IsAny<TimeSpan>())) .Returns(_distributedLock.Object); _connection.Setup(x => x.GetFirstByLowestScoreFromSet( "schedule", 0, It.Is<double>(time => time > 0))).Returns(JobId); }
public DelayedJobSchedulerFacts() { _context = new BackgroundProcessContextMock(); _connection = new Mock <JobStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _stateChanger = new Mock <IBackgroundJobStateChanger>(); _transaction = new Mock <IWriteOnlyTransaction>(); _connection.Setup(x => x.CreateWriteTransaction()).Returns(_transaction.Object); _distributedLock = new Mock <IDisposable>(); _connection .Setup(x => x.AcquireDistributedLock("locks:schedulepoller", It.IsAny <TimeSpan>())) .Returns(_distributedLock.Object); _connection .Setup(x => x.GetFirstByLowestScoreFromSet("schedule", 0, It.Is <double>(time => time > 0))) .Returns(_schedule.FirstOrDefault); _connection .Setup(x => x.GetFirstByLowestScoreFromSet("schedule", 0, It.Is <double>(time => time > 0), It.IsAny <int>())) .Returns(_schedule.ToList); _stateChanger .Setup(x => x.ChangeState(It.IsNotNull <StateChangeContext>())) .Callback <StateChangeContext>(ctx => { if (!(ctx.NewState is ScheduledState)) { _schedule.Remove(ctx.BackgroundJobId); } }); _transaction .Setup(x => x.RemoveFromSet("schedule", It.IsNotNull <string>())) .Callback <string, string>((key, value) => _schedule.Remove(value)); }
public DelayedJobSchedulerFacts() { _context = new BackgroundProcessContextMock(); _context.CancellationTokenSource.Cancel(); _connection = new Mock <IStorageConnection>(); _context.Storage.Setup(x => x.GetConnection()).Returns(_connection.Object); _stateChanger = new Mock <IBackgroundJobStateChanger>(); _transaction = new Mock <IWriteOnlyTransaction>(); _connection.Setup(x => x.CreateWriteTransaction()).Returns(_transaction.Object); _distributedLock = new Mock <IDisposable>(); _jobSet = new Dictionary <string, double>() { { JobId, 1 } }; _connection.Setup(x => x.GetAllValuesWithScoresFromSetQueueWithinScoreRange( "schedule", "default", 0, It.Is <double>(time => time > 0))).Returns(_jobSet); _queues = new[] { EnqueuedState.DefaultQueue }; }
public BackgroundProcessExtensionsFacts() { _context = new BackgroundProcessContextMock(); }
public InfiniteLoopComponentFacts() { _innerComponent = new Mock <IServerComponent>(); _innerProcess = new Mock <IBackgroundProcess>(); _context = new BackgroundProcessContextMock(); }
public InfiniteLoopComponentFacts() { _innerComponent = new Mock<IServerComponent>(); _innerProcess = new Mock<IBackgroundProcess>(); _context = new BackgroundProcessContextMock(); }