Add project files.
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Elsa.Extensions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.JsonObjectToObjectRemainsJsonObject.Activities;
|
||||
|
||||
public class JsonObjectProducer : CodeActivity<JsonObject>
|
||||
{
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
{
|
||||
var value = new JsonObject
|
||||
{
|
||||
["Foo"] = new JsonObject
|
||||
{
|
||||
["Bar"] = "Baz"
|
||||
}
|
||||
};
|
||||
|
||||
context.SetResult(value);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Models;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.JsonObjectToObjectRemainsJsonObject.Activities;
|
||||
|
||||
public class ObjectProcessor : CodeActivity<object>
|
||||
{
|
||||
public Input<object> Value { get; set; } = default!;
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
{
|
||||
var value = Value.Get(context);
|
||||
context.SetResult(value);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using Elsa.Testing.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.JsonObjectToObjectRemainsJsonObject;
|
||||
|
||||
public class JsonObjectJintTests
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public JsonObjectJintTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_services.GetRequiredService<IWorkflowBuilderFactory>();
|
||||
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "The produced JsonObject remains JsonObject and does not become JsonElement (which does not support index notation)")]
|
||||
public async Task Test1()
|
||||
{
|
||||
await _services.PopulateRegistriesAsync();
|
||||
await _workflowRunner.RunAsync<Workflows.TestWorkflow>();
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(new[] { "Baz" }, lines);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.JavaScript.Models;
|
||||
using Elsa.Workflows.Activities;
|
||||
using Elsa.Workflows.IntegrationTests.Scenarios.JsonObjectToObjectRemainsJsonObject.Activities;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.JsonObjectToObjectRemainsJsonObject.Workflows;
|
||||
|
||||
public class TestWorkflow : WorkflowBase
|
||||
{
|
||||
protected override void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
var item = builder.WithVariable<JsonObject>("item", default!);
|
||||
|
||||
builder.Root = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new JsonObjectProducer
|
||||
{
|
||||
Result = new(item)
|
||||
},
|
||||
new ObjectProcessor
|
||||
{
|
||||
Value = new(JavaScriptExpression.Create("getItem()"), new MemoryBlockReference()),
|
||||
Result = new(item)
|
||||
},
|
||||
new WriteLine(JavaScriptExpression.Create("getItem()['Foo']['Bar']"))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user