Move IWorkflow to Core and update tests
This commit is contained in:
parent
e8ba302500
commit
7bd4df2532
|
|
@ -72,4 +72,11 @@ public class WorkflowDefinitionBuilder : IWorkflowDefinitionBuilder
|
|||
var metadata = new WorkflowMetadata();
|
||||
return new Workflow(identity, publication, metadata, root, Variables, Metadata, ApplicationProperties);
|
||||
}
|
||||
|
||||
public Workflow BuildWorkflow(IWorkflow workflowDefinition)
|
||||
{
|
||||
WithDefinitionId(workflowDefinition.GetType().Name);
|
||||
workflowDefinition.Build(this);
|
||||
return BuildWorkflow();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using Elsa.Contracts;
|
||||
|
||||
namespace Elsa.Runtime.Contracts;
|
||||
namespace Elsa.Contracts;
|
||||
|
||||
public interface IWorkflow
|
||||
{
|
||||
|
|
@ -9,11 +9,11 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dahomey.Json" Version="1.12.2"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0"/>
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="6.0.0-preview.4.21253.7"/>
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.2"/>
|
||||
<PackageReference Include="Dahomey.Json" Version="1.12.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="6.0.0-preview.4.21253.7" />
|
||||
<PackageReference Include="System.Text.Json" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- <ItemGroup>-->
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Elsa.Contracts;
|
||||
using Elsa.Runtime.Contracts;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Elsa.Contracts;
|
||||
using Elsa.Runtime.Contracts;
|
||||
using Elsa.Runtime.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
|
|||
60
test/Elsa.IntegrationTests/Workflows/ForEachWorkflowTests.cs
Normal file
60
test/Elsa.IntegrationTests/Workflows/ForEachWorkflowTests.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Elsa.Activities;
|
||||
using Elsa.Builders;
|
||||
using Elsa.Contracts;
|
||||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
using Elsa.Testing.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.IntegrationTests.Workflows;
|
||||
|
||||
public class ForEachWorkflowTests
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
private readonly Workflow _workflow;
|
||||
|
||||
public ForEachWorkflowTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var services = new TestContainerBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
||||
_workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new ForEachWorkflow());
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "ForEach outputs each iteration")]
|
||||
public async Task Test1()
|
||||
{
|
||||
await _workflowRunner.RunAsync(_workflow);
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal("C#", lines[0]);
|
||||
Assert.Equal("Rust", lines[1]);
|
||||
Assert.Equal("Go", lines[2]);
|
||||
}
|
||||
|
||||
private class ForEachWorkflow : IWorkflow
|
||||
{
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
var items = new[] { "C#", "Rust", "Go" };
|
||||
var currentItem = new Variable<string>();
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new ForEach<string>
|
||||
{
|
||||
Items = new Input<ICollection<string>>(items),
|
||||
CurrentValue = currentItem,
|
||||
Body = new WriteLine(context => currentItem.Get(context))
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,6 @@ using System.Threading.Tasks;
|
|||
using Elsa.Contracts;
|
||||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
using Elsa.Modules.Activities.Contracts;
|
||||
using Elsa.Modules.Activities.Providers;
|
||||
using Elsa.Testing.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
|
@ -19,11 +17,10 @@ public class HelloWorldWorkflowTests
|
|||
|
||||
public HelloWorldWorkflowTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var combinedTextWriter = new CombinedTextWriter(_capturingTextWriter, new XunitConsoleTextWriter(testOutputHelper));
|
||||
var services = TestContainerBuilder.Build(testOutputHelper, x => x.AddSingleton<IStandardOutStreamProvider>(new StandardOutStreamProvider(combinedTextWriter)));
|
||||
var services = new TestContainerBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
|
||||
[Fact(DisplayName = "Run a simple workflow")]
|
||||
public async Task Test1()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,20 +11,34 @@ namespace Elsa.Testing.Shared;
|
|||
|
||||
public class TestContainerBuilder
|
||||
{
|
||||
public static IServiceProvider Build(ITestOutputHelper testOutputHelper, Action<IServiceCollection>? configureServices = default)
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
private readonly ITestOutputHelper _testOutputHelper;
|
||||
private readonly ServiceCollection _services;
|
||||
|
||||
services
|
||||
public TestContainerBuilder(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
_testOutputHelper = testOutputHelper;
|
||||
_services = new ServiceCollection();
|
||||
|
||||
_services
|
||||
.AddElsa()
|
||||
.AddInMemoryPersistence()
|
||||
.AddSingleton(testOutputHelper)
|
||||
.AddSingleton<IStandardOutStreamProvider>(new StandardOutStreamProvider(new XunitConsoleTextWriter(testOutputHelper)))
|
||||
.AddLogging(logging => logging.AddProvider(new XunitLoggerProvider(testOutputHelper)).SetMinimumLevel(LogLevel.Debug));
|
||||
}
|
||||
|
||||
services.AddSingleton(testOutputHelper);
|
||||
services.AddSingleton<IStandardOutStreamProvider>(new StandardOutStreamProvider(new XunitConsoleTextWriter(testOutputHelper)));
|
||||
|
||||
configureServices?.Invoke(services);
|
||||
public IServiceProvider Build() => _services.BuildServiceProvider();
|
||||
|
||||
return services.BuildServiceProvider();
|
||||
public TestContainerBuilder Configure(Action<IServiceCollection> configure)
|
||||
{
|
||||
configure(_services);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestContainerBuilder WithCapturingTextWriter(CapturingTextWriter capturingTextWriter)
|
||||
{
|
||||
var combinedTextWriter = new CombinedTextWriter(capturingTextWriter, new XunitConsoleTextWriter(_testOutputHelper));
|
||||
_services.AddSingleton<IStandardOutStreamProvider>(new StandardOutStreamProvider(combinedTextWriter));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue