public void CancelTask() { ITaskRuntimeInfo taskInfo = this.Repository.TaskRuntimeInfo.Create(); this.Repository.TaskRuntimeInfo.Add(taskInfo); ITask task = new FakeTask(); this.Repository.Tasks.Add(taskInfo.TaskId, task); using (FakeTaskWorker taskWorker = new FakeTaskWorker()) { this.TaskWorkerFactory.PredefineResult(taskWorker, f => f.CreateTaskWorker(task)); taskWorker.PredefineMethodCall(w => w.StartTask(task, null), () => Thread.Sleep(TimeSpan.FromSeconds(1))); ThreadPool.QueueUserWorkItem(_ => this.TaskWorkerBootstrap.StartTask(taskInfo.TaskId)); Thread.Sleep(TimeSpan.FromSeconds(0.5)); this.DateTimeProvider.UtcNow = DateTime.UtcNow; this.MessageBus.Tasks.NotifyTaskCancelRequest(taskInfo.TaskId, this.DateTimeProvider.UtcNow); Thread.Sleep(TimeSpan.FromSeconds(1.5)); taskWorker.AssertMethodCallOnce(w => w.CancelTask()); taskWorker.AssertMethodCallOnce(w => w.Dispose()); } this.MessageBus.Tasks.Receiver.AssertMethodCallOnce(mb => mb.UnsubscribeFromAllChannels()); }
public void StartTaskWithTaskJobSettings() { this.Configuration.Get <FakeTask>().HasTaskJobSettings = true; ITaskJobSettings settings = new FakeTaskJobSettings(); this.Repository.TaskJobSettings.Set <FakeTask>(settings); ITaskRuntimeInfo taskInfo = this.Repository.TaskRuntimeInfo.Create(); FakeTask task = new FakeTask(); this.Repository.Tasks.Add(taskInfo.TaskId, task); this.Repository.TaskRuntimeInfo.Add(taskInfo); using (FakeTaskWorker taskWorker = new FakeTaskWorker()) { this.TaskWorkerFactory.PredefineResult(taskWorker, f => f.CreateTaskWorker(task)); this.DateTimeProvider.UtcNow = DateTime.UtcNow; this.TaskWorkerBootstrap.StartTask(taskInfo.TaskId); this.TaskWorkerFactory.AssertMethodCallOnceWithArguments(f => f.CreateTaskWorker(task)); taskWorker.AssertMethodCallOnce(w => w.StartTask(task, settings)); } }
public void Fail() { ITaskRuntimeInfo taskInfo = this.Repository.TaskRuntimeInfo.Add(); ITask task = new FakeTask(); this.Repository.Tasks.Add(taskInfo.TaskId, task); this.DateTimeProvider.UtcNow = DateTime.UtcNow; Exception error = new TypeNotFoundInRedisException("Dummy Error"); using (FakeTaskWorker worker = new FakeTaskWorker()) { worker.PredefineMethodCall(w => w.StartTask(task, null), () => { throw error; }); this.TaskWorkerFactory.PredefineResult(worker, f => f.CreateTaskWorker(task)); try { this.TaskWorkerBootstrap.StartTask(taskInfo.TaskId); } catch (TypeNotFoundInRedisException) { } worker.AssertMethodCallOnce(w => w.Dispose()); } this.MessageBus.Tasks.Receiver.AssertMethodCallOnce(mb => mb.UnsubscribeFromAllChannels()); this.Repository.TaskRuntimeInfo.AssertMethodCallOnceWithArguments(r => r.Fail(taskInfo.TaskId, this.DateTimeProvider.UtcNow, error)); }
public void Complete() { ITaskRuntimeInfo taskInfo = this.Repository.TaskRuntimeInfo.Add(); ITask task = new FakeTask(); this.Repository.Tasks.Add(taskInfo.TaskId, task); this.DateTimeProvider.UtcNow = DateTime.UtcNow; using (FakeTaskWorker taskWorker = new FakeTaskWorker()) { taskWorker.PredefineMethodCall(w => w.StartTask(task, null), () => { }); this.TaskWorkerFactory.PredefineResult(taskWorker, f => f.CreateTaskWorker(task)); this.TaskWorkerBootstrap.StartTask(taskInfo.TaskId); taskWorker.AssertMethodCallOnce(w => w.Dispose()); } this.MessageBus.Tasks.Receiver.AssertMethodCallOnce(mb => mb.UnsubscribeFromAllChannels()); }
public void StartTaskNoTaskJobSettings() { ITaskRuntimeInfo taskInfo = this.Repository.TaskRuntimeInfo.Create(); FakeTask task = new FakeTask(); this.Repository.Tasks.Add(taskInfo.TaskId, task); this.Repository.TaskRuntimeInfo.Add(taskInfo); this.DateTimeProvider.UtcNow = DateTime.UtcNow; using (FakeTaskWorker taskWorker = new FakeTaskWorker()) { this.TaskWorkerFactory.PredefineResult(taskWorker, f => f.CreateTaskWorker(task)); this.TaskWorkerBootstrap.StartTask(taskInfo.TaskId); this.TaskWorkerFactory.AssertMethodCallOnceWithArguments(f => f.CreateTaskWorker(task)); taskWorker.AssertMethodCallOnce(w => w.StartTask(task, null)); } }