Add project files.
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Memory;
|
||||
using Elsa.Workflows.Models;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Serialization.VariableExpressions;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class NumberActivity : CodeActivity
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[JsonConstructor]
|
||||
public NumberActivity()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public NumberActivity(Variable<int> variable)
|
||||
{
|
||||
Number = new(variable);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public NumberActivity(Literal<int> literal)
|
||||
{
|
||||
Number = new(literal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number.
|
||||
/// </summary>
|
||||
public Input<int> Number { get; set; } = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
{
|
||||
var number = Number.Get(context);
|
||||
Console.WriteLine(number.ToString());
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Testing.Shared;
|
||||
using Elsa.Workflows.Activities;
|
||||
using Elsa.Workflows.Management;
|
||||
using Elsa.Workflows.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Serialization.VariableExpressions;
|
||||
|
||||
/// <summary>
|
||||
/// Contains tests for variable expressions serialization.
|
||||
/// </summary>
|
||||
public class Tests
|
||||
{
|
||||
private readonly IWorkflowSerializer _workflowSerializer;
|
||||
private readonly IWorkflowBuilder _workflowBuilder;
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Tests"/> class.
|
||||
/// </summary>
|
||||
public Tests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var serviceProvider = new TestApplicationBuilder(testOutputHelper).Build();
|
||||
_workflowSerializer = serviceProvider.GetRequiredService<IWorkflowSerializer>();
|
||||
IWorkflowBuilderFactory workflowBuilderFactory = serviceProvider.GetRequiredService<IWorkflowBuilderFactory>();
|
||||
_workflowBuilder = workflowBuilderFactory.CreateBuilder();
|
||||
_workflowRunner = serviceProvider.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Variable types remain intact after serialization.
|
||||
/// </summary>
|
||||
[Fact(DisplayName = "Variable types remain intact after serialization")]
|
||||
public async Task Test1()
|
||||
{
|
||||
var workflow = await _workflowBuilder.BuildWorkflowAsync<SampleWorkflow>();
|
||||
var serialized = _workflowSerializer.Serialize(workflow);
|
||||
var deserializedWorkflow = _workflowSerializer.Deserialize(serialized);
|
||||
var rehydratedWriteLine1 = (WriteLine)((Sequence)deserializedWorkflow.Root).Activities.ElementAt(0);
|
||||
var rehydratedNumberActivity1 = (NumberActivity)((Sequence)deserializedWorkflow.Root).Activities.ElementAt(2);
|
||||
|
||||
Assert.IsType<Variable<string>>(rehydratedWriteLine1.Text.Expression!.Value);
|
||||
Assert.IsType<Variable<int>>(rehydratedNumberActivity1.Number.Expression!.Value);
|
||||
|
||||
await _workflowRunner.RunAsync(workflow);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.Workflows.Activities;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Serialization.VariableExpressions;
|
||||
|
||||
class SampleWorkflow : WorkflowBase
|
||||
{
|
||||
protected override void Build(IWorkflowBuilder workflow)
|
||||
{
|
||||
var variable1 = workflow.WithVariable("Some variable");
|
||||
var variable2 = workflow.WithVariable(42);
|
||||
var literal1 = new Literal<string>("Some literal");
|
||||
var literal2 = new Literal<int>(84);
|
||||
var writeLine1 = new WriteLine(variable1);
|
||||
var writeLine2 = new WriteLine(literal1);
|
||||
var numberActivity1 = new NumberActivity(variable2);
|
||||
var numberActivity2 = new NumberActivity(literal2);
|
||||
|
||||
workflow.Root = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
writeLine1,
|
||||
writeLine2,
|
||||
numberActivity1,
|
||||
numberActivity2
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user