public void PreSendInterceptorReturningModifiedMessage() { var expected = new Mock <IMessage>().Object; var interceptor = new PreSendInterceptor(); interceptor.MessageToReturn = expected; channel.AddInterceptor(interceptor); channel.Send(MessageBuilder.WithPayload("test").Build()); Assert.Single(messageHandler.Messages); var result = messageHandler.Messages[0]; Assert.NotNull(result); Assert.Same(expected, result); Assert.True(interceptor.WasAfterCompletionInvoked); }
public void PreSendInterceptorReturningNull() { var interceptor1 = new PreSendInterceptor(); var interceptor2 = new NullReturningPreSendInterceptor(); channel.AddInterceptor(interceptor1); channel.AddInterceptor(interceptor2); var message = MessageBuilder.WithPayload("test").Build(); channel.Send(message); Assert.Equal(1, interceptor1.Counter); Assert.Equal(1, interceptor2.Counter); Assert.Empty(messageHandler.Messages); Assert.True(interceptor1.WasAfterCompletionInvoked); Assert.False(interceptor2.WasAfterCompletionInvoked); }
public void AfterCompletionWithPreSendException() { var interceptor1 = new PreSendInterceptor(); var interceptor2 = new PreSendInterceptor(); interceptor2.ExceptionToRaise = new Exception("Simulated exception"); channel.AddInterceptor(interceptor1); channel.AddInterceptor(interceptor2); try { channel.Send(MessageBuilder.WithPayload("test").Build()); } catch (Exception ex) { Assert.Equal("Simulated exception", ex.InnerException.Message); } Assert.True(interceptor1.WasAfterCompletionInvoked); Assert.False(interceptor2.WasAfterCompletionInvoked); }
public void AfterCompletionWithSendException() { AbstractMessageChannel testChannel = new AfterCompletionWithSendExceptionChannel(); var interceptor1 = new PreSendInterceptor(); var interceptor2 = new PreSendInterceptor(); testChannel.AddInterceptor(interceptor1); testChannel.AddInterceptor(interceptor2); try { testChannel.Send(MessageBuilder.WithPayload("test").Build()); } catch (Exception ex) { Assert.Equal("Simulated exception", ex.InnerException.Message); } Assert.True(interceptor1.WasAfterCompletionInvoked); Assert.True(interceptor2.WasAfterCompletionInvoked); }