-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add integration tests for enumerables with projection to arrays #7290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...IntegrationTests/Scenarios/ProjectedEnumerableToArray/EnumerableProjectionTestWorkflow.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using Elsa.Expressions.JavaScript.Activities; | ||
| using Elsa.Extensions; | ||
| using Elsa.Workflows.Activities; | ||
| using Elsa.Workflows.Memory; | ||
|
|
||
| namespace Elsa.Workflows.IntegrationTests.Scenarios.ProjectedEnumerableToArray; | ||
|
|
||
| /// <summary> | ||
| /// Code-first workflow that reproduces the "projected IEnumerable to array" scenario end-to-end. | ||
| /// </summary> | ||
| public class EnumerableProjectionTestWorkflow : WorkflowBase | ||
| { | ||
| protected override void Build(IWorkflowBuilder workflow) | ||
| { | ||
| // Store in workflow instance state to mimic real execution behavior. | ||
| var messagesVar = new Variable<object>("Messages", Array.Empty<string>()).WithWorkflowStorage(); | ||
|
|
||
| workflow.WithVariables(messagesVar); | ||
|
|
||
| workflow.Root = new Sequence | ||
| { | ||
| Activities = | ||
| { | ||
| new TestEnumerableActivity | ||
| { | ||
| EnumerableResult = new(messagesVar) | ||
| }, | ||
|
|
||
| new RunJavaScript | ||
| { | ||
| // Accessing Messages through JS triggers the conversion logic. | ||
| Script = new("return getMessages();"), | ||
| Result = new(messagesVar) | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...kflows.IntegrationTests/Scenarios/ProjectedEnumerableToArray/EnumerableProjectionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using Elsa.Expressions.Helpers; | ||
| using Elsa.Testing.Shared; | ||
| using Elsa.Workflows.Management; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Elsa.Workflows.IntegrationTests.Scenarios.ProjectedEnumerableToArray; | ||
|
|
||
| public class EnumerableProjectionTests(ITestOutputHelper testOutputHelper) | ||
| { | ||
| private readonly WorkflowTestFixture _fixture = new(testOutputHelper); | ||
|
|
||
| [Fact(DisplayName = "JavaScript should convert a Select-projected IEnumerable variable to an array")] | ||
| public async Task Should_Convert_Select_Projected_Enumerable_To_Array() | ||
| { | ||
| // Arrange | ||
| var workflow = new EnumerableProjectionTestWorkflow(); | ||
|
|
||
| // Act | ||
| var result = await _fixture.RunWorkflowAsync(workflow); | ||
|
|
||
| // Assert | ||
| Assert.Equal(WorkflowSubStatus.Finished, result.WorkflowState.SubStatus); // If conversion failed, workflow will have faulted. | ||
| var variableManager = _fixture.Services.GetRequiredService<IWorkflowInstanceVariableManager>(); | ||
| var messagesVariable = (await variableManager.GetVariablesAsync(result.WorkflowExecutionContext)).FirstOrDefault(x => x.Variable.Name == "Messages"); | ||
| var messages = messagesVariable?.Value.ConvertTo<string[]>(); | ||
|
|
||
| Assert.NotNull(messages); | ||
| Assert.Equal(5, messages.Length); | ||
|
|
||
| Assert.All(messages, message => | ||
| { | ||
| Assert.Contains("Name:", message); | ||
| Assert.Contains("ID:", message); | ||
| }); | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
...Workflows.IntegrationTests/Scenarios/ProjectedEnumerableToArray/TestEnumerableActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using Elsa.Workflows.Models; | ||
|
|
||
| namespace Elsa.Workflows.IntegrationTests.Scenarios.ProjectedEnumerableToArray; | ||
|
|
||
| /// <summary> | ||
| /// A test activity that produces an IEnumerable<string> via Select projection, which has two generic arguments and was triggering the bug in ConvertIEnumerableToArray. | ||
| /// </summary> | ||
| public class TestEnumerableActivity : Activity | ||
| { | ||
| public Output<object?> EnumerableResult { get; set; } = new(); | ||
|
|
||
| protected override ValueTask ExecuteAsync(ActivityExecutionContext context) | ||
| { | ||
| // Create a list of items | ||
| var items = Enumerable | ||
| .Range(1, 5) | ||
| .Select(x => new TestOutputItem()) | ||
| .ToList(); | ||
|
|
||
| // Use Select to project to strings - this creates a ListSelectIterator<TestOutputItem, string> | ||
| // which has TWO generic arguments, triggering the bug | ||
| var messages = items.Select(e => $"Name: {e.Name} ID: {e.Id}"); | ||
|
|
||
| context.Set(EnumerableResult, messages); | ||
| return context.CompleteActivityWithOutcomesAsync("Done"); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...on/Elsa.Workflows.IntegrationTests/Scenarios/ProjectedEnumerableToArray/TestOutputItem.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace Elsa.Workflows.IntegrationTests.Scenarios.ProjectedEnumerableToArray; | ||
|
|
||
| public class TestOutputItem | ||
| { | ||
| public string Name { get; } = Guid.NewGuid().ToString(); | ||
| public string Id { get; } = Guid.NewGuid().ToString(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.