Add project files.

This commit is contained in:
2025-08-18 17:11:43 +03:30
parent 807dc263be
commit e5eb10d604
3943 changed files with 223719 additions and 0 deletions
@@ -0,0 +1,88 @@
using Elsa.Extensions;
using Elsa.Testing.Shared;
using Elsa.Workflows.IntegrationTests.Scenarios.BlockingAndBreaking.Workflows;
using Elsa.Workflows.Options;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Scenarios.BlockingAndBreaking;
public class Tests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IWorkflowBuilderFactory _workflowBuilderFactory;
private readonly IServiceProvider _services;
public Tests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowBuilderFactory = _services.GetRequiredService<IWorkflowBuilderFactory>();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Fork completes after all branches complete.")]
public async Task Test1()
{
await _services.PopulateRegistriesAsync();
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync<WaitAllForkWorkflow>();
// Start workflow.
var result1 = await _workflowRunner.RunAsync(workflow);
// Resume the first branch.
var bookmark = result1.WorkflowState.Bookmarks.FirstOrDefault(x => x.ActivityId == "Branch 1");
var runOptions = new RunWorkflowOptions { BookmarkId = bookmark!.Id };
var result2 = await _workflowRunner.RunAsync(workflow, result1.WorkflowState, runOptions);
// Resume the second branch.
bookmark = result2.WorkflowState.Bookmarks.FirstOrDefault(x => x.ActivityId == "Branch 2");
runOptions = new RunWorkflowOptions { BookmarkId = bookmark!.Id };
var result3 = await _workflowRunner.RunAsync(workflow, result2.WorkflowState, runOptions);
// Verify expected output.
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "Branch 1", "Branch 2", "Branch 1 - Resumed", "Branch 2 - Resumed", "End" }, lines);
}
[Fact(DisplayName = "Fork completes after any branch completes.")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync<WaitAnyForkWorkflow>();
// Start workflow.
var result1 = await _workflowRunner.RunAsync(workflow);
// Resume the first branch.
var bookmark = result1.WorkflowState.Bookmarks.FirstOrDefault(x => x.ActivityId == "Branch 1");
var runOptions = new RunWorkflowOptions { BookmarkId = bookmark!.Id };
var result2 = await _workflowRunner.RunAsync(workflow, result1.WorkflowState, runOptions);
// Verify expected output.
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "Branch 1", "Branch 2", "Branch 1 - Resumed", "End" }, lines);
}
[Fact(DisplayName = "Break breaks out of While loop.")]
public async Task Test3()
{
await _services.PopulateRegistriesAsync();
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync<BreakWhileFromForkWorkflow>();
// Start workflow.
var result1 = await _workflowRunner.RunAsync(workflow);
// Resume the first branch.
var bookmark = result1.WorkflowState.Bookmarks.FirstOrDefault(x => x.ActivityId == "Branch 1");
var runOptions = new RunWorkflowOptions { BookmarkId = bookmark!.Id };
var result2 = await _workflowRunner.RunAsync(workflow, result1.WorkflowState, runOptions);
// There should be no bookmarks left, since the while loop was broken out of.
Assert.Empty(result2.WorkflowState.Bookmarks);
// Verify expected output.
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "Branch 1", "Branch 2", "Branch 1 - Resumed", "End" }, lines);
}
}
@@ -0,0 +1,61 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.IntegrationTests.Scenarios.BlockingAndBreaking.Workflows;
public class BreakWhileFromForkWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var currentValue = new Variable<int?>("CurrentValue", 0);
workflow.WithVariable(currentValue);
workflow.Root = new Sequence
{
Activities =
{
new WriteLine("Start"),
new While(() => true)
{
Body = new Sequence
{
Activities =
{
new Fork
{
JoinMode = ForkJoinMode.WaitAll,
Branches =
{
new Sequence
{
Activities =
{
new WriteLine("Branch 1"),
new Event("Branch 1") { Id = "Branch 1" },
new WriteLine("Branch 1 - Resumed"),
// This should break the while loop, not matter how high up in the tree it is.
new Break()
}
},
new Sequence
{
Activities =
{
new WriteLine("Branch 2"),
new Event("Branch 2") { Id = "Branch 2" },
new WriteLine("Branch 2 - Resumed"),
}
}
}
}
}
}
},
new WriteLine("End")
}
};
}
}
@@ -0,0 +1,50 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.IntegrationTests.Scenarios.BlockingAndBreaking.Workflows;
public class WaitAllForkWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var currentValue = new Variable<int?>("CurrentValue", 0);
workflow.WithVariable(currentValue);
workflow.Root =
new Sequence
{
Activities =
{
new WriteLine("Start"),
new Fork
{
JoinMode = ForkJoinMode.WaitAll,
Branches =
{
new Sequence
{
Activities =
{
new WriteLine("Branch 1"),
new Event("Branch 1") { Id = "Branch 1" },
new WriteLine("Branch 1 - Resumed"),
}
},
new Sequence
{
Activities =
{
new WriteLine("Branch 2"),
new Event("Branch 2") { Id = "Branch 2" },
new WriteLine("Branch 2 - Resumed"),
}
}
}
},
new WriteLine("End")
}
};
}
}
@@ -0,0 +1,50 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.IntegrationTests.Scenarios.BlockingAndBreaking.Workflows;
public class WaitAnyForkWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var currentValue = new Variable<int?>("CurrentValue", 0);
workflow.WithVariable(currentValue);
workflow.Root =
new Sequence
{
Activities =
{
new WriteLine("Start"),
new Fork
{
JoinMode = ForkJoinMode.WaitAny,
Branches =
{
new Sequence
{
Activities =
{
new WriteLine("Branch 1"),
new Event("Branch 1") { Id = "Branch 1" },
new WriteLine("Branch 1 - Resumed"),
}
},
new Sequence
{
Activities =
{
new WriteLine("Branch 2"),
new Event("Branch 2") { Id = "Branch 2" },
new WriteLine("Branch 2 - Resumed"),
}
}
}
},
new WriteLine("End")
}
};
}
}