diff --git a/src/modules/Elsa.WorkflowTesting.Api/Elsa.WorkflowTesting.Api.csproj b/src/modules/Elsa.WorkflowTesting.Api/Elsa.WorkflowTesting.Api.csproj
index 97af0d6f2..80af17ef6 100644
--- a/src/modules/Elsa.WorkflowTesting.Api/Elsa.WorkflowTesting.Api.csproj
+++ b/src/modules/Elsa.WorkflowTesting.Api/Elsa.WorkflowTesting.Api.csproj
@@ -2,7 +2,6 @@
net5.0
- enable
enable
default
diff --git a/src/modules/Elsa.WorkflowTesting/Elsa.WorkflowTesting.csproj b/src/modules/Elsa.WorkflowTesting/Elsa.WorkflowTesting.csproj
index a9655fd87..06d938bf0 100644
--- a/src/modules/Elsa.WorkflowTesting/Elsa.WorkflowTesting.csproj
+++ b/src/modules/Elsa.WorkflowTesting/Elsa.WorkflowTesting.csproj
@@ -2,7 +2,6 @@
net5.0
- enable
enable
default
diff --git a/src/modules/Elsa.WorkflowTesting/Messages/WorkflowTestMessage.cs b/src/modules/Elsa.WorkflowTesting/Messages/WorkflowTestMessage.cs
index c080fb2d8..1772b7b21 100644
--- a/src/modules/Elsa.WorkflowTesting/Messages/WorkflowTestMessage.cs
+++ b/src/modules/Elsa.WorkflowTesting/Messages/WorkflowTestMessage.cs
@@ -1,3 +1,5 @@
+using System.Collections.Generic;
+
namespace Elsa.WorkflowTesting.Messages
{
public class WorkflowTestMessage
diff --git a/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestLaunchpad.cs b/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestLaunchpad.cs
index a87c37afa..0e582562d 100644
--- a/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestLaunchpad.cs
+++ b/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestLaunchpad.cs
@@ -1,4 +1,6 @@
-using Elsa.Services.Models;
+using System.Threading;
+using System.Threading.Tasks;
+using Elsa.Services.Models;
namespace Elsa.WorkflowTesting.Services
{
diff --git a/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestService.cs b/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestService.cs
index 71280d6c9..7d1f50766 100644
--- a/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestService.cs
+++ b/src/modules/Elsa.WorkflowTesting/Services/IWorkflowTestService.cs
@@ -1,3 +1,4 @@
+using System.Threading.Tasks;
using Elsa.WorkflowTesting.Messages;
namespace Elsa.WorkflowTesting.Services
diff --git a/src/modules/Elsa.WorkflowTesting/Services/WorkflowTestLaunchpad.cs b/src/modules/Elsa.WorkflowTesting/Services/WorkflowTestLaunchpad.cs
index 4bb18cccc..549d4e10b 100644
--- a/src/modules/Elsa.WorkflowTesting/Services/WorkflowTestLaunchpad.cs
+++ b/src/modules/Elsa.WorkflowTesting/Services/WorkflowTestLaunchpad.cs
@@ -1,4 +1,8 @@
-using Elsa.Models;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Elsa.Models;
using Elsa.Persistence;
using Elsa.Persistence.Specifications;
using Elsa.Services;
@@ -24,7 +28,7 @@ namespace Elsa.WorkflowTesting.Services
_workflowFactory = workflowFactory;
_workflowRunner = workflowRunner;
}
-
+
public async Task FindAndRestartTestWorkflowAsync(
string workflowDefinitionId,
string activityId,
@@ -35,30 +39,30 @@ namespace Elsa.WorkflowTesting.Services
CancellationToken cancellationToken = default)
{
var workflowBlueprint = await _workflowRegistry.GetAsync(workflowDefinitionId, tenantId, VersionOptions.SpecificVersion(version), cancellationToken);
-
+
if (workflowBlueprint == null)
return null;
-
+
var lastWorkflowInstance = await _workflowInstanceStore.FindAsync(new EntityIdSpecification(lastWorkflowInstanceId), cancellationToken);
-
+
if (lastWorkflowInstance == null)
return null;
-
+
var startActivity = workflowBlueprint.Activities.First(x => x.Id == activityId);
-
+
var startableWorkflowDefinition = new StartableWorkflowDefinition(workflowBlueprint, startActivity.Id);
-
+
var workflow = await InstantiateStartableWorkflow(startableWorkflowDefinition, cancellationToken);
-
+
var previousActivityData = GetActivityDataFromLastWorkflowInstance(workflow.WorkflowInstance, lastWorkflowInstance, workflowBlueprint, activityId);
-
+
MergeActivityDataIntoInstance(workflow.WorkflowInstance, previousActivityData);
-
+
SetMetadata(workflow.WorkflowInstance, signalRConnectionId);
-
+
//if previousActivityOutput has any items, then the first one is from activity closest to the starting one
var previousActivityOutput = previousActivityData.Count == 0 ? null : previousActivityData.First().Value?.GetItem("Output");
-
+
return await ExecuteStartableWorkflowAsync(workflow, new WorkflowInput(previousActivityOutput), cancellationToken);
}
@@ -67,7 +71,7 @@ namespace Elsa.WorkflowTesting.Services
workflowInstance.SetMetadata("isTest", true);
workflowInstance.SetMetadata("signalRConnectionId", signalRConnectionId);
}
-
+
private void MergeActivityDataIntoInstance(WorkflowInstance workflowInstance, IDictionary> activityData)
{
foreach (var (key, value) in activityData)
@@ -75,24 +79,24 @@ namespace Elsa.WorkflowTesting.Services
workflowInstance.ActivityData[key] = value;
}
}
-
+
private IDictionary> GetActivityDataFromLastWorkflowInstance(WorkflowInstance currentWorkflowInstance, WorkflowInstance lastWorkflowInstance, IWorkflowBlueprint workflowBlueprint, string startingActivityId)
{
IDictionary> CollectSourceActivityData(string targetActivityId, IDictionary> activityDataAccumulator)
{
var sourceActivityId = workflowBlueprint.Connections.FirstOrDefault(x => x.Target.Activity.Id == targetActivityId)?.Source.Activity.Id;
-
+
if (sourceActivityId == null)
return activityDataAccumulator;
-
+
activityDataAccumulator.Add(sourceActivityId, lastWorkflowInstance.ActivityData.GetItem(sourceActivityId));
-
+
return CollectSourceActivityData(sourceActivityId, activityDataAccumulator);
}
-
+
return CollectSourceActivityData(startingActivityId, new Dictionary>());
}
-
+
private async Task InstantiateStartableWorkflow(StartableWorkflowDefinition startableWorkflowDefinition, CancellationToken cancellationToken)
{
var workflowInstance = await _workflowFactory.InstantiateAsync(
@@ -100,11 +104,11 @@ namespace Elsa.WorkflowTesting.Services
startableWorkflowDefinition.CorrelationId,
startableWorkflowDefinition.ContextId,
cancellationToken: cancellationToken);
-
+
await _workflowInstanceStore.SaveAsync(workflowInstance, cancellationToken);
return new StartableWorkflow(startableWorkflowDefinition.WorkflowBlueprint, workflowInstance, startableWorkflowDefinition.ActivityId);
}
-
+
private async Task ExecuteStartableWorkflowAsync(StartableWorkflow startableWorkflow, WorkflowInput? input, CancellationToken cancellationToken = default) =>
await _workflowRunner.RunWorkflowAsync(startableWorkflow.WorkflowBlueprint, startableWorkflow.WorkflowInstance, startableWorkflow.ActivityId, input, cancellationToken);
}