public void ExecuteWorkflows_OnDelayedAction_ResumesAfterDelay() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); DelayedWorkflow workflow = new DelayedWorkflow(DelayedWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = DelayedWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); IWorkflowServer workflowServer = new WorkflowServer(workflowStore); // execute workflowServer.ExecuteWorkflows(5); workflow = workflowStore.Get <DelayedWorkflow>(workflow.Id); Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState); // execute again - nothing should have changed workflowServer.ExecuteWorkflows(5); workflow = workflowStore.Get <DelayedWorkflow>(workflow.Id); Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState); // delay and run - should be now be complete Thread.Sleep(3100); workflowServer.ExecuteWorkflows(5); Assert.IsNull(workflowStore.GetOrDefault(workflow.Id)); Assert.IsNotNull(workflowStore.GetCompletedOrDefault(workflow.Id)); }
public void RegisterWorkflow_SingleInstanceWorkflowRegistered_ThrowsExceptionIfAlreadyExists() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); workflowStore.Save(new SingleInstanceWorkflow(SingleInstanceWorkflow.State.Start)); SingleInstanceWorkflow workflow = new SingleInstanceWorkflow(SingleInstanceWorkflow.State.Start); IWorkflowRegistrationService regService = new WorkflowRegistrationService(); regService.RegisterWorkflow(workflowStore, workflow); }
public void RegisterWorkflow_SingleInstanceWorkflowRegistered_ThrowsExceptionIfAlreadyExists() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); workflowStore.Save(new SingleInstanceWorkflow(SingleInstanceWorkflow.State.Start)); SingleInstanceWorkflow workflow = new SingleInstanceWorkflow(SingleInstanceWorkflow.State.Start); IWorkflowRegistrationService regService = new WorkflowRegistrationService(); TestDelegate del = () => regService.RegisterWorkflow(workflowStore, workflow); Assert.Throws <SingleInstanceWorkflowAlreadyExistsException>(del); }
public void IsSingleInstanceWorkflowRegistered_WorkflowRegisteredNotSingleInstance_ThrowsException() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.IsSingleInstance = false; workflowStore.Save(workflow); // execute IWorkflowRegistrationService regService = new WorkflowRegistrationService(); bool result = regService.IsSingleInstanceWorkflowRegistered<BasicWorkflow>(workflowStore); }
public void IsSingleInstanceWorkflowRegistered_WorkflowRegistered_ReturnsTrue() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.IsSingleInstance = true; workflowStore.Save(workflow); // execute IWorkflowRegistrationService regService = new WorkflowRegistrationService(); bool result = regService.IsSingleInstanceWorkflowRegistered<BasicWorkflow>(workflowStore); Assert.IsTrue(result); }
public void IsSingleInstanceWorkflowRegistered_WorkflowRegistered_ReturnsTrue() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.IsSingleInstance = true; workflowStore.Save(workflow); // execute IWorkflowRegistrationService regService = new WorkflowRegistrationService(); bool result = regService.IsSingleInstanceWorkflowRegistered <BasicWorkflow>(workflowStore); Assert.IsTrue(result); }
public void ExecuteWorkflow_OnExecution_InitialisesAndFiresTriggers() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowServer = new WorkflowServer(workflowStore); workflowServer.ExecuteWorkflow(workflow); Assert.AreEqual(BasicWorkflow.State.Complete.ToString(), workflow.CurrentState); }
public void ExecuteWorkflow_OnSuccessfulExecution_RetryCountIsZero() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowEngine = new WorkflowServer(workflowStore); workflowEngine.ExecuteWorkflow(workflow); Assert.AreEqual(0, workflow.RetryCount); }
public void IsSingleInstanceWorkflowRegistered_WorkflowRegisteredNotSingleInstance_ThrowsException() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.IsSingleInstance = false; workflowStore.Save(workflow); // execute IWorkflowRegistrationService regService = new WorkflowRegistrationService(); TestDelegate del = () => regService.IsSingleInstanceWorkflowRegistered <BasicWorkflow>(workflowStore); // assert Assert.Throws <WorkflowException>(del); }
public void ExecuteWorkflow_OnExecution_InitialisesAndFiresTriggers() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowServer = new WorkflowServer(workflowStore); workflowServer.ExecuteWorkflow(workflow); Assert.AreEqual(BasicWorkflow.State.Complete.ToString(), workflow.CurrentState); }
public void ExecuteWorkflow_OnStepCompletion_ExecutesNextStep() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow("Start"); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowEngine = new WorkflowServer(workflowStore); workflowEngine.ExecuteWorkflow(workflow); Assert.AreEqual("Complete", workflow.CurrentState); }
public void ExecuteWorkflow_OnCompletion_MovesWorkflowIntoCompletedArchive() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.DoingStuff); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.Complete.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowEngine = new WorkflowServer(workflowStore); workflowEngine.ExecuteWorkflow(workflow); Assert.IsNull(workflowStore.GetOrDefault(workflow.Id)); Assert.IsNotNull(workflowStore.GetCompleted(workflow.Id)); }
public void ExecuteWorkflow_OnSuccessfulExecution_RetryCountIsZero() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowEngine = new WorkflowServer(workflowStore); workflowEngine.ExecuteWorkflow(workflow); Assert.AreEqual(0, workflow.RetryCount); }
public void ExecuteWorkflow_OnCompletion_MovesWorkflowIntoCompletedArchive() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.DoingStuff); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.Complete.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowEngine = new WorkflowServer(workflowStore); workflowEngine.ExecuteWorkflow(workflow); Assert.IsNull(workflowStore.GetOrDefault(workflow.Id)); Assert.IsNotNull(workflowStore.GetCompleted(workflow.Id)); }
public void ExecuteWorkflow_OnCompletion_WorkflowOnCompleteCalled() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = Substitute.For <BasicWorkflow>(BasicWorkflow.State.DoingStuff); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.Complete.ToString(); workflowStore.Save(workflow); workflow.When(x => x.Fire("Complete")).Do(x => workflow.IsComplete = true); // execute IWorkflowServer workflowServer = new WorkflowServer(workflowStore); workflowServer.ExecuteWorkflow(workflow); workflow.Received(1).OnComplete(); }
public void ExecuteWorkflows_ActionWithNoDefaultConstructorAndNoDependencyResolver_ThrowsException() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); IWorkflowServer workflowServer = new WorkflowServer(workflowStore); DependencyInjectionWorkflow workflow = new DependencyInjectionWorkflow(DependencyInjectionWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = DependencyInjectionWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); Assert.AreEqual(0, workflow.RetryCount); // execute workflowServer.ExecuteWorkflows(10); // we won't get an error, but check the workflow to see if any error occurred Assert.AreEqual(1, workflow.RetryCount); Assert.IsTrue(workflow.LastException.Contains("MissingMethodException")); }
public void ExecuteWorkflows_OnExecution_ReturnsNumberOfWorkflowsExecuted(int activeWorkflowCount) { const int executeCount = 10; int expectedResult = Math.Min(executeCount, activeWorkflowCount); // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); for (int i = 0; i < activeWorkflowCount; i++) { BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); } IWorkflowServer workflowServer = new WorkflowServer(workflowStore); // execute int result = workflowServer.ExecuteWorkflows(10); Assert.AreEqual(expectedResult, result); }
public void ExecuteWorkflows_ActionWithNoDefaultConstructorAndDependencyResolver_ExecutesAction() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); IWorkflowServer workflowServer = new WorkflowServer(workflowStore); DependencyInjectionWorkflow workflow = new DependencyInjectionWorkflow(DependencyInjectionWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = DependencyInjectionWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); MyDependencyResolver resolver = new MyDependencyResolver();// Substitute.For<IWorkflowEngineDependencyResolver>(); //resolver.GetInstance<NoDefaultConstructorAction>().Returns(new NoDefaultConstructorAction("test", 1)); workflowServer.DependencyResolver = resolver; // execute Assert.AreEqual(0, resolver.RunCount); workflowServer.ExecuteWorkflows(10); Assert.AreEqual(1, resolver.RunCount); }
public void ExecuteWorkflow_OnCompletion_WorkflowCompletedEventRaised() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); bool eventRaised = false; BasicWorkflow workflow = new BasicWorkflow(BasicWorkflow.State.DoingStuff); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.Complete.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowServer = new WorkflowServer(workflowStore); workflowServer.WorkflowCompleted += delegate(object sender, WorkflowEventArgs e) { eventRaised = true; }; workflowServer.ExecuteWorkflow(workflow); Assert.IsTrue(eventRaised); }
public void ExecuteWorkflows_OnDelayedAction_ResumesAfterDelay() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); DelayedWorkflow workflow = new DelayedWorkflow(DelayedWorkflow.State.Start); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = DelayedWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); IWorkflowServer workflowServer = new WorkflowServer(workflowStore); // execute workflowServer.ExecuteWorkflows(5); workflow = workflowStore.Get<DelayedWorkflow>(workflow.Id); Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState); // execute again - nothing should have changed workflowServer.ExecuteWorkflows(5); workflow = workflowStore.Get<DelayedWorkflow>(workflow.Id); Assert.AreEqual(DelayedWorkflow.State.DoingStuff.ToString(), workflow.CurrentState); // delay and run - should be now be complete Thread.Sleep(3100); workflowServer.ExecuteWorkflows(5); Assert.IsNull(workflowStore.GetOrDefault(workflow.Id)); Assert.IsNotNull(workflowStore.GetCompletedOrDefault(workflow.Id)); }
public void ExecuteWorkflow_OnStepCompletion_ExecutesNextStep() { // set up the store and the workflows IWorkflowStore workflowStore = new MemoryWorkflowStore(); BasicWorkflow workflow = new BasicWorkflow("Start"); workflow.CreatedOn = DateTime.UtcNow.AddMinutes(-2); workflow.ResumeTrigger = BasicWorkflow.Trigger.DoStuff.ToString(); workflowStore.Save(workflow); // execute IWorkflowServer workflowEngine = new WorkflowServer(workflowStore); workflowEngine.ExecuteWorkflow(workflow); Assert.AreEqual("Complete", workflow.CurrentState); }