public void Should_throw_friendly_exception_when_IMutateOutgoingMessages_MutateOutgoing_returns_null() { var behavior = new MutateOutgoingMessageBehavior(hasOutgoingMessageMutators: true); var context = new TestableOutgoingLogicalMessageContext(); context.Extensions.Set(new IncomingMessage("messageId", new Dictionary<string, string>(), new byte[0])); context.Extensions.Set(new LogicalMessage(null, null)); context.Builder.Register<IMutateOutgoingMessages>(() => new MutateOutgoingMessagesReturnsNull()); Assert.That(async () => await behavior.Invoke(context, ctx => TaskEx.CompletedTask), Throws.Exception.With.Message.EqualTo("Return a Task or mark the method as async.")); }
public async Task When_mutator_modifies_the_body_should_update_the_body() { var behavior = new MutateOutgoingMessageBehavior(hasOutgoingMessageMutators: true); var context = new InterceptUpdateMessageOutgoingLogicalMessageContext(); context.Builder.Register<IMutateOutgoingMessages>(() => new MutatorWhichMutatesTheBody()); await behavior.Invoke(context, ctx => TaskEx.CompletedTask); Assert.True(context.UpdateMessageCalled); }
public async Task When_no_mutator_available_should_not_update_the_body() { var behavior = new MutateOutgoingMessageBehavior(hasOutgoingMessageMutators: true); var context = new InterceptUpdateMessageOutgoingLogicalMessageContext(); context.Builder.Register(() => new IMutateOutgoingMessages[] { }); await behavior.Invoke(context, ctx => TaskEx.CompletedTask); Assert.False(context.UpdateMessageCalled); }
public async Task Should_not_call_MutateOutgoing_when_hasOutgoingMessageMutators_is_false() { var behavior = new MutateOutgoingMessageBehavior(hasOutgoingMessageMutators: false); var context = new TestableOutgoingLogicalMessageContext(); var mutator = new MutatorThatIndicatesIfItWasCalled(); context.Builder.Register<IMutateOutgoingMessages>(() => mutator); await behavior.Invoke(context, ctx => TaskEx.CompletedTask); Assert.IsFalse(mutator.MutateOutgoingCalled); }
public async Task Should_invoke_both_explicit_and_container_provided_mutators() { var explicitMutator = new MutatorThatIndicatesIfItWasCalled(); var containerMutator = new MutatorThatIndicatesIfItWasCalled(); var behavior = new MutateOutgoingMessageBehavior(new HashSet <IMutateOutgoingMessages> { explicitMutator }); var context = new TestableOutgoingLogicalMessageContext(); context.Builder.Register <IMutateOutgoingMessages>(() => containerMutator); await behavior.Invoke(context, ctx => TaskEx.CompletedTask); Assert.True(explicitMutator.MutateOutgoingCalled); Assert.True(containerMutator.MutateOutgoingCalled); }