Skip to content

Commit d0cacdb

Browse files
committed
Refactor StopScenario for better readability
1 parent 1ae6b28 commit d0cacdb

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

test/WorkflowCore.IntegrationTests/Scenarios/StopScenario.cs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using WorkflowCore.Interface;
2-
using WorkflowCore.Models;
3-
using Xunit;
1+
using System.Threading;
2+
using System.Threading.Tasks;
43
using FluentAssertions;
5-
using WorkflowCore.Testing;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
66
using WorkflowCore.Models.LifeCycleEvents;
7-
using System.Threading.Tasks;
8-
using System.Threading;
9-
using Moq;
7+
using WorkflowCore.Testing;
8+
using Xunit;
109

1110
namespace WorkflowCore.IntegrationTests.Scenarios
1211
{
@@ -18,33 +17,29 @@ public class StopWorkflow : IWorkflow
1817
public int Version => 1;
1918
public void Build(IWorkflowBuilder<object> builder)
2019
{
21-
builder.StartWith(context => ExecutionResult.Next());
20+
builder.StartWith(context => ExecutionResult.Next());
2221
}
2322
}
2423

25-
public StopScenario()
26-
{
27-
Setup();
28-
}
24+
public StopScenario() => Setup();
2925

3026
[Fact]
3127
public async Task Scenario()
3228
{
3329
var tcs = new TaskCompletionSource<object>();
34-
Host.OnLifeCycleEvent += (evt) => OnLifeCycleEvent(evt, tcs);
35-
var workflowId = StartWorkflow(null);
30+
Host.OnLifeCycleEvent += async (evt) =>
31+
{
32+
if (evt is WorkflowCompleted)
33+
{
34+
await Host.StopAsync(CancellationToken.None);
35+
tcs.SetResult(default);
36+
}
37+
};
3638

39+
var workflowId = StartWorkflow(default);
3740
await tcs.Task;
38-
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
39-
}
4041

41-
private async void OnLifeCycleEvent(LifeCycleEvent evt, TaskCompletionSource<object> tcs)
42-
{
43-
if (evt is WorkflowCompleted)
44-
{
45-
await Host.StopAsync(CancellationToken.None);
46-
tcs.SetResult(new());
47-
}
42+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
4843
}
4944

5045
protected override void Dispose(bool disposing) { }

0 commit comments

Comments
 (0)