Ejemplo n.º 1
0
        public void DualSendMessageTest()
        {
            MessageBus bus       = new MessageBus();
            var        singleSub = new MockSingleSubscriber();

            bus.Subscribe(singleSub);
            var dualSub = new MockDualSubscriber();

            bus.Subscribe(dualSub);

            StatusMsg statusMsg = new StatusMsg()
            {
                Text = "Test"
            };

            bus.SendMessage(statusMsg);

            Assert.That(singleSub.StatusMsgs[0], Is.EqualTo(statusMsg));
            Assert.That(dualSub.StatusMsgs[0], Is.EqualTo(statusMsg));

            ResetMsg resetMsg = new ResetMsg()
            {
                Reason = "Test2"
            };

            bus.SendMessage(resetMsg);

            Assert.That(singleSub.StatusMsgs.Count, Is.EqualTo(1));
            Assert.That(dualSub.StatusMsgs.Count, Is.EqualTo(1));

            Assert.That(dualSub.ResetMsgs.Count, Is.EqualTo(1));
        }
Ejemplo n.º 2
0
        public void UnsubscribeTest()
        {
            MessageBus bus       = new MessageBus();
            var        singleSub = new MockSingleSubscriber();
            var        dualSub   = new MockDualSubscriber();

            bus.Subscribe(singleSub);
            bus.Subscribe(dualSub);
            bus.Unsubscribe(singleSub);

            var statSubs  = bus.GetSubscribers(typeof(StatusMsg));
            var resetSubs = bus.GetSubscribers(typeof(ResetMsg));

            Assert.That(statSubs.Count, Is.EqualTo(1));
            Assert.That(resetSubs.Count, Is.EqualTo(1));

            bus.Unsubscribe(dualSub);
            statSubs  = bus.GetSubscribers(typeof(StatusMsg));
            resetSubs = bus.GetSubscribers(typeof(ResetMsg));
            Assert.That(statSubs.Count, Is.EqualTo(0));
            Assert.That(resetSubs.Count, Is.EqualTo(0));
        }