public async Task Nested01_HappyPath_MovedToFinal(bool mockWorkflowStore) { var workflowEngineBuildResult = BuildWorkflowEngine(mockWorkflowStore, true, new NoOpActivity(), new NoOpEventHandler()); IEvent initialEvent = new SimpleDomainEntityEvent(Package01, "initial"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage02Id, initialEvent); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "awaitingSigners", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsFalse(Package01.GetProperty <bool>("IsSent")); var signer01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Signer01); Assert.IsTrue(string.Equals(signer01WorkflowInstance.CurrentStateCode, "awaitingBadges", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(signer01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsTrue(Signer01.GetProperty <bool>("IsSent")); // send event to a nested Signer01 to trigger its completion IEvent processEvent = new SimpleDomainEntityEvent(signer01WorkflowInstance.Id, "process"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowSigner01Id, processEvent); signer01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Signer01); Assert.IsTrue(string.Equals(signer01WorkflowInstance.CurrentStateCode, "final", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(signer01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); Assert.IsTrue(Signer01.GetProperty <DateTime>("LastVisited") > DateTime.MinValue); Assert.IsTrue(Signer01.GetProperty <bool>("VisitedIntermediateState")); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "final", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); Assert.IsTrue(Package01.GetProperty <bool>("IsSent")); }
public async Task Simple01_Cyclic_DetectCycleOfThreeStatesWithBothStores(bool mockWorkflowStore) { var workflowEngineBuildResult = BuildWorkflowEngine(mockWorkflowStore, false, new NoOpActivity(), new NoOpEventHandler()); var packageJsonState = new JsonState(); packageJsonState.SetProperty("IsSent", false); IEventRequestWorkflowMessage initialEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackageCyclic02Id, Package01.GetType().FullName, Package01.EntityId, "initial", packageJsonState.ToJsonString()); var workflowProcessingResult = await workflowEngineBuildResult.WorkflowEngine.ProcessMessage(initialEventWorkflowMessage); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process.03", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsTrue(workflowProcessingResult.WorkflowInstance.Entity.GetProperty <bool>("IsSent")); IEventRequestWorkflowMessage processEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackageCyclic02Id, workflowProcessingResult.WorkflowInstance.Id, "process", packageJsonState.ToJsonString()); workflowProcessingResult = await workflowEngineBuildResult.WorkflowEngine.ProcessMessage(processEventWorkflowMessage); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process.03", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); processEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackageCyclic02Id, workflowProcessingResult.WorkflowInstance.Id, "process", packageJsonState.ToJsonString()); workflowProcessingResult = await workflowEngineBuildResult.WorkflowEngine.ProcessMessage(processEventWorkflowMessage); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "failed", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); }
public async Task Simple01_HappyPath_MovedToFinalOnEventWorkflowMessages() { var workflowEngineBuildResult = BuildWorkflowEngine(true, false, new NoOpActivity(), new NoOpEventHandler()); var packageJsonState = new JsonState(); packageJsonState.SetProperty("IsSent", false); IEventRequestWorkflowMessage initialEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackage01Id, Package01.GetType().FullName, Package01.EntityId, "initial", packageJsonState.ToJsonString()); var workflowProcessingResult = await workflowEngineBuildResult.WorkflowEngine.ProcessMessage(initialEventWorkflowMessage); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsTrue(workflowProcessingResult.WorkflowInstance.Entity.GetProperty <bool>("IsSent")); IEventRequestWorkflowMessage processEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackage01Id, workflowProcessingResult.WorkflowInstance.Id, "process", "{}"); workflowProcessingResult = await workflowEngineBuildResult.WorkflowEngine.ProcessMessage(processEventWorkflowMessage); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "final", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); Assert.IsTrue(workflowProcessingResult.WorkflowInstance.Entity.GetProperty <bool>("IsSent")); }
public async Task Simple01_Lock_FailedToTakeTheLock() { var workflowEngineBuildResult02 = BuildWorkflowEngine(true, false, new NoOpActivity(), new NoOpEventHandler()); var workflowEngineBuildResult01 = BuildWorkflowEngine(true, false, new NoOpActivity(), new NoOpEventHandler()); var packageJsonState = new JsonState(); packageJsonState.SetProperty("IsSent", false); IEventRequestWorkflowMessage initialEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackage01Id, Package01.GetType().FullName, Package01.EntityId, "initial", packageJsonState.ToJsonString()); var workflowProcessingResult = await workflowEngineBuildResult01.WorkflowEngine.ProcessMessage(initialEventWorkflowMessage); var package01WorkflowInstance = workflowEngineBuildResult01.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsTrue(workflowProcessingResult.WorkflowInstance.Entity.GetProperty <bool>("IsSent")); Assert.IsTrue(package01WorkflowInstance.Lock.LockOwner == workflowEngineBuildResult01.WorkflowEngine.Id); WorkflowStoreMock.Verify(m => m.TryLockWorkflowInstance(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <CancellationToken>()), Times.Never); WorkflowStoreMock.Verify(m => m.TryUnlockWorkflowInstance(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <CancellationToken>()), Times.Once); IEventRequestWorkflowMessage processEventWorkflowMessage = new EventRequestWorkflowMessage( WorkflowPackage01Id, workflowProcessingResult.WorkflowInstance.Id, "process", "{}"); Assert.ThrowsAsync <WorkflowException>(() => workflowEngineBuildResult02.WorkflowEngine.ProcessMessage(processEventWorkflowMessage)); }
public async Task Simple01_Failed_DoNotAllowEventsWhileWaitingAsyncTransition(bool mockWorkflowStore) { var workflowEngineBuildResult = BuildWorkflowEngine(mockWorkflowStore, false, new NoOpActivity(), new NoOpEventHandler()); IEvent initialEvent = new SimpleDomainEntityEvent(Package01, "initial"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage04Id, initialEvent); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingAsyncTransition); Assert.IsTrue(Package01.GetProperty <bool>("IsSent")); IEvent processEvent = new SimpleDomainEntityEvent(package01WorkflowInstance.Id, "process"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage04Id, processEvent); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "failed", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); }
public async Task Simple01_HappyPath_MovedToFinal(bool mockWorkflowStore) { var workflowEngineBuildResult = BuildWorkflowEngine(mockWorkflowStore, false, new NoOpActivity(), new NoOpEventHandler()); IEvent initialEvent = new SimpleDomainEntityEvent(Package01, "initial"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage04Id, initialEvent); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingAsyncTransition); Assert.IsTrue(Package01.GetProperty <bool>("IsSent")); IWorkflowMessage workflowMessage = new AsynchronousTransitionWorkflowMessage(WorkflowPackage04Id, package01WorkflowInstance.Id, "{}"); await workflowEngineBuildResult.WorkflowEngine.ProcessMessage(workflowMessage); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "final", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); }
public async Task Simple01_IntermediateFailure_RecoveredAndMovedToFinal() { var workflowEngineBuildResult = BuildWorkflowEngine(true, false, new NoOpActivity(), new NoOpEventHandler()); IEvent initialEvent = new SimpleDomainEntityEvent(Package01, "initial"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage07Id, initialEvent); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "process", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsTrue(Package01.GetProperty <bool>("IsSent")); IEvent processEvent = new SimpleDomainEntityEvent(package01WorkflowInstance.Id, "process"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage07Id, processEvent); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "final", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); }
public async Task Nested01_NestedWorkflowFailed_MovedToFailed(bool mockWorkflowStore) { var workflowEngineBuildResult = BuildWorkflowEngine(mockWorkflowStore, true, new NoOpWithExceptionActivity(), new NoOpEventHandler()); IEvent initialEvent = new SimpleDomainEntityEvent(Package01, "initial"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowPackage02Id, initialEvent); var package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "awaitingSigners", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsFalse(Package01.GetProperty <bool>("IsSent")); var signer01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Signer01); Assert.IsTrue(string.Equals(signer01WorkflowInstance.CurrentStateCode, "awaitingBadges", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(signer01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.AwaitingEvent); Assert.IsTrue(Signer01.GetProperty <bool>("IsSent")); // send event to a nested Signer01 to trigger its move to failed ==> Package01 & Singer01 & Signer02 must be moved to failed IEvent processEvent = new SimpleDomainEntityEvent(signer01WorkflowInstance.Id, "process"); await workflowEngineBuildResult.WorkflowEngine.ProcessEvent(WorkflowSigner01Id, processEvent); package01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Package01); Assert.IsTrue(string.Equals(package01WorkflowInstance.CurrentStateCode, "failed", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(package01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); Assert.IsFalse(Package01.GetProperty <bool>("IsSent")); signer01WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Signer01); Assert.IsTrue(string.Equals(signer01WorkflowInstance.CurrentStateCode, "failed", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(signer01WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); var signer02WorkflowInstance = workflowEngineBuildResult.GetWorkflowInstance(Signer02); Assert.IsTrue(string.Equals(signer02WorkflowInstance.CurrentStateCode, "failed", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(signer02WorkflowInstance.CurrentStateProgress == StateExecutionProgress.Completed); }