Fix tests, remove named variables

Only reference variables by C# reference or reference ID
This commit is contained in:
Sipke Schoorstra 2023-07-03 21:31:03 +02:00
parent 7224d19272
commit 466c4b922e
3 changed files with 26 additions and 22 deletions

View file

@ -21,10 +21,10 @@ public class Tests
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Subsequent activity does not get scheduled when previous activity created a bookmark")]
[Fact(DisplayName = "Workflow can set variable")]
public async Task Test1()
{
await _workflowRunner.RunAsync<SetGetVariablesWorkflow>();
await _workflowRunner.RunAsync<SetGetVariableWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Line 5" }, lines);
}
@ -32,8 +32,8 @@ public class Tests
[Fact(DisplayName = "Workflow can reference variables set in previous activities")]
public async Task Test2()
{
await _workflowRunner.RunAsync<SetGetNamedVariablesWorkflow>();
await _workflowRunner.RunAsync<SetGetVariablesWorkflow>();
var lines = _capturingTextWriter.Lines.ToList();
Assert.Equal(new[] { "Other variable: Some value" }, lines);
Assert.Equal(new[] { "Variable 2: The value of variable 1" }, lines);
}
}

View file

@ -1,4 +1,3 @@
using Elsa.Extensions;
using Elsa.Workflows.Core.Abstractions;
using Elsa.Workflows.Core.Activities;
using Elsa.Workflows.Core.Contracts;
@ -6,46 +5,51 @@ using Elsa.Workflows.Core.Models;
namespace Elsa.IntegrationTests.Scenarios.SetGetVariables;
class SetGetVariablesWorkflow : WorkflowBase
class SetGetVariableWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var variable = new Variable<string>("test");
var variable1 = new Variable<string>();
workflow.Root = new Sequence
{
Variables = {
variable
variable1
},
Activities =
{
new SetVariable<string>(variable,"Line 5"),
new WriteLine(variable)
new SetVariable<string>(variable1,"Line 5"),
new WriteLine(variable1)
}
};
}
}
class SetGetNamedVariablesWorkflow : WorkflowBase
class SetGetVariablesWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
var variable1 = new Variable<string>();
var variable2 = new Variable<string>();
workflow.Root = new Sequence
{
Variables = { variable1, variable2 },
Activities =
{
new SetVariable()
new SetVariable
{
Variable = new Variable("MyVar"),
Value = new ("Some value")
Variable = variable1,
Value = new ("The value of variable 1")
},
new SetVariable()
{
Variable = new Variable("some_other_variable"),
Value = new Input<object?>(new Variable("MyVar"))
Variable = variable2,
Value = new Input<object?>(variable1)
},
new WriteLine(context => $"Other variable: {context.GetVariable<string>("MyVar")}")
new WriteLine(context => $"Variable 2: {variable2.Get(context)}")
}
};
}

View file

@ -20,24 +20,24 @@ public class Tests
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
}
[Fact(DisplayName = "Setting a named variable should be captured when the ResultVariable is set")]
[Fact(DisplayName = "Setting a variable should be captured when the ResultVariable is set")]
public async Task Test1()
{
var expectedValue = "Some value";
var variableName = "MyVar";
var variable1 = new Variable();
var workflow = Workflow.FromActivity(new Sequence
{
Activities =
{
new SetVariable()
new SetVariable
{
Variable = new (variableName),
Variable = variable1,
Value = new (expectedValue)
}
}
});
workflow.ResultVariable = new (variableName);
workflow.ResultVariable = variable1;
var runWorkflowResult = await _workflowRunner.RunAsync(workflow);
Assert.Equal(expectedValue, runWorkflowResult.Result);
}