Add Fork tests
This commit is contained in:
parent
81c88eee7c
commit
c79acde5fc
|
|
@ -0,0 +1,21 @@
|
|||
using Elsa.Activities;
|
||||
using Elsa.Contracts;
|
||||
using Elsa.Modules.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class BasicForkWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
workflow.WithRoot(new Fork
|
||||
{
|
||||
Branches =
|
||||
{
|
||||
new WriteLine("Branch 1"),
|
||||
new WriteLine("Branch 2"),
|
||||
new WriteLine("Branch 3")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
51
test/Elsa.IntegrationTests/Activities/Fork/ForkTests.cs
Normal file
51
test/Elsa.IntegrationTests/Activities/Fork/ForkTests.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Contracts;
|
||||
using Elsa.Testing.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class ForkTests
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
|
||||
public ForkTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "Each branch executes")]
|
||||
public async Task Test1()
|
||||
{
|
||||
var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BasicForkWorkflow());
|
||||
await _workflowRunner.RunAsync(workflow);
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(new[]{ "Branch 1", "Branch 2", "Branch 3" }, lines);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "Wait Any causes workflow to continue")]
|
||||
public async Task Test2()
|
||||
{
|
||||
var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new JoinAnyForkWorkflow());
|
||||
|
||||
// First run.
|
||||
var result = await _workflowRunner.RunAsync(workflow);
|
||||
|
||||
// Collect one of the bookmarks to resume the workflow.
|
||||
var bookmark = result.Bookmarks.FirstOrDefault(x => x.ActivityId == "Event2");
|
||||
Assert.NotNull(bookmark);
|
||||
|
||||
// Resume the workflow.
|
||||
await _workflowRunner.RunAsync(workflow, result.WorkflowState, bookmark);
|
||||
|
||||
// Verify output.
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(new[]{ "Start", "Branch 2", "End" }, lines);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
using Elsa.Activities;
|
||||
using Elsa.Contracts;
|
||||
using Elsa.Modules.Activities.Console;
|
||||
using Elsa.Modules.Activities.Primitives;
|
||||
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class JoinAnyForkWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Start"),
|
||||
new Fork
|
||||
{
|
||||
Branches =
|
||||
{
|
||||
new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new Event("Event 1")
|
||||
{
|
||||
Id = "Event1"
|
||||
},
|
||||
new WriteLine("Branch 1")
|
||||
}
|
||||
},
|
||||
new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new Event("Event 2")
|
||||
{
|
||||
Id = "Event2"
|
||||
},
|
||||
new WriteLine("Branch 2")
|
||||
}
|
||||
},
|
||||
new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new Event("Event 3")
|
||||
{
|
||||
Id = "Event3"
|
||||
},
|
||||
new WriteLine("Branch 3")
|
||||
}
|
||||
},
|
||||
},
|
||||
JoinMode = JoinMode.WaitAny
|
||||
},
|
||||
new WriteLine("End")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue