From 17a515c4c0de6075a97001fc064cf4ecb32e2c73 Mon Sep 17 00:00:00 2001 From: Tom Gardham-Pallister Date: Sat, 5 May 2018 10:38:47 +0100 Subject: [PATCH] sticking send messages toself in to make this testable --- src/Ocelot/Infrastructure/InMemoryBus.cs | 0 .../Infrastructure/InMemoryBusTests.cs | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/Ocelot/Infrastructure/InMemoryBus.cs create mode 100644 test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs diff --git a/src/Ocelot/Infrastructure/InMemoryBus.cs b/src/Ocelot/Infrastructure/InMemoryBus.cs new file mode 100644 index 00000000..e69de29b diff --git a/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs b/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs new file mode 100644 index 00000000..918cfb9f --- /dev/null +++ b/test/Ocelot.UnitTests/Infrastructure/InMemoryBusTests.cs @@ -0,0 +1,45 @@ +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace Ocelot.UnitTests.Infrastructure +{ + public class InMemoryBusTests + { + private InMemoryBus _bus; + + public InMemoryBusTests() + { + _bus = new InMemoryBus(); + } + + [Fact] + public async Task should_publish_with_delay() + { + var called = false; + _bus.Subscribe(x => { + called = true; + }); + await _bus.Publish(new Message(), 1); + await Task.Delay(10); + called.ShouldBeTrue(); + } + + [Fact] + public async Task should_not_be_publish_yet_as_no_delay_in_caller() + { + var called = false; + _bus.Subscribe(x => { + called = true; + }); + await _bus.Publish(new Message(), 1); + called.ShouldBeFalse(); + } + + + class Message + { + + } + } +}