elsa-core/test/unit/Elsa.Activities.UnitTests/Primitives/CorrelateTests.cs
Sipke Schoorstra e3a8e533c8
Add unit tests for Correlate activity and enhance ActivityTestFixture execution functionality (#7119)
* Add unit tests for `Correlate` activity and enhance `ActivityTestFixture` execution functionality

- Introduced `CorrelateTests` to validate correlation ID handling with string literals, inputs, and functions.
- Extended `ActivityTestFixture` with new `ExecuteAsync(ActivityExecutionContext)` overload for improved test execution customization.

* Update src/common/Elsa.Testing.Shared/ActivityTestFixture.cs

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

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-27 20:57:48 +01:00

55 lines
1.7 KiB
C#

using Elsa.Testing.Shared;
namespace Elsa.Activities.UnitTests.Primitives;
public class CorrelateTests
{
[Fact]
public async Task Should_Set_CorrelationId_From_String_Literal()
{
const string expected = "test-correlation-id";
var correlate = new Correlate(expected, null, null);
await AssertCorrelationIdAsync(correlate, expected);
}
[Fact]
public async Task Should_Set_CorrelationId_From_Input()
{
const string expected = "dynamic-correlation-id";
var correlate = new Correlate { CorrelationId = new(expected) };
await AssertCorrelationIdAsync(correlate, expected);
}
[Fact]
public async Task Should_Set_CorrelationId_From_Func()
{
const string expected = "func-correlation-id";
var correlate = new Correlate(_ => expected);
await AssertCorrelationIdAsync(correlate, expected);
}
[Fact]
public async Task Should_Overwrite_Existing_CorrelationId()
{
const string initial = "initial-correlation-id";
const string expected = "updated-correlation-id";
var correlate = new Correlate(expected, null, null);
var fixture = new ActivityTestFixture(correlate);
var context = await fixture.BuildAsync();
context.WorkflowExecutionContext.CorrelationId = initial;
await fixture.ExecuteAsync(context);
Assert.Equal(expected, context.WorkflowExecutionContext.CorrelationId);
}
private static async Task AssertCorrelationIdAsync(Correlate correlate, string expected)
{
var context = await new ActivityTestFixture(correlate).ExecuteAsync();
Assert.Equal(expected, context.WorkflowExecutionContext.CorrelationId);
}
}