Add project files.

This commit is contained in:
2025-08-18 17:11:43 +03:30
parent 807dc263be
commit e5eb10d604
3943 changed files with 223719 additions and 0 deletions
@@ -0,0 +1,50 @@
using Elsa.Testing.Shared;
using Microsoft.Extensions.DependencyInjection;
using Xunit.Abstractions;
namespace Elsa.Workflows.IntegrationTests.Scenarios.SetGetVariables;
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();
_services.GetRequiredService<IWorkflowBuilderFactory>();
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Workflow can set variable")]
public async Task Test1()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<SetGetVariableWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Line 5" }, lines);
}
[Fact(DisplayName = "Workflow can reference variables set in previous activities")]
public async Task Test2()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<SetGetVariablesWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Variable 2: The value of variable 1" }, lines);
}
[Fact(DisplayName = "Workflow can set and get named variables")]
public async Task Test3()
{
await _services.PopulateRegistriesAsync();
await _workflowRunner.RunAsync<SetGetNamedVariableWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[]
{
"Foo = Bar",
"Foo = Baz"
}, lines);
}
}
@@ -0,0 +1,74 @@
using Elsa.Extensions;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Memory;
namespace Elsa.Workflows.IntegrationTests.Scenarios.SetGetVariables;
class SetGetVariableWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var variable1 = new Variable<string>("Variable1", "");
workflow.Root = new Sequence
{
Variables =
{
variable1
},
Activities =
{
new SetVariable<string>(variable1, "Line 5"),
new WriteLine(variable1)
}
};
}
}
class SetGetVariablesWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var variable1 = new Variable<string>("Variable1", "");
var variable2 = new Variable<string>("Variable2", "");
workflow.Root = new Sequence
{
Variables = { variable1, variable2 },
Activities =
{
new SetVariable
{
Variable = variable1,
Value = new("The value of variable 1")
},
new SetVariable
{
Variable = variable2,
Value = new(variable1)
},
new WriteLine(context => $"Variable 2: {variable2.Get(context)}")
}
};
}
}
class SetGetNamedVariableWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
workflow.Root = new Sequence
{
Variables = { new Variable<string>("Foo", "Bar") },
Activities =
{
new WriteLine(context => $"Foo = {context.GetVariable<string>("Foo")}"),
Inline.From(context => context.SetVariable("Foo", "Baz")),
new WriteLine(context => $"Foo = {context.GetVariable<string>("Foo")}"),
}
};
}
}