elsa-core/test/integration/Elsa.Activities.IntegrationTests/Flow/EndTests.cs
Sipke Schoorstra 87dc976b5f
Add integration and unit tests for End activity and update flowchart termination logic (#7109)
- Introduced `EndInFlowchartWorkflow` and `EndInSequenceWorkflow` to test `End` activity behavior in flowcharts and sequences.
- Added `EndTests` integration and unit tests to verify correct termination behavior, including `ITerminalNode` implementation.
- Updated flowchart logic to handle terminal nodes, ensuring immediate flowchart completion upon encountering `End`.
2025-11-26 12:26:04 +01:00

49 lines
1.8 KiB
C#

using Elsa.Activities.IntegrationTests.Flow.Workflows;
using Elsa.Testing.Shared;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Xunit.Abstractions;
namespace Elsa.Activities.IntegrationTests.Flow;
/// <summary>
/// Integration tests for the <see cref="End"/> activity.
/// </summary>
public class EndTests(ITestOutputHelper testOutputHelper)
{
private readonly WorkflowTestFixture _fixture = new WorkflowTestFixture(testOutputHelper)
.AddWorkflow<EndInSequenceWorkflow>()
.AddWorkflow<EndInFlowchartWorkflow>();
[Fact(DisplayName = "End terminates sequence execution")]
public async Task End_TerminatesSequenceExecution()
{
// Act
var workflowState = await _fixture.RunWorkflowAsync(EndInSequenceWorkflow.DefinitionId);
// Assert
Assert.Equal(WorkflowStatus.Finished, workflowState.Status);
var lines = _fixture.CapturingTextWriter.Lines.ToList();
Assert.Contains("Before End", lines);
Assert.DoesNotContain("After End", lines);
}
[Fact(DisplayName = "End in flowchart terminates flowchart immediately")]
public async Task End_InFlowchart_TerminatesFlowchartImmediately()
{
// Act
var workflowState = await _fixture.RunWorkflowAsync(EndInFlowchartWorkflow.DefinitionId);
// Assert
Assert.Equal(WorkflowStatus.Finished, workflowState.Status);
var lines = _fixture.CapturingTextWriter.Lines.ToList();
Assert.Contains("Start", lines);
Assert.Contains("Path A executed", lines);
// End is a terminal node - it terminates the flowchart immediately
// Path B should not execute because End completes the flowchart
Assert.DoesNotContain("Path B executed", lines);
// The outer sequence continues after the flowchart completes
Assert.Contains("After flowchart", lines);
}
}