forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.cs
45 lines (37 loc) · 1.82 KB
/
Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Linq;
using System.Threading.Tasks;
using Elsa.Extensions;
using Elsa.Testing.Shared;
using Elsa.Workflows.Core.Services;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;
namespace Elsa.IntegrationTests.Scenarios.BlockingAndBreaking;
public class Tests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IWorkflowBuilderFactory _workflowBuilderFactory;
public Tests(ITestOutputHelper testOutputHelper)
{
var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowBuilderFactory = services.GetRequiredService<IWorkflowBuilderFactory>();
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "While loop blocks when bookmark is created")]
public async Task Test1()
{
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync<BreakWhileBlockForkWorkflow>();
// Start workflow.
var result1 = await _workflowRunner.RunAsync(workflow);
// Resume one of the branches.
var bookmark = result1.WorkflowState.Bookmarks.FirstOrDefault(x => x.ActivityNodeId == "Workflow1:While1:Sequence1:Fork1:Sequence2:Branch 1");
var runOptions = new RunWorkflowOptions(BookmarkId: bookmark!.Id);
var result2 = await _workflowRunner.RunAsync(workflow, result1.WorkflowState, runOptions);
// Assert that all bookmarks have been cleared.
Assert.Empty(result2.WorkflowState.Bookmarks);
// Verify expected output.
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Branch 2", "Branch 1", "Branch 1 - Resumed" }, lines);
}
}