Ejemplo n.º 1
0
        public void Should_Send_Incoming_Envelopes_Through_the_Chain()
        {
            // create an envelope and context
            Envelope env = new Envelope()
            {
                Payload = Encoding.UTF8.GetBytes("Test")
            };
            EnvelopeContext ctx = new EnvelopeContext(EnvelopeContext.Directions.In, env);

            // mock a transport provider and envelope processor
            Mock <ITransportProvider>  txMock         = _mocker.Create <ITransportProvider>();
            Mock <IEnvelopeProcessor>  procMock       = _mocker.Create <IEnvelopeProcessor>();
            Mock <IEnvelopeDispatcher> dispatcherMock = _mocker.Create <IEnvelopeDispatcher>();

            dispatcherMock.SetupGet <Envelope>(disp => disp.Envelope).Returns(env);

            DefaultEnvelopeBus bus = new DefaultEnvelopeBus(txMock.Object);

            bus.OutboundChain = null;
            bus.InboundChain  = new Dictionary <int, IEnvelopeProcessor>();
            bus.InboundChain.Add(0, procMock.Object);

            txMock.Raise(tx => tx.OnEnvelopeReceived += null, dispatcherMock.Object);

            procMock.Verify(
                proc => proc.ProcessEnvelope(It.IsAny <EnvelopeContext>(), It.IsAny <Action>()), Times.Once());
        }
Ejemplo n.º 2
0
        public void Should_Not_Continue_Processing_If_Processor_Does_Not_Call_Continuation()
        {
            // create an envelope and context
            Envelope env = new Envelope()
            {
                Payload = Encoding.UTF8.GetBytes("Test")
            };
            EnvelopeContext ctx = new EnvelopeContext(EnvelopeContext.Directions.In, env);

            // mock a transport provider and envelope processor
            Mock <ITransportProvider> txMock   = _mocker.Create <ITransportProvider>();
            Mock <IEnvelopeProcessor> procMock = _mocker.Create <IEnvelopeProcessor>();

            // create a processor chain and add the mock processor to it
            List <IEnvelopeProcessor> processorChain = new List <IEnvelopeProcessor>();

            processorChain.Add(procMock.Object);

            // the continuation that, if called, fails the test
            Action continuation = new Action(() =>
                                             Assert.Fail("The continuation action should not have been called"));

            // this is what we're testing (extended class gives public access to protected method)
            ExtendedDefaultEnvelopeBus bus = new ExtendedDefaultEnvelopeBus(txMock.Object);

            bus.PublicProcessEnvelope(ctx, processorChain, continuation);

            // make sure that the processor was called once
            procMock.Verify(proc => proc.ProcessEnvelope(ctx, It.IsAny <Action>()), Times.Once());

            // and that since it did nothing, the transport provider didn't get the envelope
            txMock.Verify(tx => tx.Send(env), Times.Never());
        }
Ejemplo n.º 3
0
        public void ignores_nulls_just_fine()
        {
            var messages = new EnvelopeContext(null, new Envelope {
                Message = new Message1()
            }, null, null);

            messages.EnqueueCascading(null);

            messages.OutgoingMessages().Any().ShouldBeFalse();
        }
Ejemplo n.º 4
0
        public async Task <IInvocationContext> Execute <TMessage>(TMessage message)
        {
            var handler = HandlerFor <TMessage>();

            theEnvelope = new Envelope(message);
            var context = new EnvelopeContext(null, theEnvelope, _runtime.Value.Get <IServiceBus>());

            await handler.Handle(context);

            return(context);
        }
Ejemplo n.º 5
0
        public async Task <IInvocationContext> Execute <TMessage>(TMessage message)
        {
            var handler = HandlerFor <TMessage>();

            theEnvelope = new Envelope(message);
            var context = new EnvelopeContext(null, theEnvelope, null, new InMemoryDelayedJobProcessor());

            await handler.Handle(context);

            return(context);
        }
Ejemplo n.º 6
0
        public async Task <IInvocationContext> Execute <TMessage>(TMessage message)
        {
            var handler = HandlerFor <TMessage>();

            theEnvelope = Envelope.ForMessage(message);
            var context = new EnvelopeContext(null, theEnvelope, null);

            await handler.Handle(context);

            return(context);
        }
Ejemplo n.º 7
0
        public void enqueue_an_oject_array()
        {
            var messages = new EnvelopeContext(null, new Envelope {
                Message = new Message1()
            }, null, null);
            var m1 = new Message1();
            var m2 = new Message2();

            messages.EnqueueCascading(new object[] { m1, m2 });

            messages.OutgoingMessages().ShouldHaveTheSameElementsAs(m1, m2);
        }
Ejemplo n.º 8
0
        public void enqueue()
        {
            var messages = new EnvelopeContext(null, new Envelope {
                Message = new Message1()
            }, null, null);
            var m1 = new Message1();
            var m2 = new Message2();

            messages.EnqueueCascading(m1);
            messages.EnqueueCascading(m2);

            messages.OutgoingMessages().ShouldHaveTheSameElementsAs(m1, m2);
        }
Ejemplo n.º 9
0
 public void PublicProcessEnvelope(EnvelopeContext context, IEnumerable <IEnvelopeProcessor> processorChain, Action processingComplete)
 {
     this.ProcessEnvelope(context, processorChain, processingComplete);
 }