diff --git a/test/Elsa.IntegrationTests/Break/BreakForEachWorkflow.cs b/test/Elsa.IntegrationTests/Break/BreakForEachWorkflow.cs new file mode 100644 index 000000000..e24a18fda --- /dev/null +++ b/test/Elsa.IntegrationTests/Break/BreakForEachWorkflow.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Models; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests; + +class BreakForEachWorkflow : IWorkflow +{ + public void Build(IWorkflowDefinitionBuilder workflow) + { + var items = new[] { "C#", "Rust", "Go" }; + var currentItem = new Variable(); + + workflow.WithRoot(new Sequence + { + Activities = + { + new WriteLine("Start"), + new ForEach + { + Items = new Input>(items), + CurrentValue = currentItem, + Body = new Sequence + { + Activities = + { + new If(context => currentItem.Get(context) == "Rust") + { + Then = new Break() + }, + new WriteLine(currentItem), + new WriteLine("Test") + } + } + }, + new WriteLine("End"), + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Break/BreakForWorkflow.cs b/test/Elsa.IntegrationTests/Break/BreakForWorkflow.cs new file mode 100644 index 000000000..7b6b08647 --- /dev/null +++ b/test/Elsa.IntegrationTests/Break/BreakForWorkflow.cs @@ -0,0 +1,38 @@ +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Models; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests; + +class BreakForWorkflow : IWorkflow +{ + public void Build(IWorkflowDefinitionBuilder workflow) + { + var currentValue = new Variable(); + + workflow.WithRoot(new Sequence + { + Activities = + { + new WriteLine("Start"), + new For(0, 3) + { + CurrentValue = currentValue, + Body = new Sequence + { + Activities = + { + new If(context => currentValue.Get(context) == 2) + { + Then = new Break() + }, + new WriteLine(context => currentValue.Get(context).ToString()), + } + } + }, + new WriteLine("End"), + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Break/BreakTests.cs b/test/Elsa.IntegrationTests/Break/BreakTests.cs new file mode 100644 index 000000000..f050c9777 --- /dev/null +++ b/test/Elsa.IntegrationTests/Break/BreakTests.cs @@ -0,0 +1,59 @@ +using System.Linq; +using System.Threading.Tasks; +using Elsa.Builders; +using Elsa.Contracts; +using Elsa.IntegrationTests.Workflows; +using Elsa.Testing.Shared; +using Microsoft.Extensions.DependencyInjection; +using Xunit; +using Xunit.Abstractions; + +namespace Elsa.IntegrationTests; + +public class BreakWorkflowTests +{ + private readonly IWorkflowRunner _workflowRunner; + private readonly CapturingTextWriter _capturingTextWriter = new(); + + public BreakWorkflowTests(ITestOutputHelper testOutputHelper) + { + var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build(); + _workflowRunner = services.GetRequiredService(); + } + + [Fact(DisplayName = "Break exits out of ForEach")] + public async Task Test1() + { + var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BreakForEachWorkflow()); + await _workflowRunner.RunAsync(workflow); + var lines = _capturingTextWriter.Lines.ToList(); + Assert.Equal(new[] { "Start", "C#", "Test", "End" }, lines); + } + + [Fact(DisplayName = "Break exits out of immediate ForEach only")] + public async Task Test2() + { + var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new NestedForEachWithBreakWorkflow()); + await _workflowRunner.RunAsync(workflow); + var lines = _capturingTextWriter.Lines.ToList(); + Assert.Equal(new[] { "C#", "Classes", "Rust", "Classes", "Go", "Classes" }, lines); + } + + [Fact(DisplayName = "Break exits out of For")] + public async Task Test3() + { + var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BreakForWorkflow()); + await _workflowRunner.RunAsync(workflow); + var lines = _capturingTextWriter.Lines.ToList(); + Assert.Equal(new[] { "Start", "0", "1", "End" }, lines); + } + + [Fact(DisplayName = "Break exits out of While")] + public async Task Test4() + { + var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BreakWhileWorkflow()); + await _workflowRunner.RunAsync(workflow); + var lines = _capturingTextWriter.Lines.ToList(); + Assert.Equal(new[] { "Start", "1", "2", "End" }, lines); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Break/BreakWhileWorkflow.cs b/test/Elsa.IntegrationTests/Break/BreakWhileWorkflow.cs new file mode 100644 index 000000000..b04f10b4c --- /dev/null +++ b/test/Elsa.IntegrationTests/Break/BreakWhileWorkflow.cs @@ -0,0 +1,40 @@ +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Models; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests; + +public class BreakWhileWorkflow : IWorkflow +{ + public void Build(IWorkflowDefinitionBuilder workflow) + { + var currentValue = new Variable(0); + + workflow.WithRoot(new Sequence + { + Variables = { currentValue }, + Activities = + { + new WriteLine("Start"), + While.True(new Sequence + { + Activities = + { + new SetVariable + { + Variable = currentValue, + Value = new Input(context => currentValue.Get(context) + 1) + }, + new If(context => currentValue.Get(context) == 3) + { + Then = new Break() + }, + new WriteLine(context => currentValue.Get(context).ToString()), + } + }), + new WriteLine("End"), + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj.DotSettings b/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj.DotSettings new file mode 100644 index 000000000..4b4f2ea72 --- /dev/null +++ b/test/Elsa.IntegrationTests/Elsa.IntegrationTests.csproj.DotSettings @@ -0,0 +1,5 @@ + + True + True + True + True \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/ForEach/ForEachTests.cs b/test/Elsa.IntegrationTests/ForEach/ForEachTests.cs new file mode 100644 index 000000000..5cabe4d9b --- /dev/null +++ b/test/Elsa.IntegrationTests/ForEach/ForEachTests.cs @@ -0,0 +1,32 @@ +using System.Linq; +using System.Threading.Tasks; +using Elsa.Builders; +using Elsa.Contracts; +using Elsa.Testing.Shared; +using Microsoft.Extensions.DependencyInjection; +using Xunit; +using Xunit.Abstractions; + +namespace Elsa.IntegrationTests; + +public class ForEachTests +{ + private readonly IWorkflowRunner _workflowRunner; + private readonly CapturingTextWriter _capturingTextWriter = new(); + + public ForEachTests(ITestOutputHelper testOutputHelper) + { + var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build(); + _workflowRunner = services.GetRequiredService(); + } + + [Fact(DisplayName = "ForEach outputs each iteration")] + public async Task Test1() + { + var items = new[] { "C#", "Rust", "Go"}; + var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new ForEachWorkflow(items)); + await _workflowRunner.RunAsync(workflow); + var lines = _capturingTextWriter.Lines.ToList(); + Assert.Equal(items, lines); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/ForEach/ForEachWorkflow.cs b/test/Elsa.IntegrationTests/ForEach/ForEachWorkflow.cs new file mode 100644 index 000000000..063a91685 --- /dev/null +++ b/test/Elsa.IntegrationTests/ForEach/ForEachWorkflow.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Models; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests; + +class ForEachWorkflow : IWorkflow +{ + private readonly ICollection _items; + + public ForEachWorkflow(ICollection items) + { + _items = items; + } + + public void Build(IWorkflowDefinitionBuilder workflow) + { + var currentItem = new Variable(); + + workflow.WithRoot(new Sequence + { + Activities = + { + new ForEach + { + Items = new Input>(_items), + CurrentValue = currentItem, + Body = new WriteLine(currentItem) + }, + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/ForEach/NestedForEachWithBreakWorkflow.cs b/test/Elsa.IntegrationTests/ForEach/NestedForEachWithBreakWorkflow.cs new file mode 100644 index 000000000..fae0e9e18 --- /dev/null +++ b/test/Elsa.IntegrationTests/ForEach/NestedForEachWithBreakWorkflow.cs @@ -0,0 +1,44 @@ +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Models; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests; + +class NestedForEachWithBreakWorkflow : IWorkflow +{ + public void Build(IWorkflowDefinitionBuilder workflow) + { + var outerItems = new[] { "C#", "Rust", "Go" }; + var innerItems = new[] { "Classes", "Functions", "Modules" }; + var currentOuterItem = new Variable(); + var currentInnerItem = new Variable(); + + workflow.WithRoot(new ForEach(outerItems) + { + CurrentValue = currentOuterItem, + Body = new Sequence + { + Activities = + { + new WriteLine(currentOuterItem), + new ForEach(innerItems) + { + CurrentValue = currentInnerItem, + Body = new Sequence + { + Activities = + { + new If(context => currentInnerItem.Get(context) == "Functions") + { + Then = new Break() + }, + new WriteLine(currentInnerItem) + } + } + } + } + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Sequence/NestedSequentialWorkflow.cs b/test/Elsa.IntegrationTests/Sequence/NestedSequentialWorkflow.cs new file mode 100644 index 000000000..ff3f8e9db --- /dev/null +++ b/test/Elsa.IntegrationTests/Sequence/NestedSequentialWorkflow.cs @@ -0,0 +1,29 @@ +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests; + +class NestedSequentialWorkflow : IWorkflow +{ + public void Build(IWorkflowDefinitionBuilder workflow) + { + workflow.WithRoot(new Sequence + { + Activities = + { + new WriteLine("Start"), + new Sequence + { + Activities = + { + new WriteLine("Line 1"), + new WriteLine("Line 2"), + new WriteLine("Line 3") + } + }, + new WriteLine("End"), + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Workflows/SequentialWorkflowTests.cs b/test/Elsa.IntegrationTests/Sequence/SequenceTests.cs similarity index 50% rename from test/Elsa.IntegrationTests/Workflows/SequentialWorkflowTests.cs rename to test/Elsa.IntegrationTests/Sequence/SequenceTests.cs index 0997677e8..7acabca37 100644 --- a/test/Elsa.IntegrationTests/Workflows/SequentialWorkflowTests.cs +++ b/test/Elsa.IntegrationTests/Sequence/SequenceTests.cs @@ -1,23 +1,21 @@ 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.IntegrationTests.Workflows; using Elsa.Testing.Shared; using Microsoft.Extensions.DependencyInjection; using Xunit; using Xunit.Abstractions; -namespace Elsa.IntegrationTests.Workflows; +namespace Elsa.IntegrationTests; -public class SequentialWorkflowTests +public class SequenceTests { private readonly IWorkflowRunner _workflowRunner; private readonly CapturingTextWriter _capturingTextWriter = new(); - public SequentialWorkflowTests(ITestOutputHelper testOutputHelper) + public SequenceTests(ITestOutputHelper testOutputHelper) { var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build(); _workflowRunner = services.GetRequiredService(); @@ -41,43 +39,5 @@ public class SequentialWorkflowTests Assert.Equal(new[] { "Start", "Line 1", "Line 2", "Line 3", "End" }, lines); } - private class SequentialWorkflow : IWorkflow - { - public void Build(IWorkflowDefinitionBuilder workflow) - { - workflow.WithRoot(new Sequence - { - Activities = - { - new WriteLine("Line 1"), - new WriteLine("Line 2"), - new WriteLine("Line 3") - } - }); - } - } - private class NestedSequentialWorkflow : IWorkflow - { - public void Build(IWorkflowDefinitionBuilder workflow) - { - workflow.WithRoot(new Sequence - { - Activities = - { - new WriteLine("Start"), - new Sequence - { - Activities = - { - new WriteLine("Line 1"), - new WriteLine("Line 2"), - new WriteLine("Line 3") - } - }, - new WriteLine("End"), - } - }); - } - } } \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Sequence/SequentialWorkflow.cs b/test/Elsa.IntegrationTests/Sequence/SequentialWorkflow.cs new file mode 100644 index 000000000..29b81d6fa --- /dev/null +++ b/test/Elsa.IntegrationTests/Sequence/SequentialWorkflow.cs @@ -0,0 +1,21 @@ +using Elsa.Activities; +using Elsa.Contracts; +using Elsa.Modules.Activities.Activities.Console; + +namespace Elsa.IntegrationTests.Workflows; + +class SequentialWorkflow : IWorkflow +{ + public void Build(IWorkflowDefinitionBuilder workflow) + { + workflow.WithRoot(new Sequence + { + Activities = + { + new WriteLine("Line 1"), + new WriteLine("Line 2"), + new WriteLine("Line 3") + } + }); + } +} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Workflows/BreakWorkflowTests.cs b/test/Elsa.IntegrationTests/Workflows/BreakWorkflowTests.cs deleted file mode 100644 index 401af3d2b..000000000 --- a/test/Elsa.IntegrationTests/Workflows/BreakWorkflowTests.cs +++ /dev/null @@ -1,201 +0,0 @@ -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 BreakWorkflowTests -{ - private readonly IWorkflowRunner _workflowRunner; - private readonly CapturingTextWriter _capturingTextWriter = new(); - - public BreakWorkflowTests(ITestOutputHelper testOutputHelper) - { - var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build(); - _workflowRunner = services.GetRequiredService(); - } - - [Fact(DisplayName = "Break exits out of ForEach")] - public async Task Test1() - { - var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BreakForEachWorkflow()); - await _workflowRunner.RunAsync(workflow); - var lines = _capturingTextWriter.Lines.ToList(); - Assert.Equal(new[] { "Start", "C#", "Test", "End" }, lines); - } - - [Fact(DisplayName = "Break exits out of immediate ForEach only")] - public async Task Test2() - { - var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new NestedForEachWithBreakWorkflow()); - await _workflowRunner.RunAsync(workflow); - var lines = _capturingTextWriter.Lines.ToList(); - Assert.Equal(new[] { "C#", "Classes", "Rust", "Classes", "Go", "Classes" }, lines); - } - - [Fact(DisplayName = "Break exits out of For")] - public async Task Test3() - { - var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BreakForWorkflow()); - await _workflowRunner.RunAsync(workflow); - var lines = _capturingTextWriter.Lines.ToList(); - Assert.Equal(new[] { "Start", "0", "1", "End" }, lines); - } - - [Fact(DisplayName = "Break exits out of While")] - public async Task Test4() - { - var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new BreakWhileWorkflow()); - await _workflowRunner.RunAsync(workflow); - var lines = _capturingTextWriter.Lines.ToList(); - Assert.Equal(new[] { "Start", "1", "2", "End" }, lines); - } - - private class BreakForEachWorkflow : IWorkflow - { - public void Build(IWorkflowDefinitionBuilder workflow) - { - var items = new[] { "C#", "Rust", "Go" }; - var currentItem = new Variable(); - - workflow.WithRoot(new Sequence - { - Activities = - { - new WriteLine("Start"), - new ForEach - { - Items = new Input>(items), - CurrentValue = currentItem, - Body = new Sequence - { - Activities = - { - new If(context => currentItem.Get(context) == "Rust") - { - Then = new Break() - }, - new WriteLine(currentItem), - new WriteLine("Test") - } - } - }, - new WriteLine("End"), - } - }); - } - } - - private class NestedForEachWithBreakWorkflow : IWorkflow - { - public void Build(IWorkflowDefinitionBuilder workflow) - { - var outerItems = new[] { "C#", "Rust", "Go" }; - var innerItems = new[] { "Classes", "Functions", "Modules" }; - var currentOuterItem = new Variable(); - var currentInnerItem = new Variable(); - - workflow.WithRoot(new ForEach(outerItems) - { - CurrentValue = currentOuterItem, - Body = new Sequence - { - Activities = - { - new WriteLine(currentOuterItem), - new ForEach(innerItems) - { - CurrentValue = currentInnerItem, - Body = new Sequence - { - Activities = - { - new If(context => currentInnerItem.Get(context) == "Functions") - { - Then = new Break() - }, - new WriteLine(currentInnerItem) - } - } - } - } - } - }); - } - } - - private class BreakForWorkflow : IWorkflow - { - public void Build(IWorkflowDefinitionBuilder workflow) - { - var currentValue = new Variable(); - - workflow.WithRoot(new Sequence - { - Activities = - { - new WriteLine("Start"), - new For(0, 3) - { - CurrentValue = currentValue, - Body = new Sequence - { - Activities = - { - new If(context => currentValue.Get(context) == 2) - { - Then = new Break() - }, - new WriteLine(context => currentValue.Get(context).ToString()), - } - } - }, - new WriteLine("End"), - } - }); - } - } - - private class BreakWhileWorkflow : IWorkflow - { - public void Build(IWorkflowDefinitionBuilder workflow) - { - var currentValue = new Variable(0); - - workflow.WithRoot(new Sequence - { - Variables = { currentValue }, - Activities = - { - new WriteLine("Start"), - While.True(new Sequence - { - Activities = - { - new SetVariable - { - Variable = currentValue, - Value = new Input(context => currentValue.Get(context) + 1) - }, - new If(context => currentValue.Get(context) == 3) - { - Then = new Break() - }, - new WriteLine(context => currentValue.Get(context).ToString()), - } - }), - new WriteLine("End"), - } - }); - } - } -} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Workflows/ForEachWorkflowTests.cs b/test/Elsa.IntegrationTests/Workflows/ForEachWorkflowTests.cs deleted file mode 100644 index 0c9e691bd..000000000 --- a/test/Elsa.IntegrationTests/Workflows/ForEachWorkflowTests.cs +++ /dev/null @@ -1,64 +0,0 @@ -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(); - - public ForEachWorkflowTests(ITestOutputHelper testOutputHelper) - { - var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build(); - _workflowRunner = services.GetRequiredService(); - } - - [Fact(DisplayName = "ForEach outputs each iteration")] - public async Task Test1() - { - var items = new[] { "C#", "Rust", "Go"}; - var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new ForEachWorkflow(items)); - await _workflowRunner.RunAsync(workflow); - var lines = _capturingTextWriter.Lines.ToList(); - Assert.Equal(items, lines); - } - - private class ForEachWorkflow : IWorkflow - { - private readonly ICollection _items; - - public ForEachWorkflow(ICollection items) - { - _items = items; - } - - public void Build(IWorkflowDefinitionBuilder workflow) - { - var currentItem = new Variable(); - - workflow.WithRoot(new Sequence - { - Activities = - { - new ForEach - { - Items = new Input>(_items), - CurrentValue = currentItem, - Body = new WriteLine(currentItem) - }, - } - }); - } - } -} \ No newline at end of file diff --git a/test/Elsa.IntegrationTests/Workflows/HelloWorldWorkflowTests.cs b/test/Elsa.IntegrationTests/WriteLine/HelloWorldWorkflowTests.cs similarity index 96% rename from test/Elsa.IntegrationTests/Workflows/HelloWorldWorkflowTests.cs rename to test/Elsa.IntegrationTests/WriteLine/HelloWorldWorkflowTests.cs index c0f0ce4e8..c6b59bef7 100644 --- a/test/Elsa.IntegrationTests/Workflows/HelloWorldWorkflowTests.cs +++ b/test/Elsa.IntegrationTests/WriteLine/HelloWorldWorkflowTests.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Xunit; using Xunit.Abstractions; -namespace Elsa.IntegrationTests.Workflows; +namespace Elsa.IntegrationTests; public class HelloWorldWorkflowTests {