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,64 @@
using Elsa.Testing.Shared;
using Elsa.Workflows.IntegrationTests.Activities.Workflows;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class BreakTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
public BreakTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Break exits out of ForEach")]
public async Task Test1()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<BreakForEachWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "C#", "End" }, lines);
}
[Fact(DisplayName = "Break exits out of immediate ForEach only")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<NestedForEachWithBreakWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "C#", "Classes", "Rust", "Classes", "Go", "Classes" }, lines);
}
[Fact(DisplayName = "Break exits out of For")]
public async Task Test3()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<BreakForWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "0", "1", "End" }, lines);
}
[Fact(DisplayName = "Break exits out of While")]
public async Task Test4()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<BreakWhileWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "1", "2", "End" }, lines);
}
[Fact(DisplayName = "Break removes the right bookmarks")]
public async Task Test5()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<BreakWhileWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "1", "2", "End" }, lines);
}
}
@@ -0,0 +1,38 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows.IntegrationTests.Activities.Workflows;
class BreakForEachWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var items = new[] { "C#", "Rust", "Go" };
var currentItem = new Variable<string>("CurrentItem", "");
workflow.Root = new Sequence
{
Activities =
{
new WriteLine("Start"),
new ForEach<string>
{
Items = new(items),
CurrentValue = new (currentItem),
Body = new Sequence
{
Activities =
{
new If(context => currentItem.Get(context) == "Rust")
{
Then = new Break()
},
new WriteLine(currentItem)
}
}
},
new WriteLine("End"),
}
};
}
}
@@ -0,0 +1,36 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows.IntegrationTests.Activities.Workflows;
class BreakForWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var currentValue = new Variable<int?>("CurrentValue", null);
workflow.Root = new Sequence
{
Activities =
{
new WriteLine("Start"),
new For(0, 3, 1)
{
CurrentValue = new (currentValue),
Body = new Sequence
{
Activities =
{
new If(context => currentValue.Get(context) == 2)
{
Then = new Break()
},
new WriteLine(context => currentValue.Get(context).ToString()),
}
}
},
new WriteLine("End"),
}
};
}
}
@@ -0,0 +1,51 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities.Workflows;
public class BreakWhileForkWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var currentValue = new Variable<int?>("CurrentValue", 0);
workflow.Root = new Sequence
{
Variables = { currentValue },
Activities =
{
While.True(new Fork
{
Branches =
{
new Sequence
{
Activities =
{
new SetVariable
{
Variable = currentValue,
Value = new (context => currentValue.Get(context) + 1)
},
new If(context => currentValue.Get(context) == 3)
{
Then = new Break()
}
}
},
new Sequence
{
Activities =
{
new WriteLine("Waiting for event..."),
new Event("Some event") { Id = "SomeEvent" },
new WriteLine("Resuming"),
}
}
}
}),
}
};
}
}
@@ -0,0 +1,38 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows.IntegrationTests.Activities.Workflows;
public class BreakWhileWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var currentValue = new Variable<int?>("CurrentValue", 0);
workflow.Root = new Sequence
{
Variables = { currentValue },
Activities =
{
new WriteLine("Start"),
While.True(new Sequence
{
Activities =
{
new SetVariable
{
Variable = currentValue,
Value = new (context => currentValue.Get(context) + 1)
},
new If(context => currentValue.Get(context) == 3)
{
Then = new Break()
},
new WriteLine(context => currentValue.Get(context).ToString()),
}
}),
new WriteLine("End"),
}
};
}
}
@@ -0,0 +1,34 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class FinishForkedWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = new Fork
{
JoinMode = ForkJoinMode.WaitAll,
Branches =
{
new Sequence
{
Activities =
{
new WriteLine("Branch 1"),
new Event("Event 1")
}
},
new Sequence
{
Activities =
{
new WriteLine("Branch 2"),
new Finish()
}
}
}
};
}
}
@@ -0,0 +1,19 @@
using Elsa.Workflows.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class FinishSequentialWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = new Sequence
{
Activities =
{
new WriteLine("Line 1"),
new Finish(),
new WriteLine("Line 2")
}
};
}
}
@@ -0,0 +1,45 @@
using Elsa.Testing.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class FinishTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
public FinishTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Subsequent activities are not executed")]
public async Task Test1()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<FinishSequentialWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Line 1" }, lines);
}
[Fact(DisplayName = "Workflow status is set to Finished")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
var result = await _workflowRunner.RunAsync<FinishSequentialWorkflow>();
var workflowState = result.WorkflowState;
Assert.Equal(WorkflowStatus.Finished, workflowState.Status);
Assert.Equal(WorkflowSubStatus.Finished, workflowState.SubStatus);
}
[Fact(DisplayName = "All bookmarks are removed")]
public async Task Test3()
{
await _services.PopulateRegistriesAsync();
var result = await _workflowRunner.RunAsync<FinishSequentialWorkflow>();
Assert.Empty(result.WorkflowState.Bookmarks);
}
}
@@ -0,0 +1,28 @@
using Elsa.Testing.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class ForEachTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
public ForEachTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "ForEach outputs each iteration")]
public async Task Test1()
{
var items = new[] { "C#", "Rust", "Go"};
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync(new ForEachWorkflow(items));
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(items, lines);
}
}
@@ -0,0 +1,33 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows.IntegrationTests.Activities;
class ForEachWorkflow : WorkflowBase
{
private readonly ICollection<string> _items;
public ForEachWorkflow(ICollection<string> items)
{
_items = items;
}
protected override void Build(IWorkflowBuilder workflow)
{
var currentItem = new Variable<string>("CurrentItem", "");
workflow.Root = new Sequence
{
Variables = { currentItem },
Activities =
{
new ForEach<string>
{
Items = new(_items),
CurrentValue = new(currentItem),
Body = new WriteLine(currentItem)
},
}
};
}
}
@@ -0,0 +1,42 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows.IntegrationTests.Activities;
class NestedForEachWithBreakWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var outerItems = new[] { "C#", "Rust", "Go" };
var innerItems = new[] { "Classes", "Functions", "Modules" };
var currentOuterItem = new Variable<string>("CurrentOuterItem", "");
var currentInnerItem = new Variable<string>("CurrentInnerItem", "");
workflow.Root = new ForEach<string>(outerItems)
{
CurrentValue = new (currentOuterItem),
Body = new Sequence
{
Activities =
{
new WriteLine(currentOuterItem),
new ForEach<string>(innerItems)
{
CurrentValue = new (currentInnerItem),
Body = new Sequence
{
Activities =
{
new If(context => currentInnerItem.Get(context) == "Functions")
{
Then = new Break()
},
new WriteLine(currentInnerItem)
}
}
}
}
}
};
}
}
@@ -0,0 +1,19 @@
using Elsa.Workflows.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class BasicForkWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = new Fork
{
Branches =
{
new WriteLine("Branch 1"),
new WriteLine("Branch 2"),
new WriteLine("Branch 3")
}
};
}
}
@@ -0,0 +1,54 @@
using Elsa.Extensions;
using Elsa.Testing.Shared;
using Elsa.Workflows.Options;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class ForkTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IWorkflowBuilderFactory _workflowBuilderFactory;
private IServiceProvider _services;
public ForkTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowBuilderFactory = _services.GetRequiredService<IWorkflowBuilderFactory>();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Each branch executes")]
public async Task Test1()
{
await _services.PopulateRegistriesAsync();
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync<BasicForkWorkflow>();
await _workflowRunner.RunAsync(workflow);
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Branch 1", "Branch 2", "Branch 3" }, lines);
}
[Fact(DisplayName = "Wait AnyAsync causes workflow to continue")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
var workflow = await _workflowBuilderFactory.CreateBuilder().BuildWorkflowAsync<JoinAnyForkWorkflow>();
// First run.
var result = await _workflowRunner.RunAsync(workflow);
// Collect one of the bookmarks to resume the workflow.
var bookmark = result.WorkflowState.Bookmarks.FirstOrDefault(x => x.ActivityId == "Event2");
Assert.NotNull(bookmark);
// Resume the workflow.
var runOptions = new RunWorkflowOptions { BookmarkId = bookmark.Id };
await _workflowRunner.RunAsync(workflow, result.WorkflowState, runOptions);
// Verify output.
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "Branch 2", "End" }, lines);
}
}
@@ -0,0 +1,59 @@
using Elsa.Workflows.Activities;
using Elsa.Workflows.Runtime.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class JoinAnyForkWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = 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 = ForkJoinMode.WaitAny
},
new WriteLine("End")
}
};
}
}
@@ -0,0 +1,59 @@
using Elsa.Testing.Shared;
using Elsa.Workflows.Activities;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class IfTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
public IfTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Theory(DisplayName = "The correct branch executes when condition is true")]
[InlineData(true)]
[InlineData(false)]
public async Task Test1(bool conditionResult)
{
var result = default(bool?);
var activity = new If(() => conditionResult)
{
Then = new Inline(() => result = true),
Else = new Inline(() => result = false)
};
await _services.RunActivityAsync(activity);
Assert.Equal(conditionResult, result);
}
[Theory(DisplayName = "The If activity completes only after either one of its branches completed")]
[InlineData(true)]
[InlineData(false)]
public async Task Test2(bool conditionResult)
{
var activity = new If(() => conditionResult)
{
Then = new Inline(),
Else = new Inline()
};
var result = await _services.RunActivityAsync(activity);
Assert.Equal(WorkflowStatus.Finished, result.WorkflowState.Status);
}
[Fact(DisplayName = "The If activity produces a result when one of its branches completes")]
public async Task Test3()
{
var activity = new If(() => true);
var result = await _services.RunActivityAsync(activity);
var activityResult = result.GetActivityOutput<bool>(activity);
Assert.True(activityResult);
}
}
@@ -0,0 +1,27 @@
using Elsa.Workflows.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities;
class NestedSequentialWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = new Sequence
{
Activities =
{
new WriteLine("Start"),
new Sequence
{
Activities =
{
new WriteLine("Line 1"),
new WriteLine("Line 2"),
new WriteLine("Line 3")
}
},
new WriteLine("End"),
}
};
}
}
@@ -0,0 +1,38 @@
using Elsa.Testing.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class SequenceTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
public SequenceTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Sequence completes after its child activities complete")]
public async Task Test1()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync(new SequentialWorkflow());
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Line 1", "Line 2", "Line 3" }, lines);
}
[Fact(DisplayName = "Sequence completes after its child sequence activity complete")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync(new NestedSequentialWorkflow());
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Start", "Line 1", "Line 2", "Line 3", "End" }, lines);
}
}
@@ -0,0 +1,19 @@
using Elsa.Workflows.Activities;
namespace Elsa.Workflows.IntegrationTests.Activities;
class SequentialWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = new Sequence
{
Activities =
{
new WriteLine("Line 1"),
new WriteLine("Line 2"),
new WriteLine("Line 3")
}
};
}
}
@@ -0,0 +1,30 @@
using Elsa.Testing.Shared;
using Elsa.Workflows.Activities;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Activities;
public class WriteLineTests
{
private readonly IWorkflowRunner _workflowRunner;
private readonly CapturingTextWriter _capturingTextWriter = new();
private readonly IServiceProvider _services;
public WriteLineTests(ITestOutputHelper testOutputHelper)
{
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Run a simple workflow")]
public async Task Test1()
{
var expectedOutput = "Hello World!";
var workflow = Workflow.FromActivity(new WriteLine(expectedOutput));
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync(workflow);
var line = _capturingTextWriter.Lines.FirstOrDefault();
Assert.Equal(expectedOutput, line);
}
}