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()); }
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()); }