Skip to content

Commit

Permalink
Merge pull request #4 from jakemoresca/json_workflow_provider_ext
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemoresca authored Jul 11, 2024
2 parents 08886a8 + 79e6f04 commit 41829d5
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 366 deletions.
7 changes: 7 additions & 0 deletions ActionFlow.Tests/ActionFlow.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="DynamicExpresso.Core" Version="2.16.1" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
Expand All @@ -24,4 +25,10 @@
<ProjectReference Include="..\ActionFlow\ActionFlow.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Providers\workflows.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
112 changes: 56 additions & 56 deletions ActionFlow.Tests/Actions/CallWorkflowActionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ActionFlow.Actions;
using ActionFlow.Domain.Actions;
using ActionFlow.Domain.Engine;
using ActionFlow.Engine;
using ActionFlow.Engine.Factories;
Expand All @@ -7,71 +8,70 @@

namespace ActionFlow.Tests.Actions
{
[TestClass]
public class CallWorkflowActionTests
{
[TestMethod]
public async Task When_executing_it_should_call_other_workflow_and_get_output_variable()
{
//Arrange
var workflowProvider = Substitute.For<IWorkflowProvider>();
var workflows = CreateFakeWorkflowsWithOutput();
workflowProvider.GetAllWorkflows().Returns(workflows);
[TestClass]
public class CallWorkflowActionTests
{
[TestMethod]
public async Task When_executing_it_should_call_other_workflow_and_get_output_variable()
{
//Arrange
var workflowProvider = Substitute.For<IWorkflowProvider>();
var workflows = CreateFakeWorkflowsWithOutput();
workflowProvider.GetAllWorkflows().Returns(workflows);

var stepActionFactory = Substitute.For<IStepActionFactory>();
stepActionFactory.Get("Variable").Returns(new SetVariableAction());
var stepActionFactory = Substitute.For<IStepActionFactory>();
stepActionFactory.Get("Variable").Returns(new SetVariableAction());

var stepExecutionEvaluator = new StepExecutionEvaluator();
var stepExecutionEvaluator = new StepExecutionEvaluator();
var actionFlowEngine = new ActionFlowEngine(workflowProvider, stepActionFactory, stepExecutionEvaluator);

var actionFlowEngine = new ActionFlowEngine(workflowProvider, stepActionFactory, stepExecutionEvaluator);
var sut = new CallWorkflowAction();
var executionContext = new ActionFlow.Engine.ExecutionContext(actionFlowEngine);
var parameters = new Dictionary<string, string>
{
{ "age", "18" }
};
var targetWorkflowName = "Test Workflow Rule 2";
var resultVariableName = "result";
executionContext.AddOrUpdateActionProperty(CallWorkflowAction.WorkflowNameKey, targetWorkflowName);
executionContext.AddOrUpdateActionProperty(CallWorkflowAction.ResultVariableKey, resultVariableName);
executionContext.AddOrUpdateActionProperty(CallWorkflowAction.ParametersKey, parameters);
sut.SetExecutionContext(executionContext);

var sut = new CallWorkflowAction();
var executionContext = new ActionFlow.Engine.ExecutionContext(actionFlowEngine);
var parameters = new Dictionary<string, string>
{
{ "age", "18" }
};
var targetWorkflowName = "Test Workflow Rule 2";
var resultVariableName = "result";
executionContext.AddOrUpdateActionProperty(CallWorkflowAction.WorkflowNameKey, targetWorkflowName);
executionContext.AddOrUpdateActionProperty(CallWorkflowAction.ResultVariableKey, resultVariableName);
executionContext.AddOrUpdateActionProperty(CallWorkflowAction.ParametersKey, parameters);
sut.SetExecutionContext(executionContext);
//Act
await sut.ExecuteAction();

//Act
await sut.ExecuteAction();
//Assert
var output = executionContext.EvaluateExpression<Dictionary<string, object>>(resultVariableName);
Assert.AreEqual(true, output["canVote"]);
}

//Assert
var output = executionContext.EvaluateExpression<Dictionary<string, object>>(resultVariableName);
Assert.IsTrue((bool)output["canVote"]);
}
private static List<Workflow> CreateFakeWorkflowsWithOutput()
{
List<Workflow> workflows = [];

private static List<Workflow> CreateFakeWorkflowsWithOutput()
{
List<Workflow> workflows = [];
var targetWorkflowName = "Test Workflow Rule 2";

var targetWorkflowName = "Test Workflow Rule 2";
var steps2 = new List<Step>
{
new("test variable value", "Variable", new Dictionary<string, object>
{
{
SetVariableAction.VariablesKey, new Dictionary<string, string>
{
{ "canVote", "age >= 18" }
}
}
})
};

var steps2 = new List<Step>
{
new("test variable value", "Variable", new Dictionary<string, object>
{
{
SetVariableAction.VariablesKey, new Dictionary<string, string>
{
{ "canVote", "age >= 18" }
}
}
})
};

Workflow workflow2 = new Workflow(targetWorkflowName, steps2,
Workflow workflow2 = new Workflow(targetWorkflowName, steps2,
[
new Parameter{ Name = "canVote", Expression = "canVote"}
]);
workflows.Add(workflow2);
new() { Name = "canVote", Expression = "canVote"}
]);
workflows.Add(workflow2);

return workflows;
}
}
return workflows;
}
}
}
Loading

0 comments on commit 41829d5

Please sign in to comment.