* Remove unused using directives in test classes The using directives for System, System.Collections.Generic, System.IO, and others were not necessary in many of the test classes. These unused directives have been removed to enhance code readability and maintainability. * Update source port retrieval in ConnectionJsonConverter The source port retrieval code in ConnectionJsonConverter.cs has been updated. It now uses TryGetProperty instead of GetProperty, enabling it to handle cases where the "port" property may not exist. This enhances error handling and resilience in the activities module. * Refactor InputJsonConverter for proper variable expressions handling The InputJsonConverter in the Elsa.Workflows.Serialization has been expanded for efficient handling of variable expressions during the JSON conversion process. The refactor ensures appropriate extraction and assignment of values to variables. This adds robustness to the serialization process, maintaining variable types after serialization. * Add tests for variable expressions serialization A new `Tests.cs` file has been added under the `Elsa.IntegrationTests/Serialization/VariableExpressions` directory. This file contains tests for ensuring the serialization of variable expressions works correctly. A corresponding `SampleWorkflow` file has also been established, providing the workflows to be used in the tests. * Refactor workflow builder extension class The WorkflowDefinitionBuilderExtensions class has been deleted and replaced with WorkflowBuilderExtensions in Elsa.Workflows.Core. This new class retains similar functionality but includes more detailed comments and dynamic member access capabilities in its method definition.
85 lines
3.3 KiB
C#
85 lines
3.3 KiB
C#
using Elsa.Testing.Shared;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Elsa.IntegrationTests.Scenarios.ParentChildOutputMapping;
|
|
|
|
/// <summary>
|
|
/// Tests for mapping an activity's output directly to the workflow's output definition.
|
|
/// </summary>
|
|
public class Tests
|
|
{
|
|
private readonly CapturingTextWriter _capturingTextWriter = new();
|
|
private readonly IServiceProvider _services;
|
|
|
|
public Tests(ITestOutputHelper testOutputHelper)
|
|
{
|
|
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
|
}
|
|
|
|
[Fact(DisplayName = "Parent workflow receives output from child workflow.")]
|
|
public async Task Test1()
|
|
{
|
|
// Populate registries.
|
|
await _services.PopulateRegistriesAsync();
|
|
|
|
// Import child workflow.
|
|
var sumFileName = "Scenarios/ParentChildOutputMapping/Workflows/sum.json";
|
|
await _services.ImportWorkflowDefinitionAsync(sumFileName);
|
|
|
|
// Import parent workflow.
|
|
var calculatorFileName = "Scenarios/ParentChildOutputMapping/Workflows/calculator.json";
|
|
var workflowDefinition = await _services.ImportWorkflowDefinitionAsync(calculatorFileName);
|
|
|
|
// Execute.
|
|
await _services.RunWorkflowUntilEndAsync(workflowDefinition.DefinitionId);
|
|
|
|
// Assert expected output.
|
|
var lines = _capturingTextWriter.Lines.ToList();
|
|
Assert.Equal(new[] { "Result: 9" }, lines);
|
|
}
|
|
|
|
[Fact(DisplayName = "Multiple parent/child workflows receive output from child workflows even when using same output names.")]
|
|
public async Task Test2()
|
|
{
|
|
// Populate registries.
|
|
await _services.PopulateRegistriesAsync();
|
|
|
|
// Import workflows.
|
|
await _services.ImportWorkflowDefinitionAsync("Scenarios/ParentChildOutputMapping/Workflows/a.json");
|
|
await _services.ImportWorkflowDefinitionAsync("Scenarios/ParentChildOutputMapping/Workflows/b.json");
|
|
await _services.ImportWorkflowDefinitionAsync("Scenarios/ParentChildOutputMapping/Workflows/c.json");
|
|
|
|
// Import root workflow.
|
|
var workflowDefinition = await _services.ImportWorkflowDefinitionAsync("Scenarios/ParentChildOutputMapping/Workflows/d.json");
|
|
|
|
// Execute.
|
|
await _services.RunWorkflowUntilEndAsync(workflowDefinition.DefinitionId);
|
|
|
|
// Assert expected output.
|
|
var lines = _capturingTextWriter.Lines.ToList();
|
|
Assert.Equal(new[] { "FooBar" }, lines);
|
|
}
|
|
|
|
[Fact(DisplayName = "Parent workflow receives output from child workflow when using SetOutput activity.")]
|
|
public async Task Test3()
|
|
{
|
|
// Populate registries.
|
|
await _services.PopulateRegistriesAsync();
|
|
|
|
// Import child workflow.
|
|
var producerFileName = "Scenarios/ParentChildOutputMapping/Workflows/producer.json";
|
|
await _services.ImportWorkflowDefinitionAsync(producerFileName);
|
|
|
|
// Import parent workflow.
|
|
var consumerFileName = "Scenarios/ParentChildOutputMapping/Workflows/consumer.json";
|
|
var workflowDefinition = await _services.ImportWorkflowDefinitionAsync(consumerFileName);
|
|
|
|
// Execute.
|
|
await _services.RunWorkflowUntilEndAsync(workflowDefinition.DefinitionId);
|
|
|
|
// Assert expected output.
|
|
var lines = _capturingTextWriter.Lines.ToList();
|
|
Assert.Equal(new[] { "Foo" }, lines);
|
|
}
|
|
} |