Example #1
0
        public async Task Process_CompleteWithError_WhenOutgoingLinkQueueNotFound()
        {
            const string     linkName        = "abcd";
            const string     entity          = "entity";
            ISecurityContext securityContext = Substitute.For <ISecurityContext>();
            IEntityLookup    entityLookup    = Substitute.For <IEntityLookup>();
            ILoggerProvider  loggerProvider  = Substitute.For <ILoggerProvider>();

            Entities.IEntity fakeEntity = Substitute.For <Entities.IEntity>();
            var linkProcessor           = new LinkProcessor(securityContext, entityLookup, loggerProvider);

            fakeEntity.DeliveryQueue.Returns((DeliveryQueue)null);
            entityLookup.Find(Arg.Any <string>()).Returns(fakeEntity);
            securityContext.IsAuthorized(Arg.Any <Connection>()).Returns(true);
            AmqpException exception = null;
            Session       session   = await TestAmqpHost.OpenAndLinkProcessorAsync(linkProcessor);

            try
            {
                var receiver = new ReceiverLink(session, linkName, entity);

                Func <Task> action = async() => await receiver.ReceiveAsync();

                linkProcessor.ShouldSatisfyAllConditions(
                    () => exception = action.ShouldThrow <AmqpException>(),
                    () => exception.Error.Condition.ShouldBe((Symbol)ErrorCode.NotFound),
                    () => exception.Error.Description.ShouldBe("Queue not found.")
                    );
            }
            finally
            {
                await session.Connection.CloseAsync();
            }
        }
Example #2
0
        public async Task Process_CompleteWithError_WhenIncomingLinkEntityNotFound()
        {
            const string     linkName        = "abcd";
            const string     entity          = "entity";
            ISecurityContext securityContext = Substitute.For <ISecurityContext>();
            IEntityLookup    entityLookup    = Substitute.For <IEntityLookup>();
            ILoggerProvider  loggerProvider  = Substitute.For <ILoggerProvider>();
            var linkProcessor = new LinkProcessor(securityContext, entityLookup, loggerProvider);

            entityLookup.Find(Arg.Any <string>()).Returns((Entities.IEntity)null);
            securityContext.IsAuthorized(Arg.Any <Connection>()).Returns(true);
            AmqpException exception = null;
            Session       session   = await TestAmqpHost.OpenAndLinkProcessorAsync(linkProcessor);

            try
            {
                var sender  = new SenderLink(session, linkName, entity);
                var message = new Message
                {
                    Properties = new Properties {
                        MessageId = "message1"
                    },
                    BodySection = new Data {
                        Binary = Encoding.UTF8.GetBytes("hello!")
                    }
                };
                Func <Task> action = async() => await sender.SendAsync(message);

                linkProcessor.ShouldSatisfyAllConditions(
                    () => exception = action.ShouldThrow <AmqpException>(),
                    () => exception.Error.Condition.ShouldBe((Symbol)ErrorCode.NotFound),
                    () => exception.Error.Description.ShouldBe("Entity not found.")
                    );
            }
            finally
            {
                await session.Connection.CloseAsync();
            }
        }
Example #3
0
        public async Task Process_CompleteWithError_WhenLinkNameEmpty()
        {
            const string     emptyLinkName   = "";
            const string     entity          = "entity";
            ISecurityContext securityContext = Substitute.For <ISecurityContext>();
            IEntityLookup    entityLookup    = Substitute.For <IEntityLookup>();
            ILoggerProvider  loggerProvider  = Substitute.For <ILoggerProvider>();
            var           linkProcessor      = new LinkProcessor(securityContext, entityLookup, loggerProvider);
            AmqpException exception          = null;
            Session       session            = await TestAmqpHost.OpenAndLinkProcessorAsync(linkProcessor);

            try
            {
                var sender  = new SenderLink(session, emptyLinkName, entity);
                var message = new Message
                {
                    Properties = new Properties {
                        MessageId = "message1"
                    },
                    BodySection = new Data {
                        Binary = Encoding.UTF8.GetBytes("hello!")
                    }
                };
                Func <Task> action = async() => await sender.SendAsync(message);

                linkProcessor.ShouldSatisfyAllConditions(
                    () => exception = action.ShouldThrow <AmqpException>(),
                    () => exception.Error.Condition.ShouldBe((Symbol)ErrorCode.InvalidField),
                    () => exception.Error.Description.ShouldBe("Empty link name not allowed.")
                    );
            }
            finally
            {
                await session.Connection.CloseAsync();
            }
        }