Update tests

This commit is contained in:
Sipke Schoorstra 2022-04-25 11:27:18 +02:00
parent 9c321a5fe0
commit be913c7aa0
2 changed files with 23 additions and 9 deletions

View file

@ -26,10 +26,17 @@ public class Tests
var workflow = new WorkflowDefinitionBuilder().BuildWorkflow<BreakWhileBlockForkWorkflow>();
// Start workflow.
await _workflowRunner.RunAsync(workflow);
var result1 = await _workflowRunner.RunAsync(workflow);
// Resume one of the branches.
var bookmark = result1.Bookmarks.FirstOrDefault(x => x.ActivityId == "Branch 1");
var result2 = await _workflowRunner.RunAsync(workflow, result1.WorkflowState, bookmark);
// Assert that all bookmarks have been cleared.
Assert.Empty(result2.Bookmarks);
// Verify expected output.
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Current value: 0", "Branch 1", "Blocking Branch 2" }, lines);
Assert.Equal(new[] { "Branch 1", "Branch 2", "Branch 1 - Resumed" }, lines);
}
}

View file

@ -13,27 +13,34 @@ public class BreakWhileBlockForkWorkflow : IWorkflow
var currentValue = new Variable<int?>(0);
workflow.WithVariable(currentValue);
workflow.WithRoot(new While(context => currentValue.Get(context) < 3)
workflow.WithRoot(new While(() => true)
{
Body =
new Sequence
{
Activities =
{
new WriteLine(context => $"Current value: {currentValue.Get<int>(context)}"),
new SetVariable<int?>(currentValue, context => currentValue.Get(context) + 1),
new Fork
{
JoinMode = JoinMode.WaitAll,
Branches =
{
new WriteLine("Branch 1"),
new Sequence{
Activities =
{
new WriteLine("Branch 1"),
new Event("Branch 1") { Id = "Branch 1" },
new WriteLine("Branch 1 - Resumed"),
new Break()
}
},
new Sequence
{
Activities =
{
new WriteLine("Blocking Branch 2"),
new Event("Some event") { Id = "SomeEvent" },
new WriteLine("Resuming Branch 2"),
new WriteLine("Branch 2"),
new Event("Branch 2") { Id = "Branch 2" },
new WriteLine("Branch 2 - Resumed"),
}
}
}