public void Should_Send_Outgoing_Envelopes_Through_the_Chain() { // create an envelope Envelope env = new Envelope() { Payload = Encoding.UTF8.GetBytes("Test") }; // mock a transport provider and envelope processor Mock<ITransportProvider> txMock = _mocker.Create<ITransportProvider>(); Mock<IEnvelopeProcessor> procMock = _mocker.Create<IEnvelopeProcessor>(); // setup the processor to call its continuation procMock .Setup( proc => proc.ProcessEnvelope(It.IsAny<EnvelopeContext>(), It.IsAny<Action>())) .Callback<EnvelopeContext, Action>( (newCtx, continuation) => continuation()); // create the unit under test and give it the transport provider and processor chain DefaultEnvelopeBus bus = new DefaultEnvelopeBus(txMock.Object); bus.OutboundChain = new Dictionary<int, IEnvelopeProcessor>(); bus.OutboundChain.Add(0, procMock.Object); // send the envelope bus.Send(env); // verify the expected calls procMock.Verify( proc => proc.ProcessEnvelope(It.IsAny<EnvelopeContext>(), It.IsAny<Action>()), Times.Once()); txMock.Verify(tx => tx.Send(env), Times.Once()); }
public void Should_Send_Envelopes_Even_When_OutboundChain_Is_Null() { Envelope env = new Envelope() { Payload = Encoding.UTF8.GetBytes("Test") }; Mock<ITransportProvider> txMock = _mocker.Create<ITransportProvider>(); DefaultEnvelopeBus bus = new DefaultEnvelopeBus(txMock.Object); bus.InboundChain = null; bus.OutboundChain = null; bus.Send(env); txMock.Verify(tx => tx.Send(env), Times.Once()); }