Skip to content

Commit 56fb846

Browse files
committed
docs
1 parent aa4802c commit 56fb846

File tree

3 files changed

+218
-1
lines changed

3 files changed

+218
-1
lines changed

docs/elastic-search.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Elasticsearch plugin for Workflow Core
2+
3+
A search index plugin for Workflow Core backed by Elasticsearch, enabling you to index your workflows and search against the data and state of them.
4+
5+
## Installing
6+
7+
Install the NuGet package "WorkflowCore.Providers.Elasticsearch"
8+
9+
Using Nuget package console
10+
```
11+
PM> Install-Package WorkflowCore.Providers.Elasticsearch
12+
```
13+
14+
Using .NET CLI
15+
```
16+
dotnet add package WorkflowCore.Providers.Elasticsearch
17+
```
18+
19+
20+
## Configuration
21+
22+
Use the `.UseElasticsearch` extension method on `IServiceCollection` when building your service provider
23+
24+
```C#
25+
using Nest;
26+
...
27+
services.AddWorkflow(cfg =>
28+
{
29+
...
30+
cfg.UseElasticsearch(new ConnectionSettings(new Uri("http://localhost:9200")), "index_name");
31+
});
32+
```
33+
34+
## Usage
35+
36+
Inject the `ISearchIndex` service into your code and use the `Search` method.
37+
38+
```
39+
Search(string terms, int skip, int take, params SearchFilter[] filters)
40+
```
41+
42+
#### terms
43+
44+
A whitespace separated string of search terms, an empty string will match everything.
45+
This will do a full text search on the following default fields
46+
* Reference
47+
* Description
48+
* Status
49+
* Workflow Definition
50+
51+
In addition you can search data within your own custom data object if it implements `ISearchable`
52+
53+
```c#
54+
using WorkflowCore.Interfaces;
55+
...
56+
public class MyData : ISearchable
57+
{
58+
public string StrValue1 { get; set; }
59+
public string StrValue2 { get; set; }
60+
61+
public IEnumerable<string> GetSearchTokens()
62+
{
63+
return new List<string>()
64+
{
65+
StrValue1,
66+
StrValue2
67+
};
68+
}
69+
}
70+
```
71+
72+
##### Examples
73+
74+
Search all fields for "puppies"
75+
```c#
76+
searchIndex.Search("puppies", 0, 10);
77+
```
78+
79+
#### skip & take
80+
81+
Use `skip` and `take` to page your search results. Where `skip` is the result number to start from and `take` is the page size.
82+
83+
#### filters
84+
85+
You can also supply a list of filters to apply to the search, these can be applied to both the standard fields as well as any field within your custom data objects.
86+
There is no need to implement `ISearchable` on your data object in order to use filters against it.
87+
88+
The following filter types are available
89+
* ScalarFilter
90+
* DateRangeFilter
91+
* NumericRangeFilter
92+
* StatusFilter
93+
94+
These exist in the `WorkflowCore.Models.Search` namespace.
95+
96+
##### Examples
97+
98+
Filtering by reference
99+
```c#
100+
using WorkflowCore.Models.Search;
101+
...
102+
103+
searchIndex.Search("", 0, 10, ScalarFilter.Equals(x => x.Reference, "My Reference"));
104+
```
105+
106+
Filtering by workflows started after a date
107+
```c#
108+
searchIndex.Search("", 0, 10, DateRangeFilter.After(x => x.CreateTime, startDate));
109+
```
110+
111+
Filtering by workflows completed within a period
112+
```c#
113+
searchIndex.Search("", 0, 10, DateRangeFilter.Between(x => x.CompleteTime, startDate, endDate));
114+
```
115+
116+
Filtering by workflows in a state
117+
```c#
118+
searchIndex.Search("", 0, 10, StatusFilter.Equals(WorkflowStatus.Complete));
119+
```
120+
121+
Filtering against your own custom data class
122+
```c#
123+
124+
class MyData
125+
{
126+
public string Value1 { get; set; }
127+
public int Value2 { get; set; }
128+
}
129+
130+
searchIndex.Search("", 0, 10, ScalarFilter.Equals<MyData>(x => x.Value1, "blue moon"));
131+
searchIndex.Search("", 0, 10, NumericRangeFilter.LessThan<MyData>(x => x.Value2, 5))
132+
```

docs/test-helpers.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Test helpers for Workflow Core
2+
3+
Provides support writing tests for workflows built on WorkflowCore
4+
5+
## Installing
6+
7+
Install the NuGet package "WorkflowCore.Testing"
8+
9+
```
10+
PM> Install-Package WorkflowCore.Testing
11+
```
12+
13+
## Usage
14+
15+
### With xUnit
16+
17+
* Create a class that inherits from WorkflowTest
18+
* Call the Setup() method in the constructor
19+
* Implement your tests using the helper methods
20+
* StartWorkflow()
21+
* WaitForWorkflowToComplete()
22+
* WaitForEventSubscription()
23+
* GetStatus()
24+
* GetData()
25+
* UnhandledStepErrors
26+
27+
```C#
28+
public class xUnitTest : WorkflowTest<MyWorkflow, MyDataClass>
29+
{
30+
public xUnitTest()
31+
{
32+
Setup();
33+
}
34+
35+
[Fact]
36+
public void MyWorkflow()
37+
{
38+
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 });
39+
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
40+
41+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
42+
UnhandledStepErrors.Count.Should().Be(0);
43+
GetData(workflowId).Value3.Should().Be(5);
44+
}
45+
}
46+
```
47+
48+
49+
### With NUnit
50+
51+
* Create a class that inherits from WorkflowTest and decorate it with the *TestFixture* attribute
52+
* Override the Setup method and decorate it with the *SetUp* attribute
53+
* Implement your tests using the helper methods
54+
* StartWorkflow()
55+
* WaitForWorkflowToComplete()
56+
* WaitForEventSubscription()
57+
* GetStatus()
58+
* GetData()
59+
* UnhandledStepErrors
60+
61+
```C#
62+
[TestFixture]
63+
public class NUnitTest : WorkflowTest<MyWorkflow, MyDataClass>
64+
{
65+
[SetUp]
66+
protected override void Setup()
67+
{
68+
base.Setup();
69+
}
70+
71+
[Test]
72+
public void NUnit_workflow_test_sample()
73+
{
74+
var workflowId = StartWorkflow(new MyDataClass() { Value1 = 2, Value2 = 3 });
75+
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
76+
77+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
78+
UnhandledStepErrors.Count.Should().Be(0);
79+
GetData(workflowId).Value3.Should().Be(5);
80+
}
81+
82+
}
83+
```

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ nav:
99
- JSON / YAML Definitions: json-yaml.md
1010
- Persistence: persistence.md
1111
- Multi-node clusters: multi-node-clusters.md
12-
- ASP.NET Core.md: using-with-aspnet-core.md
12+
- ASP.NET Core: using-with-aspnet-core.md
13+
- Elasticsearch plugin: elastic-search.md
14+
- Test helpers: test-helpers.md
1315
- Extensions: extensions.md
1416
- Samples: samples.md
1517
theme: readthedocs

0 commit comments

Comments
 (0)