Skip to content

Commit 782ca9a

Browse files
Adding unit test to cover Parallel event scenario
1 parent 112fdee commit 782ca9a

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using WorkflowCore.Interface;
3+
using WorkflowCore.Models;
4+
using Xunit;
5+
using FluentAssertions;
6+
using WorkflowCore.Testing;
7+
using System.Threading;
8+
9+
namespace WorkflowCore.IntegrationTests.Scenarios
10+
{
11+
public sealed class ParallelEventsScenario
12+
: WorkflowTest<ParallelEventsScenario.ParallelEventsWorkflow, ParallelEventsScenario.MyDataClass>
13+
{
14+
private const string EVENT_KEY = nameof(EVENT_KEY);
15+
16+
public class MyDataClass
17+
{
18+
public string StrValue1 { get; set; }
19+
public string StrValue2 { get; set; }
20+
}
21+
22+
public class ParallelEventsWorkflow : IWorkflow<MyDataClass>
23+
{
24+
public string Id => "EventWorkflow";
25+
public int Version => 1;
26+
public void Build(IWorkflowBuilder<MyDataClass> builder)
27+
{
28+
builder
29+
.StartWith(context => ExecutionResult.Next())
30+
.Parallel()
31+
.Do(then =>
32+
then.WaitFor("Event1", data => EVENT_KEY).Then(x =>
33+
{
34+
Thread.Sleep(300);
35+
return ExecutionResult.Next();
36+
}))
37+
.Do(then =>
38+
then.WaitFor("Event2", data => EVENT_KEY).Then(x =>
39+
{
40+
Thread.Sleep(100);
41+
return ExecutionResult.Next();
42+
}))
43+
.Do(then =>
44+
then.WaitFor("Event3", data => EVENT_KEY).Then(x =>
45+
{
46+
Thread.Sleep(1000);
47+
return ExecutionResult.Next();
48+
}))
49+
.Do(then =>
50+
then.WaitFor("Event4", data => EVENT_KEY).Then(x =>
51+
{
52+
Thread.Sleep(100);
53+
return ExecutionResult.Next();
54+
}))
55+
.Do(then =>
56+
then.WaitFor("Event5", data => EVENT_KEY).Then(x =>
57+
{
58+
Thread.Sleep(100);
59+
return ExecutionResult.Next();
60+
}))
61+
.Join()
62+
.Then(x =>
63+
{
64+
return ExecutionResult.Next();
65+
});
66+
}
67+
}
68+
69+
public ParallelEventsScenario()
70+
{
71+
Setup();
72+
}
73+
74+
[Fact]
75+
public void Scenario()
76+
{
77+
var eventKey = Guid.NewGuid().ToString();
78+
var workflowId = StartWorkflow(new MyDataClass { StrValue1 = eventKey, StrValue2 = eventKey });
79+
Host.PublishEvent("Event1", EVENT_KEY, "Pass1");
80+
Host.PublishEvent("Event2", EVENT_KEY, "Pass2");
81+
Host.PublishEvent("Event3", EVENT_KEY, "Pass3");
82+
Host.PublishEvent("Event4", EVENT_KEY, "Pass4");
83+
Host.PublishEvent("Event5", EVENT_KEY, "Pass5");
84+
85+
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
86+
87+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
88+
UnhandledStepErrors.Count.Should().Be(0);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)