sticking send messages toself in to make this testable

This commit is contained in:
Tom Gardham-Pallister 2018-05-05 10:38:47 +01:00
parent 4c405f0f29
commit 17a515c4c0
2 changed files with 45 additions and 0 deletions

View File

View File

@ -0,0 +1,45 @@
using System.Threading.Tasks;
using Shouldly;
using Xunit;
namespace Ocelot.UnitTests.Infrastructure
{
public class InMemoryBusTests
{
private InMemoryBus<Message> _bus;
public InMemoryBusTests()
{
_bus = new InMemoryBus<Message>();
}
[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
{
}
}
}