public void SubscribeAndPublish_CurrentThread() { var target = new MessageBus(); bool ok = false; target.Subscribe <TestPubSubEvent>(builder => builder .WithTopic("Test") .Invoke(e => ok = true) .OnThread(Thread.CurrentThread.ManagedThreadId)); target.Publish("Test", typeof(TestPubSubEvent), new TestPubSubEvent("Test2")); target.GetEventLoop().EmptyActionQueue(1); ok.Should().BeTrue(); }
public void RunEventLoop_Test() { var target = new MessageBus(); var threadId = Thread.CurrentThread.ManagedThreadId; var result = 0; target.Subscribe <int>(b => b.WithDefaultTopic().Invoke(i => result = i).OnThread(threadId)); target.Publish(5); result.Should().Be(0); int iterations = 0; target.GetEventLoop().Run(() => iterations++ != 0); result.Should().Be(5); }