Esempio n. 1
0
        public async Task ShouldProcessMessage()
        {
            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <Messages.IEvent>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened();
        }
        public async Task ShouldUnpackLocalDelivery()
        {
            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.Extensions.Set(Defaults.LocalHeader, Fake <IFullMessage>());
            context.UpdateMessageInstance(Fake <IFullMessage>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened();
        }
Esempio n. 3
0
        public async Task ShouldNotAcceptIfNoResponseRequested()
        {
            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <ICommand>());
            context.MessageHeaders[Defaults.RequestResponse] = "0";

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened();
            context.RepliedMessages.Should().BeEmpty();
        }
        public async Task ShouldUnpackBulkMessage()
        {
            var message = new Internal.BulkMessage
            {
                Messages = Many <IFullMessage>()
            };
            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(message);

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened(3, Times.Exactly);
        }
Esempio n. 5
0
        public async Task ShouldReplyToCommand()
        {
            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <ICommand>());
            context.MessageHeaders[Defaults.RequestResponse] = "1";
            context.Builder.Register <Action <Accept> >(A.Fake <Action <Accept> >());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened();
            context.RepliedMessages.Should().NotBeEmpty();
            context.RepliedMessages[0].Message.Should().BeAssignableTo <Accept>();
        }
Esempio n. 6
0
        public async Task ShouldMutateMessage()
        {
            var mutator = new FakeMutator();

            A.CallTo(() => Configuration.Settings.Container.Resolve(A <Type> .Ignored)).Returns(mutator);
            MutationManager.RegisterMutator("test", typeof(FakeMutator));

            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <Messages.IEvent>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened();
            mutator.MutatedIncoming.Should().BeTrue();
        }
Esempio n. 7
0
        public async Task ShouldNotQueueRetryOnBusinessException()
        {
            var retrier = A.Fake <Internal.DelayedRetry>();

            Inject(retrier);
            var next = A.Fake <Func <Task> >();

            A.CallTo(() => next()).Throws <BusinessException>();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <Messages.IEvent>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => retrier.QueueRetry(A <IFullMessage> .Ignored, A <TimeSpan> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => next()).MustHaveHappened();
        }
Esempio n. 8
0
        public async Task ShouldAddRetryHeader()
        {
            var next = A.Fake <Func <Task> >();

            A.CallTo(() => next()).Throws <Exception>();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <Messages.IEvent>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            context.Extensions.Get <int>(Defaults.Retries).Should().Be(0);

            await Sut.Invoke(context, next).ConfigureAwait(false);

            context.Extensions.Get <int>(Defaults.Retries).Should().Be(1);
        }
Esempio n. 9
0
        public async Task ShouldRejectCommand()
        {
            var next = A.Fake <Func <Task> >();

            A.CallTo(() => next()).Throws <BusinessException>();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <ICommand>());
            context.MessageHeaders[Defaults.RequestResponse] = "1";
            context.Builder.Register <Action <BusinessException, Reject> >(A.Fake <Action <BusinessException, Reject> >());

            var e = await Record.ExceptionAsync(() => Sut.Invoke(context, next)).ConfigureAwait(false);

            e.Should().BeOfType <BusinessException>();
            context.RepliedMessages.Should().NotBeEmpty();
            context.RepliedMessages[0].Message.Should().BeAssignableTo <Reject>();
        }
        public async Task ShouldUnpackBulkHeader()
        {
            var message = Fake <IFullMessage>();

            A.CallTo(() => message.Headers).Returns(new Dictionary <string, string> {
                [Defaults.ChannelKey] = "test"
            });
            Inject(message);
            var next    = A.Fake <Func <Task> >();
            var context = new TestableIncomingLogicalMessageContext();

            context.UpdateMessageInstance(Fake <int>());
            context.Extensions.Set(Defaults.BulkHeader, Many <IFullMessage>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => next()).MustHaveHappened(3, Times.Exactly);
        }
Esempio n. 11
0
        public async Task ShouldNotSendErrorReplyIfNotSendOrPublish()
        {
            Configuration.Settings.Retries = 0;
            var retrier = A.Fake <Internal.DelayedRetry>();

            Inject(retrier);
            var next = A.Fake <Func <Task> >();

            A.CallTo(() => next()).Throws <Exception>();
            var context = new TestableIncomingLogicalMessageContext();

            context.MessageHeaders[Headers.MessageIntent]    = MessageIntentEnum.Reply.ToString();
            context.MessageHeaders[Defaults.RequestResponse] = "1";
            context.UpdateMessageInstance(Fake <Messages.IEvent>());

            await Sut.Invoke(context, next).ConfigureAwait(false);

            A.CallTo(() => retrier.QueueRetry(A <IFullMessage> .Ignored, A <TimeSpan> .Ignored)).MustNotHaveHappened();
            context.RepliedMessages.Should().BeEmpty();
        }
Esempio n. 12
0
        public async Task ShouldReplyWithErrorAfterMaxRetries()
        {
            Configuration.Settings.Retries = 0;
            var retrier = A.Fake <Internal.DelayedRetry>();

            Inject(retrier);
            var next = A.Fake <Func <Task> >();

            A.CallTo(() => next()).Throws <Exception>();
            var context = new TestableIncomingLogicalMessageContext();

            context.MessageHeaders[Headers.MessageIntent]    = MessageIntentEnum.Send.ToString();
            context.MessageHeaders[Defaults.RequestResponse] = "1";
            context.UpdateMessageInstance(Fake <Messages.IEvent>());
            context.Builder.Register <Func <Exception, string, Error> >(A.Fake <Func <Exception, string, Error> >());

            var e = await Record.ExceptionAsync(() => Sut.Invoke(context, next)).ConfigureAwait(false);

            e.Should().BeOfType <Exception>();
            A.CallTo(() => retrier.QueueRetry(A <IFullMessage> .Ignored, A <TimeSpan> .Ignored)).MustNotHaveHappened();
            context.RepliedMessages.Should().NotBeEmpty();
            context.RepliedMessages[0].Message.Should().BeAssignableTo <Messages.Error>();
        }