public void ExecuteWorkflow_OnWorkflowSuspension_WorkflowSuspendedEventRaised() { string initialState = Guid.NewGuid().ToString(); bool eventRaised = false; Workflow workflow = Substitute.For <Workflow>(); workflow.ResumeTrigger = "Test"; workflow.RetryIntervals = new int[] { }; workflow.CurrentState.Returns(initialState); workflow.WhenForAnyArgs(x => x.Fire(Arg.Any <string>())).Do(x => { throw new Exception(); }); // make sure the workflow is suspended IWorkflowExceptionHandler workflowExceptionHandler = Substitute.For <IWorkflowExceptionHandler>(); workflowExceptionHandler.WhenForAnyArgs(x => x.HandleWorkflowException(Arg.Any <Workflow>(), Arg.Any <Exception>())).Do(x => { workflow.IsSuspended = true; }); // execute IWorkflowServer workflowServer = new WorkflowServer(Substitute.For <IWorkflowStore>(), Substitute.For <IWorkflowRegistrationService>(), workflowExceptionHandler); workflowServer.WorkflowSuspended += delegate(object sender, WorkflowEventArgs e) { eventRaised = true; }; workflowServer.ExecuteWorkflow(workflow); Assert.IsTrue(eventRaised); }
public void ExecuteWorkflow_NullWorkflow_RaisesException() { IWorkflowServer workflowServer = new WorkflowServer(Substitute.For <IWorkflowStore>()); TestDelegate del = () => workflowServer.ExecuteWorkflow(null); Assert.Throws <NullReferenceException>(del); }
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_OnStepExceptionAndMultipleInstanceWorkflow_CorrectMethodCalled() { Workflow workflow = Substitute.For <Workflow>(); workflow.ResumeTrigger = "Test"; workflow.IsSingleInstance = false; workflow.WhenForAnyArgs(x => x.Fire(Arg.Any <string>())).Do(x => { throw new Exception(); }); IWorkflowExceptionHandler exceptionHandler = Substitute.For <IWorkflowExceptionHandler>(); // execute IWorkflowServer workflowServer = new WorkflowServer(Substitute.For <IWorkflowStore>(), Substitute.For <IWorkflowRegistrationService>(), exceptionHandler); workflowServer.ExecuteWorkflow(workflow); exceptionHandler.Received(1).HandleWorkflowException(Arg.Any <Workflow>(), Arg.Any <Exception>()); }
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_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_OnStepException_StateReset() { string initialState = Guid.NewGuid().ToString(); Workflow workflow = Substitute.For <Workflow>(); workflow.ResumeTrigger = "Test"; workflow.CurrentState.Returns(initialState); workflow.WhenForAnyArgs(x => x.Fire(Arg.Any <string>())).Do(x => { throw new Exception(); }); // execute IWorkflowServer workflowServer = new WorkflowServer(Substitute.For <IWorkflowStore>(), Substitute.For <IWorkflowRegistrationService>(), Substitute.For <IWorkflowExceptionHandler>()); workflowServer.ExecuteWorkflow(workflow); // make sure the property was set workflow.Received(1).CurrentState = initialState; }
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_OnWorkflowError_OnErrorCalled() { string initialState = Guid.NewGuid().ToString(); Workflow workflow = Substitute.For <Workflow>(); workflow.ResumeTrigger = "Test"; workflow.RetryIntervals = new int[] { }; workflow.CurrentState.Returns(initialState); workflow.WhenForAnyArgs(x => x.Fire(Arg.Any <string>())).Do(x => { throw new Exception(); }); // execute IWorkflowServer workflowServer = new WorkflowServer(Substitute.For <IWorkflowStore>(), Substitute.For <IWorkflowRegistrationService>(), Substitute.For <IWorkflowExceptionHandler>()); workflowServer.ExecuteWorkflow(workflow); workflow.Received(1).OnError(Arg.Any <Exception>()); }
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_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 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 ExecuteWorkflow_OnStepExceptionAndSingleInstanceWorkflow_CorrectMethodCalled() { Workflow workflow = Substitute.For<Workflow>(); workflow.ResumeTrigger = "Test"; workflow.IsSingleInstance = true; workflow.WhenForAnyArgs(x => x.Fire(Arg.Any<string>())).Do(x => { throw new Exception(); }); IWorkflowExceptionHandler exceptionHandler = Substitute.For<IWorkflowExceptionHandler>(); // execute IWorkflowServer workflowServer = new WorkflowServer(Substitute.For<IWorkflowStore>(), Substitute.For<IWorkflowRegistrationService>(), exceptionHandler); workflowServer.ExecuteWorkflow(workflow); exceptionHandler.Received(1).HandleSingleInstanceWorkflowException(Arg.Any<Workflow>(), Arg.Any<Exception>()); }
public void ExecuteWorkflow_OnStepException_StateReset() { string initialState = Guid.NewGuid().ToString(); Workflow workflow = Substitute.For<Workflow>(); workflow.ResumeTrigger = "Test"; workflow.CurrentState.Returns(initialState); workflow.WhenForAnyArgs(x => x.Fire(Arg.Any<string>())).Do(x => { throw new Exception(); }); // execute IWorkflowServer workflowServer = new WorkflowServer(Substitute.For<IWorkflowStore>(), Substitute.For<IWorkflowRegistrationService>(), Substitute.For<IWorkflowExceptionHandler>()); workflowServer.ExecuteWorkflow(workflow); // make sure the property was set workflow.Received(1).CurrentState = initialState; }
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); }