public async Task Should_support_disconnection() { ISupervisor <SimpleContext> supervisor = new PipeContextSupervisor <SimpleContext>(new SimpleContextFactory()); int count = 0; string lastValue = string.Empty; var pipe = Pipe.New <SimpleContext>(x => x.UseExecute(context => { if (Interlocked.Increment(ref count) % 2 == 0) { context.Invalidate(); } lastValue = context.Value; })); await supervisor.Send(pipe); await supervisor.Send(pipe); await supervisor.Send(pipe); Assert.That(lastValue, Is.EqualTo("2")); Assert.That(count, Is.EqualTo(3)); await supervisor.Stop(); await supervisor.Completed.UntilCompletedOrTimeout(TimeSpan.FromSeconds(5)); }
public async Task Should_allow_active_instances() { ISupervisor <SimpleContext> supervisor = new PipeContextSupervisor <SimpleContext>(new SimpleContextFactory()); int count = 0; string lastValue = string.Empty; var pipe = Pipe.New <SimpleContext>(x => x.UseExecute(context => { if (Interlocked.Increment(ref count) % 2 == 0) { throw new IntentionalTestException("It's odd that we throw when it's even."); } lastValue = context.Value; })); await supervisor.Send(pipe); Assert.That(async() => await supervisor.Send(pipe), Throws.TypeOf <IntentionalTestException>()); await supervisor.Send(pipe); Assert.That(lastValue, Is.EqualTo("2")); Assert.That(count, Is.EqualTo(3)); await supervisor.Stop(); await supervisor.Completed.UntilCompletedOrTimeout(TimeSpan.FromSeconds(5)); }