-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a22a15
commit cb8451b
Showing
14 changed files
with
312 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using WorkflowCore.Models; | ||
using WorkflowCore.Testing; | ||
using WorkflowCore.TestSample01.Workflow; | ||
|
||
namespace WorkflowCore.TestSample01 | ||
{ | ||
[TestFixture] | ||
public class NUnitTest : WorkflowTest<MyWorkflow, MyDataClass> | ||
{ | ||
[SetUp] | ||
protected override void Setup() | ||
{ | ||
base.Setup(); | ||
} | ||
|
||
[Test] | ||
public void NUnit_workflow_test_sample() | ||
{ | ||
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 }); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(0); | ||
GetData(workflowId).Value3.Should().Be(5); | ||
} | ||
|
||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/samples/WorkflowCore.TestSample01/Workflow/AddNumbers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using WorkflowCore.Interface; | ||
using WorkflowCore.Models; | ||
|
||
namespace WorkflowCore.TestSample01.Workflow | ||
{ | ||
public class AddNumbers : StepBody | ||
{ | ||
public int Input1 { get; set; } | ||
public int Input2 { get; set; } | ||
public int Output { get; set; } | ||
|
||
public override ExecutionResult Run(IStepExecutionContext context) | ||
{ | ||
Output = (Input1 + Input2); | ||
return ExecutionResult.Next(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/samples/WorkflowCore.TestSample01/Workflow/MyDataClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace WorkflowCore.TestSample01.Workflow | ||
{ | ||
public class MyDataClass | ||
{ | ||
public int Value1 { get; set; } | ||
public int Value2 { get; set; } | ||
public int Value3 { get; set; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/samples/WorkflowCore.TestSample01/Workflow/MyWorkflow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using WorkflowCore.Interface; | ||
|
||
namespace WorkflowCore.TestSample01.Workflow | ||
{ | ||
public class MyWorkflow : IWorkflow<MyDataClass> | ||
{ | ||
public string Id => "MyWorkflow"; | ||
public int Version => 1; | ||
public void Build(IWorkflowBuilder<MyDataClass> builder) | ||
{ | ||
builder | ||
.StartWith<AddNumbers>() | ||
.Input(step => step.Input1, data => data.Value1) | ||
.Input(step => step.Input2, data => data.Value2) | ||
.Output(data => data.Value3, step => step.Output); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/samples/WorkflowCore.TestSample01/WorkflowCore.TestSample01.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="4.19.2" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> | ||
<PackageReference Include="NUnit" Version="3.7.1" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0-alpha1" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\test\WorkflowCore.Testing\WorkflowCore.Testing.csproj" /> | ||
<ProjectReference Include="..\..\WorkflowCore\WorkflowCore.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Test Sample | ||
|
||
Illustrates the use of the WorkflowCore.Testing package | ||
|
||
### With xUnit | ||
|
||
* Create a class that inherits from WorkflowTest | ||
* Call the Setup() method in the constructor | ||
* Implement your tests using the helper methods | ||
* StartWorkflow() | ||
* WaitForWorkflowToComplete() | ||
* WaitForEventSubscription() | ||
* GetStatus() | ||
* GetData() | ||
* UnhandledStepErrors | ||
|
||
```C# | ||
public class xUnitTest : WorkflowTest<MyWorkflow, MyDataClass> | ||
{ | ||
public xUnitTest() | ||
{ | ||
Setup(); | ||
} | ||
|
||
[Fact] | ||
public void MyWorkflow() | ||
{ | ||
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 }); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(0); | ||
GetData(workflowId).Value3.Should().Be(5); | ||
} | ||
} | ||
``` | ||
|
||
|
||
### With NUnit | ||
|
||
* Create a class that inherits from WorkflowTest and decorate it with the *TestFixture* attribute | ||
* Override the Setup method and decorate it with the *SetUp* attribute | ||
* Implement your tests using the helper methods | ||
* StartWorkflow() | ||
* WaitForWorkflowToComplete() | ||
* WaitForEventSubscription() | ||
* GetStatus() | ||
* GetData() | ||
* UnhandledStepErrors | ||
|
||
```C# | ||
[TestFixture] | ||
public class NUnitTest : WorkflowTest<MyWorkflow, MyDataClass> | ||
{ | ||
[SetUp] | ||
protected override void Setup() | ||
{ | ||
base.Setup(); | ||
} | ||
|
||
[Test] | ||
public void NUnit_workflow_test_sample() | ||
{ | ||
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 }); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(0); | ||
GetData(workflowId).Value3.Should().Be(5); | ||
} | ||
|
||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using FluentAssertions; | ||
using System; | ||
using WorkflowCore.Models; | ||
using WorkflowCore.Testing; | ||
using WorkflowCore.TestSample01.Workflow; | ||
using Xunit; | ||
|
||
namespace WorkflowCore.TestSample01 | ||
{ | ||
public class xUnitTest : WorkflowTest<MyWorkflow, MyDataClass> | ||
{ | ||
public xUnitTest() | ||
{ | ||
Setup(); | ||
} | ||
|
||
[Fact] | ||
public void MyWorkflow() | ||
{ | ||
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 }); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(0); | ||
GetData(workflowId).Value3.Should().Be(5); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Test helpers for Workflow Core | ||
|
||
Provides support writing tests for workflows built on WorkflowCore | ||
|
||
## Installing | ||
|
||
Install the NuGet package "WorkflowCore.Testing" | ||
|
||
``` | ||
PM> Install-Package WorkflowCore.Testing | ||
``` | ||
|
||
## Usage | ||
|
||
### With xUnit | ||
|
||
* Create a class that inherits from WorkflowTest | ||
* Call the Setup() method in the constructor | ||
* Implement your tests using the helper methods | ||
* StartWorkflow() | ||
* WaitForWorkflowToComplete() | ||
* WaitForEventSubscription() | ||
* GetStatus() | ||
* GetData() | ||
* UnhandledStepErrors | ||
|
||
```C# | ||
public class xUnitTest : WorkflowTest<MyWorkflow, MyDataClass> | ||
{ | ||
public xUnitTest() | ||
{ | ||
Setup(); | ||
} | ||
|
||
[Fact] | ||
public void MyWorkflow() | ||
{ | ||
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 }); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(0); | ||
GetData(workflowId).Value3.Should().Be(5); | ||
} | ||
} | ||
``` | ||
|
||
|
||
### With NUnit | ||
|
||
* Create a class that inherits from WorkflowTest and decorate it with the *TestFixture* attribute | ||
* Override the Setup method and decorate it with the *SetUp* attribute | ||
* Implement your tests using the helper methods | ||
* StartWorkflow() | ||
* WaitForWorkflowToComplete() | ||
* WaitForEventSubscription() | ||
* GetStatus() | ||
* GetData() | ||
* UnhandledStepErrors | ||
|
||
```C# | ||
[TestFixture] | ||
public class NUnitTest : WorkflowTest<MyWorkflow, MyDataClass> | ||
{ | ||
[SetUp] | ||
protected override void Setup() | ||
{ | ||
base.Setup(); | ||
} | ||
|
||
[Test] | ||
public void NUnit_workflow_test_sample() | ||
{ | ||
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 }); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(0); | ||
GetData(workflowId).Value3.Should().Be(5); | ||
} | ||
|
||
} | ||
``` |