Add project files.
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Activities;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.ActivityOutputs;
|
||||
|
||||
public class LoopingWorkflow : WorkflowBase
|
||||
{
|
||||
protected override void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
var readCurrentValue = new Inline<string>(context => context.GetVariable<string>("CurrentValue")!);
|
||||
|
||||
builder.Root = new ForEach<string>(
|
||||
[
|
||||
"Item 1",
|
||||
"Item 2",
|
||||
"Item 3"
|
||||
])
|
||||
{
|
||||
Body = new Sequence
|
||||
{
|
||||
Activities =
|
||||
[
|
||||
readCurrentValue,
|
||||
new WriteLine(context =>
|
||||
{
|
||||
var currentValue = context.GetVariable<string>("CurrentValue");
|
||||
var activityResult = context.GetActivityExecutionContext().GetResult(readCurrentValue);
|
||||
return $"Current value: {currentValue}, Activity result: {activityResult}";
|
||||
})
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Memory;
|
||||
using Elsa.Workflows.Models;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.ActivityOutputs;
|
||||
|
||||
public class SumActivity : CodeActivity<int>
|
||||
{
|
||||
public SumActivity(Variable<int> a, Variable<int> b)
|
||||
{
|
||||
A = new(a);
|
||||
B = new(b);
|
||||
}
|
||||
|
||||
public Input<int> A { get; set; }
|
||||
public Input<int> B { get; set; }
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
{
|
||||
var input1 = A.Get(context);
|
||||
var input2 = B.Get(context);
|
||||
var result = input1 + input2;
|
||||
|
||||
// All three work.
|
||||
Result.Set(context, result);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Activities;
|
||||
using Elsa.Workflows.Memory;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.ActivityOutputs;
|
||||
|
||||
public class SumWorkflow : WorkflowBase
|
||||
{
|
||||
protected override void Build(IWorkflowBuilder workflow)
|
||||
{
|
||||
var a = new Variable<int>("A", 0);
|
||||
var b = new Variable<int>("B", 0);
|
||||
|
||||
var sumActivity = new SumActivity(a, b);
|
||||
|
||||
workflow.Root = new Sequence
|
||||
{
|
||||
Variables = { a, b },
|
||||
Activities =
|
||||
{
|
||||
new Inline(context => a.Set(context, 4)),
|
||||
new Inline(context => b.Set(context, 6)),
|
||||
sumActivity,
|
||||
new WriteLine(context => $"The result of {a.Get(context)} and {b.Get(context)} is {sumActivity.GetResult<int>(context)}."),
|
||||
new WriteLine(context => $"The last result is {context.GetLastResult<int>()}."),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Elsa.Testing.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.ActivityOutputs;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public Tests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "Activity outputs can be accessed from other activities.")]
|
||||
public async Task Test1()
|
||||
{
|
||||
await _services.PopulateRegistriesAsync();
|
||||
await _workflowRunner.RunAsync<SumWorkflow>();
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(new[]
|
||||
{
|
||||
"The result of 4 and 6 is 10.", "The last result is 10."
|
||||
}, lines);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "The last activity output is returned.")]
|
||||
public async Task Test2()
|
||||
{
|
||||
await _services.PopulateRegistriesAsync();
|
||||
await _workflowRunner.RunAsync<LoopingWorkflow>();
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(new[]
|
||||
{
|
||||
"Current value: Item 1, Activity result: Item 1",
|
||||
"Current value: Item 2, Activity result: Item 2",
|
||||
"Current value: Item 3, Activity result: Item 3"
|
||||
}, lines);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user