Exemple #1
0
        public void RemoveConsumerBetweenSends()
        {
            var dispatcher = new UnicastingDispatcher(provider.GetService <IApplicationContext>());
            var target1    = new CountingTestEndpoint(false);
            var target2    = new CountingTestEndpoint(false);
            var target3    = new CountingTestEndpoint(false);

            dispatcher.AddHandler(target1);
            dispatcher.AddHandler(target2);
            dispatcher.AddHandler(target3);
            try
            {
                dispatcher.Dispatch(Message.Create("test1"));
            }
            catch (Exception)
            {
                // ignore
            }

            Assert.Equal(3, target1.Counter + target2.Counter + target3.Counter);
            dispatcher.RemoveHandler(target2);
            try
            {
                dispatcher.Dispatch(Message.Create("test2"));
            }
            catch (Exception)
            {
                // ignore
            }

            Assert.Equal(5, target1.Counter + target2.Counter + target3.Counter);
            dispatcher.RemoveHandler(target1);
            try
            {
                dispatcher.Dispatch(Message.Create("test3"));
            }
            catch (Exception)
            {
                // ignore
            }

            Assert.Equal(6, target1.Counter + target2.Counter + target3.Counter);
        }
Exemple #2
0
        public void RemoveConsumerLastTargetCausesDeliveryException()
        {
            var dispatcher = new UnicastingDispatcher(provider.GetService <IApplicationContext>());
            var target1    = new CountingTestEndpoint(false);

            dispatcher.AddHandler(target1);
            try
            {
                dispatcher.Dispatch(Message.Create("test1"));
            }
            catch (Exception)
            {
                // ignore
            }

            Assert.Equal(1, target1.Counter);
            dispatcher.RemoveHandler(target1);
            Assert.Throws <MessageDispatchingException>(() => dispatcher.Dispatch(Message.Create("test2")));
        }
        public void RemoveConsumerBeforeSend()
        {
            var dispatcher = new UnicastingDispatcher(provider);
            var target1    = new CountingTestEndpoint(false);
            var target2    = new CountingTestEndpoint(false);
            var target3    = new CountingTestEndpoint(false);

            dispatcher.AddHandler(target1);
            dispatcher.AddHandler(target2);
            dispatcher.AddHandler(target3);
            dispatcher.RemoveHandler(target2);
            try
            {
                dispatcher.Dispatch(new GenericMessage("test"));
            }
            catch (Exception)
            {
                // ignore
            }

            Assert.Equal(2, target1.Counter + target2.Counter + target3.Counter);
        }