Пример #1
0
        public async Task Should_not_call_MutateIncoming_when_hasIncomingTransportMessageMutators_is_false()
        {
            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages>());

            var context = new TestableIncomingPhysicalMessageContext();

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            var mutator = new MutatorThatIndicatesIfItWasCalled();

            context.Builder.Register <IMutateIncomingTransportMessages>(() => mutator);

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            Assert.IsFalse(mutator.MutateIncomingCalled);
        }
Пример #2
0
        public void Should_throw_friendly_exception_when_IMutateIncomingTransportMessages_MutateIncoming_returns_null()
        {
            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages>());

            var context = new TestableIncomingPhysicalMessageContext();

            context.Builder.Register <IMutateIncomingTransportMessages>(() => new MutateIncomingTransportMessagesReturnsNull());

            Assert.That(async() => await behavior.Invoke(context, ctx => TaskEx.CompletedTask), Throws.Exception.With.Message.EqualTo("Return a Task or mark the method as async."));
        }
Пример #3
0
        public async Task When_no_mutator_available_should_not_update_the_body()
        {
            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages>());

            var context = new InterceptUpdateMessageIncomingPhysicalMessageContext();

            context.Builder.Register(() => new IMutateIncomingTransportMessages[] { });

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            Assert.False(context.UpdateMessageBodyCalled);
        }
Пример #4
0
        public async Task When_mutator_modifies_the_body_should_update_the_body()
        {
            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages>());

            var context = new InterceptUpdateMessageIncomingPhysicalMessageContext();

            context.Builder.Register <IMutateIncomingTransportMessages>(() => new MutatorWhichMutatesTheBody());

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            Assert.True(context.UpdateMessageBodyCalled);
        }
Пример #5
0
        public async Task When_no_mutator_updates_the_body_should_not_update_the_body()
        {
            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages>());

            var context = new InterceptUpdateMessageIncomingPhysicalMessageContext();

            context.Services.AddTransient <IMutateIncomingTransportMessages>(sp => new MutatorWhichDoesNotMutateTheBody());

            await behavior.Invoke(context, ctx => Task.CompletedTask);

            Assert.False(context.UpdateMessageBodyCalled);
        }
Пример #6
0
        public async Task When_no_mutator_updates_the_body_should_not_update_the_body()
        {
            var behavior = new MutateIncomingTransportMessageBehavior(hasIncomingTransportMessageMutators: true);

            var context = new InterceptUpdateMessageIncomingPhysicalMessageContext();

            context.Builder.Register <IMutateIncomingTransportMessages>(() => new MutatorWhichDoesNotMutateTheBody());

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            Assert.False(context.UpdateMessageBodyCalled);
        }
Пример #7
0
        public async Task Should_invoke_all_explicit_mutators()
        {
            var mutator      = new MutatorThatIndicatesIfItWasCalled();
            var otherMutator = new MutatorThatIndicatesIfItWasCalled();

            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages> {
                mutator, otherMutator
            });

            var context = new TestableIncomingPhysicalMessageContext();

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            Assert.True(mutator.MutateIncomingCalled);
            Assert.True(otherMutator.MutateIncomingCalled);
        }
Пример #8
0
        public async Task Should_invoke_both_explicit_and_container_provided_mutators()
        {
            var explicitMutator  = new MutatorThatIndicatesIfItWasCalled();
            var containerMutator = new MutatorThatIndicatesIfItWasCalled();

            var behavior = new MutateIncomingTransportMessageBehavior(new HashSet <IMutateIncomingTransportMessages> {
                explicitMutator
            });

            var context = new TestableIncomingPhysicalMessageContext();

            context.Builder.Register <IMutateIncomingTransportMessages>(() => containerMutator);

            await behavior.Invoke(context, ctx => TaskEx.CompletedTask);

            Assert.True(explicitMutator.MutateIncomingCalled);
            Assert.True(containerMutator.MutateIncomingCalled);
        }