コード例 #1
0
        public void GivenSubscriber_WhenPost_ShouldSendEventToSubscriber()
        {
            var @event     = new TestEvent("One");
            var subscriber = new TestEventSubscriber();

            var bus = new SimpleBus();

            bus.Register(subscriber);
            bus.Post(@event);

            Assert.Single(subscriber.Events);
        }
コード例 #2
0
        public void GivenMultipleSubscribers_WhenPost_ShouldSentEventToAllSubscribers()
        {
            var @event      = new TestEvent("One");
            var subscriber1 = new TestEventSubscriber();
            var subscriber2 = new TestEventSubscriber();

            var bus = new SimpleBus();

            bus.Register(subscriber1)
            .Register(subscriber2);
            bus.Post(@event);

            Assert.Single(subscriber1.Events);
            Assert.Single(subscriber2.Events);
        }
コード例 #3
0
        public void GivenSubscriber_WhenUnregister_ShouldNoLongerReceiveEvents()
        {
            var @event     = new TestEvent("One");
            var subscriber = new TestEventSubscriber();

            var bus = new SimpleBus();

            bus.Register(subscriber);
            bus.Post(@event);

            Assert.Single(subscriber.Events);

            bus.Unregister(subscriber);
            bus.Post(@event);

            Assert.Single(subscriber.Events);
        }