public void CanSubscribeMultipleTargets() { var bus = new DirectDispatchMessageBus(); var target1 = new SingleSubscriber(); var target2 = new SingleSubscriber(); bus.Subscribe(target1); bus.Subscribe(target2); var message = new TestMessage(); bus.Publish(message); Assert.That(target1.LastMessage, Is.SameAs(message)); Assert.That(target2.LastMessage, Is.SameAs(message)); }
public void CollectedTargetIsUnsubscribed() { var bus = new DirectDispatchMessageBus(); bus.Subscribe(new SingleSubscriber()); GC.Collect(); var message = new TestMessage(); bus.Publish(message); Assert.That(message.LastReceiver, Is.Null); }
public void CanUnsubscribe() { var bus = new DirectDispatchMessageBus(); var target = new SingleSubscriber(); bus.Subscribe(target); bus.Unsubscribe(target); var message = new TestMessage(); bus.Publish(message); Assert.That(message.LastReceiver, Is.Null); }
public void SameTargetCanOnlySubscribeOnce() { var bus = new DirectDispatchMessageBus(); var target = new SingleSubscriber(); bus.Subscribe(target); bus.Subscribe(target); bus.Publish<TestMessage>(); Assert.That(target.ReceivedMessages, Is.EqualTo(1)); }
public void CanSubscribeWithoutHandlerMethod() { var bus = new DirectDispatchMessageBus(); Assert.DoesNotThrow(() => bus.Subscribe(new string('s', 10))); }
public void MessagesAreHandledInPolymorphicFashion() { var bus = new DirectDispatchMessageBus(); var target = new PolySubscriber(); bus.Subscribe(target); bus.Publish<DerivedTestMessage>(); Assert.That(target.MessageHandleCount, Is.EqualTo(2)); Assert.That(target.HandledMessageTypes.Contains(typeof(TestMessage))); Assert.That(target.HandledMessageTypes.Contains(typeof(DerivedTestMessage))); }
public void CanSubscribe() { var bus = new DirectDispatchMessageBus(); Assert.DoesNotThrow(() => bus.Subscribe(new SingleSubscriber())); }