Add tests for If activity
This commit is contained in:
parent
75d036b0fc
commit
7fa62582b8
|
|
@ -4,7 +4,7 @@ using Elsa.Contracts;
|
|||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
class BreakForEachWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@ using Elsa.Contracts;
|
|||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
class BreakForWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -2,13 +2,12 @@ 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;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class BreakWorkflowTests
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@ using Elsa.Contracts;
|
|||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class BreakWhileWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class ForEachTests
|
||||
{
|
||||
|
|
@ -4,7 +4,7 @@ using Elsa.Contracts;
|
|||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
class ForEachWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -3,7 +3,7 @@ using Elsa.Contracts;
|
|||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
class NestedForEachWithBreakWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using Elsa.Activities;
|
||||
using Elsa.Contracts;
|
||||
using Elsa.Models;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class ComplexIfWorkflow : IWorkflow
|
||||
{
|
||||
private readonly Func<bool> _condition;
|
||||
|
||||
public ComplexIfWorkflow(Func<bool> condition)
|
||||
{
|
||||
_condition = condition;
|
||||
}
|
||||
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
workflow.WithRoot(new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Start"),
|
||||
new If(_condition)
|
||||
{
|
||||
Then = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Executing"),
|
||||
new WriteLine("True!"),
|
||||
}
|
||||
},
|
||||
Else = new Sequence
|
||||
{
|
||||
Activities =
|
||||
{
|
||||
new WriteLine("Executing"),
|
||||
new WriteLine("False!"),
|
||||
}
|
||||
}
|
||||
},
|
||||
new WriteLine("End")
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
44
test/Elsa.IntegrationTests/Activities/If/IfTests.cs
Normal file
44
test/Elsa.IntegrationTests/Activities/If/IfTests.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
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.Activities;
|
||||
|
||||
public class IfTests
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
|
||||
public IfTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
||||
}
|
||||
|
||||
[Theory(DisplayName = "The correct branch executes when condition is true")]
|
||||
[InlineData(true, "True!")]
|
||||
[InlineData(false, "False!")]
|
||||
public async Task Test1(bool conditionResult, string expectedLine)
|
||||
{
|
||||
var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new IfThenWorkflow(() => conditionResult));
|
||||
await _workflowRunner.RunAsync(workflow);
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(new[] { expectedLine }, lines);
|
||||
}
|
||||
|
||||
[Theory(DisplayName = "The If activity completes only after either one of its branches completed")]
|
||||
[InlineData(true, new[] { "Start", "Executing", "True!", "End" })]
|
||||
[InlineData(false, new[] { "Start", "Executing", "False!", "End" })]
|
||||
public async Task Test2(bool conditionResult, string[] expectedLines)
|
||||
{
|
||||
var workflow = new WorkflowDefinitionBuilder().BuildWorkflow(new ComplexIfWorkflow(() => conditionResult));
|
||||
await _workflowRunner.RunAsync(workflow);
|
||||
var lines = _capturingTextWriter.Lines.ToList();
|
||||
Assert.Equal(expectedLines, lines);
|
||||
}
|
||||
}
|
||||
25
test/Elsa.IntegrationTests/Activities/If/IfThenWorkflow.cs
Normal file
25
test/Elsa.IntegrationTests/Activities/If/IfThenWorkflow.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using Elsa.Activities;
|
||||
using Elsa.Contracts;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class IfThenWorkflow : IWorkflow
|
||||
{
|
||||
private readonly Func<bool> _condition;
|
||||
|
||||
public IfThenWorkflow(Func<bool> condition)
|
||||
{
|
||||
_condition = condition;
|
||||
}
|
||||
|
||||
public void Build(IWorkflowDefinitionBuilder workflow)
|
||||
{
|
||||
workflow.WithRoot(new If(_condition)
|
||||
{
|
||||
Then = new WriteLine("True!"),
|
||||
Else = new WriteLine("False!")
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ using Elsa.Activities;
|
|||
using Elsa.Contracts;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
class NestedSequentialWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -2,13 +2,12 @@ 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;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class SequenceTests
|
||||
{
|
||||
|
|
@ -2,7 +2,7 @@ using Elsa.Activities;
|
|||
using Elsa.Contracts;
|
||||
using Elsa.Modules.Activities.Activities.Console;
|
||||
|
||||
namespace Elsa.IntegrationTests.Workflows;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
class SequentialWorkflow : IWorkflow
|
||||
{
|
||||
|
|
@ -8,14 +8,14 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.IntegrationTests;
|
||||
namespace Elsa.IntegrationTests.Activities;
|
||||
|
||||
public class HelloWorldWorkflowTests
|
||||
public class WriteLineTests
|
||||
{
|
||||
private readonly IWorkflowRunner _workflowRunner;
|
||||
private readonly CapturingTextWriter _capturingTextWriter = new();
|
||||
|
||||
public HelloWorldWorkflowTests(ITestOutputHelper testOutputHelper)
|
||||
public WriteLineTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
var services = new TestApplicationBuilder(testOutputHelper).WithCapturingTextWriter(_capturingTextWriter).Build();
|
||||
_workflowRunner = services.GetRequiredService<IWorkflowRunner>();
|
||||
|
|
@ -26,4 +26,8 @@
|
|||
<ProjectReference Include="..\Elsa.Testing.Shared\Elsa.Testing.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Activities" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
<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/=activities_005Cbreak/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=activities_005Cforeach/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=activities_005Cif/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=activities_005Csequence/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=activities_005Cwriteline/@EntryIndexedValue">True</s:Boolean>
|
||||
<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/=if/@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>
|
||||
Loading…
Reference in a new issue