1
0
mirror of synced 2024-11-22 01:13:49 +00:00

Test case in flow example proves the previous fix works - closes #21

This commit is contained in:
Mark van Renswoude 2021-03-16 10:54:15 +01:00
parent 0b7c84a119
commit fa231bcc64
3 changed files with 30 additions and 3 deletions

View File

@ -19,7 +19,7 @@ namespace _03_FlowRequestResponse
container.Register<ILogger, ConsoleLogger>(); container.Register<ILogger, ConsoleLogger>();
var helper = new ExampleConsoleApp(dependencyResolver); var helper = new ExampleConsoleApp(dependencyResolver, 2);
helper.Run(MainAsync); helper.Run(MainAsync);
} }

View File

@ -65,9 +65,30 @@ namespace _03_FlowRequestResponse
Console.WriteLine("[SimpleFlowController] Quote: " + message.Quote); Console.WriteLine("[SimpleFlowController] Quote: " + message.Quote);
// Test for issue #21: Same request/response twice in flow does not continue
return flowProvider.YieldWithRequestSync<QuoteRequestMessage, QuoteResponseMessage>(
new QuoteRequestMessage
{
Amount = 42
},
HandleQuoteResponse2);
//exampleState.Done();
//return flowProvider.End();
}
[Continuation]
public IYieldPoint HandleQuoteResponse2(QuoteResponseMessage message)
{
Console.WriteLine("[SimpleFlowController] Quote 2: " + message.Quote);
exampleState.Done(); exampleState.Done();
return flowProvider.End(); return flowProvider.End();
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Tapeti; using Tapeti;
@ -21,13 +22,17 @@ namespace ExampleLib
public class ExampleConsoleApp public class ExampleConsoleApp
{ {
private readonly IDependencyContainer dependencyResolver; private readonly IDependencyContainer dependencyResolver;
private readonly int expectedDoneCount;
private int doneCount = 0;
private readonly TaskCompletionSource<bool> doneSignal = new TaskCompletionSource<bool>(); private readonly TaskCompletionSource<bool> doneSignal = new TaskCompletionSource<bool>();
/// <param name="dependencyResolver">Uses Tapeti's IDependencyContainer interface so you can easily switch an example to your favourite IoC container</param> /// <param name="dependencyResolver">Uses Tapeti's IDependencyContainer interface so you can easily switch an example to your favourite IoC container</param>
public ExampleConsoleApp(IDependencyContainer dependencyResolver) public ExampleConsoleApp(IDependencyContainer dependencyResolver, int expectedDoneCount = 1)
{ {
this.dependencyResolver = dependencyResolver; this.dependencyResolver = dependencyResolver;
this.expectedDoneCount = expectedDoneCount;
dependencyResolver.RegisterDefault<IExampleState>(() => new ExampleState(this)); dependencyResolver.RegisterDefault<IExampleState>(() => new ExampleState(this));
} }
@ -85,6 +90,7 @@ namespace ExampleLib
internal void Done() internal void Done()
{ {
if (Interlocked.Increment(ref doneCount) == expectedDoneCount)
doneSignal.TrySetResult(true); doneSignal.TrySetResult(true);
} }