Add project files.
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
using Elsa.Expressions.Models;
|
||||
using Elsa.JavaScript.Activities;
|
||||
using Elsa.Workflows.Activities;
|
||||
using Elsa.Workflows.Memory;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.HttpRequestWithLiquid;
|
||||
|
||||
/// <summary>
|
||||
/// A workflow that use javascript to get some data, use them with some liquid expressions
|
||||
/// </summary>
|
||||
public class JavascriptAndLiquidWorkflow : WorkflowBase
|
||||
{
|
||||
protected override void Build(IWorkflowBuilder builder)
|
||||
{
|
||||
var products = new Variable<object>("Products", null!).WithStorageDriver<WorkflowInstanceStorageDriver>();
|
||||
var product = new Variable<object>("Product", null!).WithStorageDriver<WorkflowInstanceStorageDriver>();
|
||||
|
||||
builder.Root = new Sequence
|
||||
{
|
||||
Variables = { products, product },
|
||||
Activities =
|
||||
{
|
||||
new RunJavaScript
|
||||
{
|
||||
Script = new(@"setProducts([{""id"":1, ""price"":12.99}, {""id"":2, ""price"":10}, {""id"":3, ""price"":1}])")
|
||||
},
|
||||
new WriteLine(new Expression("Liquid", "First product id: {{ Variables.Products[0].id }}")),
|
||||
new WriteLine(new Expression("Liquid", "First product price rounded: {{ Variables.Products[0].price | round }}")),
|
||||
new WriteLine(new Expression("Liquid", "First product as json: {{ Variables.Products[0] | json }}")),
|
||||
new WriteLine(new Expression("Liquid", "Second product id: {{ Variables.Products[1].id }}")),
|
||||
new RunJavaScript
|
||||
{
|
||||
Script = new(@"variables.Product = {""id"":2, ""price"":10}")
|
||||
},
|
||||
new WriteLine(new Expression("Liquid", "Single product id: {{ Variables.Product.id }}")),
|
||||
new WriteLine(new Expression("Liquid", "Single product as json: {{ Variables.Product | json }}")),
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Testing.Shared;
|
||||
using Elsa.Workflows.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Scenarios.HttpRequestWithLiquid;
|
||||
|
||||
public sealed class Tests : IDisposable
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public Tests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_services = new TestApplicationBuilder(testOutputHelper)
|
||||
.WithCapturingTextWriter(_capturingTextWriter)
|
||||
.ConfigureElsa(configure => configure.UseHttp())
|
||||
.Build();
|
||||
_workflowRunner = _services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetProducts()
|
||||
{
|
||||
await _services.PopulateRegistriesAsync();
|
||||
RunWorkflowResult result = await _workflowRunner.RunAsync(new JavascriptAndLiquidWorkflow());
|
||||
Assert.Equal(WorkflowStatus.Finished, result.WorkflowState.Status);
|
||||
Assert.Empty(result.WorkflowState.Incidents);
|
||||
Assert.Equal(WorkflowSubStatus.Finished, result.WorkflowState.SubStatus);
|
||||
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Contains("First product id: 1", lines);
|
||||
Assert.Contains("First product price rounded: 13", lines);
|
||||
Assert.Contains("First product as json: {\"id\":1,\"price\":12.99}", lines);
|
||||
Assert.Contains("Second product id: 2", lines);
|
||||
|
||||
Assert.Contains("Single product id: 2", lines);
|
||||
Assert.Contains("Single product as json: {\"id\":2,\"price\":10}", lines);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_capturingTextWriter.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user