Skip to content

Commit

Permalink
samples, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgerlag committed Jul 2, 2017
1 parent 8a22a15 commit cb8451b
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ There are several persistence providers available as separate Nuget packages.

* [Human(User) Workflow](src/samples/WorkflowCore.Sample08)

* [Testing](src/samples/WorkflowCore.TestSample01)


## Authors

Expand Down
File renamed without changes.
9 changes: 8 additions & 1 deletion WorkflowCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ReleaseNotes", "ReleaseNotes", "{38ECB00C-3F3B-4442-8408-ACE3B37FFAA8}"
ProjectSection(SolutionItems) = preProject
ReleaseNotes\1.2.8.md = ReleaseNotes\1.2.8.md
1.2.9.md = 1.2.9.md
ReleaseNotes\1.2.9.md = ReleaseNotes\1.2.9.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Sample14", "src\samples\WorkflowCore.Sample14\WorkflowCore.Sample14.csproj", "{6BC66637-B42A-4334-ADFB-DBEC9F29D293}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.Testing", "test\WorkflowCore.Testing\WorkflowCore.Testing.csproj", "{62A9709E-27DA-42EE-B94F-5AF431D86354}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.TestSample01", "src\samples\WorkflowCore.TestSample01\WorkflowCore.TestSample01.csproj", "{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -252,6 +254,10 @@ Global
{62A9709E-27DA-42EE-B94F-5AF431D86354}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62A9709E-27DA-42EE-B94F-5AF431D86354}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62A9709E-27DA-42EE-B94F-5AF431D86354}.Release|Any CPU.Build.0 = Release|Any CPU
{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -297,5 +303,6 @@ Global
{A2374B7C-4198-40B3-B8FE-FAC3DB3F2539} = {2EEE6ABD-EE9B-473F-AF2D-6DABB85D7BA2}
{6BC66637-B42A-4334-ADFB-DBEC9F29D293} = {5080DB09-CBE8-4C45-9957-C3BB7651755E}
{62A9709E-27DA-42EE-B94F-5AF431D86354} = {E6CEAD8D-F565-471E-A0DC-676F54EAEDEB}
{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E} = {5080DB09-CBE8-4C45-9957-C3BB7651755E}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion src/providers/WorkflowCore.Persistence.MongoDB/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Provides support to persist workflows running on [Workflow Core](../../README.md
Install the NuGet package "WorkflowCore.Persistence.MongoDB"

```
PM> Install-Package WorkflowCore.Persistence.MongoDB -Pre
PM> Install-Package WorkflowCore.Persistence.MongoDB
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion src/providers/WorkflowCore.Persistence.SqlServer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Provides support to persist workflows running on [Workflow Core](../../README.md
Install the NuGet package "WorkflowCore.Persistence.SqlServer"

```
PM> Install-Package WorkflowCore.Persistence.SqlServer -Pre
PM> Install-Package WorkflowCore.Persistence.SqlServer
```

## Usage
Expand Down
33 changes: 33 additions & 0 deletions src/samples/WorkflowCore.TestSample01/NUnitTest.cs
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 src/samples/WorkflowCore.TestSample01/Workflow/AddNumbers.cs
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 src/samples/WorkflowCore.TestSample01/Workflow/MyDataClass.cs
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 src/samples/WorkflowCore.TestSample01/Workflow/MyWorkflow.cs
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);
}
}
}
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>
73 changes: 73 additions & 0 deletions src/samples/WorkflowCore.TestSample01/readme.md
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);
}

}
```
28 changes: 28 additions & 0 deletions src/samples/WorkflowCore.TestSample01/xUnitTest.cs
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);
}
}
}
2 changes: 1 addition & 1 deletion test/WorkflowCore.Testing/WorkflowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class WorkflowTest<TWorkflow, TData> : IDisposable
protected IPersistenceProvider PersistenceProvider;
protected List<StepError> UnhandledStepErrors = new List<StepError>();

protected void Setup()
protected virtual void Setup()
{
//setup dependency injection
IServiceCollection services = new ServiceCollection();
Expand Down
83 changes: 83 additions & 0 deletions test/WorkflowCore.Testing/readme.md
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);
}

}
```

0 comments on commit cb8451b

Please sign in to comment.