Restructure integration tests
This commit is contained in:
parent
d1e5efb160
commit
75d036b0fc
42
test/Elsa.IntegrationTests/Break/BreakForEachWorkflow.cs
Normal file
42
test/Elsa.IntegrationTests/Break/BreakForEachWorkflow.cs
Normal file
|
|
@ -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<string>();
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Start"),
|
||||
new ForEach<string>
|
||||
{
|
||||
Items = new Input<ICollection<string>>(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"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
38
test/Elsa.IntegrationTests/Break/BreakForWorkflow.cs
Normal file
38
test/Elsa.IntegrationTests/Break/BreakForWorkflow.cs
Normal file
|
|
@ -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<int?>();
|
||||
|
||||
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"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
59
test/Elsa.IntegrationTests/Break/BreakTests.cs
Normal file
59
test/Elsa.IntegrationTests/Break/BreakTests.cs
Normal file
|
|
@ -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<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
40
test/Elsa.IntegrationTests/Break/BreakWhileWorkflow.cs
Normal file
40
test/Elsa.IntegrationTests/Break/BreakWhileWorkflow.cs
Normal file
|
|
@ -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<int?>(0);
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Variables = { currentValue },
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Start"),
|
||||
While.True(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new SetVariable
|
||||
{
|
||||
Variable = currentValue,
|
||||
Value = new Input<object?>(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"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=break/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=foreach/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=sequence/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=writeline/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
32
test/Elsa.IntegrationTests/ForEach/ForEachTests.cs
Normal file
32
test/Elsa.IntegrationTests/ForEach/ForEachTests.cs
Normal file
|
|
@ -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<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
35
test/Elsa.IntegrationTests/ForEach/ForEachWorkflow.cs
Normal file
35
test/Elsa.IntegrationTests/ForEach/ForEachWorkflow.cs
Normal file
|
|
@ -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<string> _items;
|
||||
|
||||
public ForEachWorkflow(ICollection<string> items)
|
||||
{
|
||||
_items = items;
|
||||
}
|
||||
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
var currentItem = new Variable<string>();
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new ForEach<string>
|
||||
{
|
||||
Items = new Input<ICollection<string>>(_items),
|
||||
CurrentValue = currentItem,
|
||||
Body = new WriteLine(currentItem)
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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<string>();
|
||||
var currentInnerItem = new Variable<string>();
|
||||
|
||||
workflow.WithRoot(new ForEach<string>(outerItems)
|
||||
{
|
||||
CurrentValue = currentOuterItem,
|
||||
Body = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine(currentOuterItem),
|
||||
new ForEach<string>(innerItems)
|
||||
{
|
||||
CurrentValue = currentInnerItem,
|
||||
Body = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new If(context => currentInnerItem.Get(context) == "Functions")
|
||||
{
|
||||
Then = new Break()
|
||||
},
|
||||
new WriteLine(currentInnerItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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<IWorkflowRunner>();
|
||||
|
|
@ -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"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
21
test/Elsa.IntegrationTests/Sequence/SequentialWorkflow.cs
Normal file
21
test/Elsa.IntegrationTests/Sequence/SequentialWorkflow.cs
Normal file
|
|
@ -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")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[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<string>();
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Start"),
|
||||
new ForEach<string>
|
||||
{
|
||||
Items = new Input<ICollection<string>>(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<string>();
|
||||
var currentInnerItem = new Variable<string>();
|
||||
|
||||
workflow.WithRoot(new ForEach<string>(outerItems)
|
||||
{
|
||||
CurrentValue = currentOuterItem,
|
||||
Body = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine(currentOuterItem),
|
||||
new ForEach<string>(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<int?>();
|
||||
|
||||
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<int?>(0);
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Variables = { currentValue },
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Start"),
|
||||
While.True(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new SetVariable
|
||||
{
|
||||
Variable = currentValue,
|
||||
Value = new Input<object?>(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"),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[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<string> _items;
|
||||
|
||||
public ForEachWorkflow(ICollection<string> items)
|
||||
{
|
||||
_items = items;
|
||||
}
|
||||
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
var currentItem = new Variable<string>();
|
||||
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new ForEach<string>
|
||||
{
|
||||
Items = new Input<ICollection<string>>(_items),
|
||||
CurrentValue = currentItem,
|
||||
Body = new WriteLine(currentItem)
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.IntegrationTests.Workflows;
|
||||
namespace Elsa.IntegrationTests;
|
||||
|
||||
public class HelloWorldWorkflowTests
|
||||
{
|
||||
Loading…
Reference in a new issue