Skip to content

Commit

Permalink
Refactor StopScenario for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
mamidenn committed Aug 8, 2022
1 parent 55429e3 commit 7186d59
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions test/WorkflowCore.IntegrationTests/Scenarios/StopScenario.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using WorkflowCore.Interface;
using WorkflowCore.Models;
using Xunit;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using WorkflowCore.Testing;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Models.LifeCycleEvents;
using System.Threading.Tasks;
using System.Threading;
using Moq;
using WorkflowCore.Testing;
using Xunit;

namespace WorkflowCore.IntegrationTests.Scenarios
{
Expand All @@ -18,33 +17,29 @@ public class StopWorkflow : IWorkflow
public int Version => 1;
public void Build(IWorkflowBuilder<object> builder)
{
builder.StartWith(context => ExecutionResult.Next());
builder.StartWith(context => ExecutionResult.Next());
}
}

public StopScenario()
{
Setup();
}
public StopScenario() => Setup();

[Fact]
public async Task Scenario()
{
var tcs = new TaskCompletionSource<object>();
Host.OnLifeCycleEvent += (evt) => OnLifeCycleEvent(evt, tcs);
var workflowId = StartWorkflow(null);
Host.OnLifeCycleEvent += async (evt) =>
{
if (evt is WorkflowCompleted)
{
await Host.StopAsync(CancellationToken.None);
tcs.SetResult(default);
}
};

var workflowId = StartWorkflow(default);
await tcs.Task;
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
}

private async void OnLifeCycleEvent(LifeCycleEvent evt, TaskCompletionSource<object> tcs)
{
if (evt is WorkflowCompleted)
{
await Host.StopAsync(CancellationToken.None);
tcs.SetResult(new());
}
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
}

protected override void Dispose(bool disposing) { }
Expand Down

0 comments on commit 7186d59

Please sign in to comment.