public void The_pipeline_should_have_insertable_items()
        {
            // two consumers, one for each type of message

            IndiscriminantConsumer <PingMessage> pingConsumer = new IndiscriminantConsumer <PingMessage>();
            IndiscriminantConsumer <PongMessage> pongConsumer = new IndiscriminantConsumer <PongMessage>();

            UnsubscribeAction pingToken = _pipeline.Subscribe(pingConsumer);
            UnsubscribeAction pongToken = _pipeline.Subscribe(pongConsumer);

            PipelineViewer.Trace(_pipeline);

            PingMessage pingMessage = new PingMessage();
            PongMessage pongMessage = new PongMessage();

            _pipeline.Dispatch(pingMessage, accept => true);
            _pipeline.Dispatch(pongMessage, accept => true);

            Assert.AreEqual(pingMessage, pingConsumer.Consumed);
            Assert.AreEqual(pongMessage, pongConsumer.Consumed);

            pingToken();
            pongToken();

            PipelineViewer.Trace(_pipeline);
        }
        public bool Visit <TMessage>(IndiscriminantConsumer <TMessage> obj)
            where TMessage : class
        {
            Trace.WriteLine("IndiscriminantConsumer<TMessage> - " + typeof(TMessage));

            return(true);
        }
Example #3
0
        public void The_pipeline_should_be_happy()
        {
            var consumer = new IndiscriminantConsumer <PingMessage>();

            _pipeline.ConnectInstance(consumer);

            _pipeline.Dispatch(new PingMessage());

            Assert.IsNotNull(consumer.Consumed);
        }
        public void The_subscriptions_should_be_a_separate_concern_from_the_pipeline()
        {
            IndiscriminantConsumer <PingMessage> consumer = new IndiscriminantConsumer <PingMessage>();

            _pipeline.Subscribe(consumer);

            PingMessage message = new PingMessage();

            _pipeline.Dispatch(message, x => true);

            Assert.AreEqual(message, consumer.Consumed);
        }
        public void The_appropriate_handler_should_be_added()
        {
            IndiscriminantConsumer <PingMessage> consumer = new IndiscriminantConsumer <PingMessage>();

            _pipeline.Subscribe(consumer);

            PingMessage message = new PingMessage();

            _pipeline.Dispatch(message, x => true);

            Assert.AreEqual(message, consumer.Consumed);
        }
        public void The_wrong_type_of_message_should_not_blow_up_the_test()
        {
            IndiscriminantConsumer <PingMessage> consumer = new IndiscriminantConsumer <PingMessage>();

            _pipeline.ConnectInstance(consumer);

            PongMessage message = new PongMessage();

            _pipeline.Dispatch(message);

            Assert.AreEqual(null, consumer.Consumed);
        }
        public void When_somebody_gets_the_message_it_should_be_accepted()
        {
            IndiscriminantConsumer <PingMessage> consumer = new IndiscriminantConsumer <PingMessage>();

            _pipeline.Subscribe(consumer);

            PingMessage message = new PingMessage();

            bool accepted = false;

            _pipeline.Dispatch(message, x => accepted = true);

            Assert.IsTrue(accepted);
        }
        public void The_subscription_should_be_added()
        {
            IndiscriminantConsumer <PingMessage> consumer = new IndiscriminantConsumer <PingMessage>();

            Stopwatch firstTime = Stopwatch.StartNew();

            _pipeline.ConnectInstance(consumer);
            firstTime.Stop();


            PingMessage message = new PingMessage();

            _pipeline.Dispatch(message);

            Assert.AreEqual(message, consumer.Consumed);
        }
        public void A_bunch_of_mixed_subscriber_types_should_work()
        {
            IndiscriminantConsumer <PingMessage> consumer = new IndiscriminantConsumer <PingMessage>();
            ParticularConsumer consumerYes = new ParticularConsumer(true);
            ParticularConsumer consumerNo  = new ParticularConsumer(false);

            Stopwatch firstTime        = Stopwatch.StartNew();
            var       unsubscribeToken = _pipeline.ConnectInstance(consumer);

            firstTime.Stop();

            Stopwatch secondTime = Stopwatch.StartNew();

            unsubscribeToken += _pipeline.ConnectInstance(consumerYes);
            secondTime.Stop();

            unsubscribeToken += _pipeline.ConnectInstance(consumerNo);

            Trace.WriteLine(string.Format("First time: {0}, Second Time: {1}", firstTime.Elapsed, secondTime.Elapsed));

            PipelineViewer.Trace(_pipeline);

            PingMessage message = new PingMessage();

            _pipeline.Dispatch(message);

            Assert.AreEqual(message, consumer.Consumed);
            Assert.AreEqual(message, consumerYes.Consumed);
            Assert.AreEqual(null, consumerNo.Consumed);

            unsubscribeToken();

            PingMessage nextMessage = new PingMessage();

            _pipeline.Dispatch(nextMessage);

            Assert.AreEqual(message, consumer.Consumed);
            Assert.AreEqual(message, consumerYes.Consumed);
        }
        public bool Visit(IndiscriminantConsumer <PingMessage> obj)
        {
            Trace.WriteLine("IndiscriminantConsumer<PingMessage>");

            return(true);
        }