Beispiel #1
0
        public async Task Should_not_call_MutateIncoming_when_hasIncomingMessageMutators_is_false()
        {
            var behavior = new MutateIncomingMessageBehavior(new HashSet <IMutateIncomingMessages>());

            var context = new TestableIncomingLogicalMessageContext();

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

            var mutator = new MutatorThatIndicatesIfItWasCalled();

            context.Services.AddTransient <IMutateIncomingMessages>(sp => mutator);

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

            Assert.IsFalse(mutator.MutateIncomingCalled);
        }
        public async Task Should_not_call_MutateIncoming_when_hasIncomingMessageMutators_is_false()
        {
            var behavior = new MutateIncomingMessageBehavior();

            var context = new TestableIncomingLogicalMessageContext();

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

            var mutator = new MutatorThatIndicatesIfItWasCalled();

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

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

            Assert.IsFalse(mutator.MutateIncomingCalled);
        }
        public async Task When_mutator_modifies_the_body_should_update_the_body()
        {
            var behavior = new MutateIncomingMessageBehavior();

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

            context.Builder.Register <IMutateIncomingMessages>(() => 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 MutateIncomingMessageBehavior();

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

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

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

            Assert.False(context.UpdateMessageCalled);
        }
        public async Task When_no_mutator_updates_the_body_should_not_update_the_body()
        {
            var behavior = new MutateIncomingMessageBehavior(new HashSet <IMutateIncomingMessages>());

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

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

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

            Assert.False(context.UpdateMessageCalled);
        }
Beispiel #6
0
        public async Task When_mutator_modifies_the_body_should_update_the_body()
        {
            var behavior = new MutateIncomingMessageBehavior(new HashSet <IMutateIncomingMessages>());

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

            context.Services.AddTransient <IMutateIncomingMessages>(sp => new MutatorWhichMutatesTheBody());

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

            Assert.True(context.UpdateMessageCalled);
        }
Beispiel #7
0
        public async Task When_no_mutator_available_should_not_update_the_body()
        {
            var behavior = new MutateIncomingMessageBehavior(new HashSet <IMutateIncomingMessages>());

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

            context.Services.AddTransient(sp => new IMutateIncomingMessages[] { });

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

            Assert.False(context.UpdateMessageCalled);
        }
        public async Task When_mutator_modifies_the_body_should_update_the_body()
        {
            var behavior = new MutateIncomingMessageBehavior(hasIncomingMessageMutators: true);

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

            context.Builder.Register<IMutateIncomingMessages>(() => 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 MutateIncomingMessageBehavior(hasIncomingMessageMutators: true);

            var context = new InterceptUpdateMessageIncomingLogicalMessageContext();

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

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

            Assert.False(context.UpdateMessageCalled);
        }
        public async Task Should_not_call_MutateIncoming_when_hasIncomingMessageMutators_is_false()
        {
            var behavior = new MutateIncomingMessageBehavior(hasIncomingMessageMutators: false);

            var context = new TestableIncomingLogicalMessageContext();

            var mutator = new MutatorThatIndicatesIfItWasCalled();
            context.Builder.Register<IMutateIncomingMessages>(() => mutator);

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

            Assert.IsFalse(mutator.MutateIncomingCalled);
        }
        public void Should_throw_friendly_exception_when_IMutateIncomingMessages_MutateIncoming_returns_null()
        {
            var behavior = new MutateIncomingMessageBehavior();

            var logicalMessage = new LogicalMessage(new MessageMetadata(typeof(TestMessage)), new TestMessage());

            var context = new TestableIncomingLogicalMessageContext
            {
                Message = logicalMessage
            };

            context.Builder.Register <IMutateIncomingMessages>(() => new MutateIncomingMessagesReturnsNull());

            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 void Should_throw_friendly_exception_when_IMutateIncomingMessages_MutateIncoming_returns_null()
        {
            var behavior = new MutateIncomingMessageBehavior(hasIncomingMessageMutators: true);

            var logicalMessage = new LogicalMessage(new MessageMetadata(typeof(TestMessage)), new TestMessage());

            var context = new TestableIncomingLogicalMessageContext
            {
                Message = logicalMessage
            };

            context.Builder.Register<IMutateIncomingMessages>(() => new MutateIncomingMessagesReturnsNull());

            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 Should_invoke_all_explicit_mutators()
        {
            var mutator      = new MutatorThatIndicatesIfItWasCalled();
            var otherMutator = new MutatorThatIndicatesIfItWasCalled();

            var behavior = new MutateIncomingMessageBehavior(new HashSet <IMutateIncomingMessages> {
                mutator, otherMutator
            });

            var context = new TestableIncomingLogicalMessageContext();

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

            Assert.True(mutator.MutateIncomingCalled);
            Assert.True(otherMutator.MutateIncomingCalled);
        }
        public async Task Should_invoke_both_explicit_and_container_provided_mutators()
        {
            var explicitMutator  = new MutatorThatIndicatesIfItWasCalled();
            var containerMutator = new MutatorThatIndicatesIfItWasCalled();

            var behavior = new MutateIncomingMessageBehavior(new HashSet <IMutateIncomingMessages> {
                explicitMutator
            });

            var context = new TestableIncomingLogicalMessageContext();

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

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

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