elsa-core/test/unit/Elsa.Activities.UnitTests/Branching/FlowForkTests.cs
Sipke Schoorstra f7b7ea4d73
Add unit tests for FlowFork activity and enhance test utilities (#6995)
* Add unit tests for `FlowFork` activity and enhance test utilities

- Introduce `FlowForkTests` to validate activity behavior with various branch configurations.
- Extend `ActivityExecutionContextExtensions` with methods to retrieve and check outcomes.
- Modify `ActivityTestFixture` to ensure activities transition to `Running` status before execution.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-21 15:31:31 +02:00

41 lines
1.3 KiB
C#

using Elsa.Testing.Shared;
using Elsa.Workflows;
using Elsa.Workflows.Activities.Flowchart.Activities;
namespace Elsa.Activities.UnitTests.Branching;
public class FlowForkTests
{
[Theory]
[MemberData(nameof(BranchTestCases))]
public async Task Should_Complete_With_Specified_Branches(string[] branches, string[] expectedOutcomes)
{
// Arrange
var flowFork = new FlowFork();
if (branches.Length > 0)
flowFork.Branches = new(branches);
// Act
var context = await ExecuteAsync(flowFork);
// Assert - Activity should complete with all outcomes.
var outcomes = context.GetOutcomes().ToList();
Assert.Equal(expectedOutcomes.Length, outcomes.Count);
foreach (var expectedOutcome in expectedOutcomes)
Assert.Contains(expectedOutcome, outcomes);
}
public static IEnumerable<object[]> BranchTestCases()
{
yield return [Array.Empty<string>(), new[] { "Done" }];
yield return [new[] { "SingleBranch" }, new[] { "SingleBranch" }];
yield return [new[] { "Branch1", "Branch2", "Branch3" }, new[] { "Branch1", "Branch2", "Branch3" }];
}
private static Task<ActivityExecutionContext> ExecuteAsync(IActivity activity)
{
return new ActivityTestFixture(activity).ExecuteAsync();
}
}