Exemplo n.º 1
0
        public void ToMessageTest_InterfaceId()
        {
            // Arrange
            IMessage receivedMessage;

            byte[] bytes         = { 1, 2, 3, 4 };
            string messageId     = Guid.NewGuid().ToString();
            string correlationId = Guid.NewGuid().ToString();

            using (AmqpMessage amqpMessage = AmqpMessage.Create(new Data {
                Value = new ArraySegment <byte>(bytes)
            }))
            {
                amqpMessage.Properties.MessageId       = messageId;
                amqpMessage.Properties.CorrelationId   = correlationId;
                amqpMessage.Properties.ContentType     = "application/json";
                amqpMessage.Properties.ContentEncoding = "UTF-8";

                amqpMessage.MessageAnnotations.Map[SystemProperties.InterfaceId] = "InterfaceId1";
                var messageConverter = new AmqpMessageConverter();

                // Act
                receivedMessage = messageConverter.ToMessage(amqpMessage);
            }

            // Assert
            Assert.NotNull(receivedMessage);
            Assert.Equal(receivedMessage.Body, bytes);
            Assert.Equal(5, receivedMessage.SystemProperties.Count);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MessageId], messageId);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MsgCorrelationId], correlationId);
            Assert.Equal("application/json", receivedMessage.SystemProperties[SystemProperties.ContentType]);
            Assert.Equal("UTF-8", receivedMessage.SystemProperties[SystemProperties.ContentEncoding]);
            Assert.Equal("InterfaceId1", receivedMessage.SystemProperties[SystemProperties.InterfaceId]);
        }
Exemplo n.º 2
0
        public void ToMessageNoAppPropsTest()
        {
            // Arrange
            IMessage receivedMessage;
            byte[] bytes = { 1, 2, 3, 4 };
            string messageId = Guid.NewGuid().ToString();
            string correlationId = Guid.NewGuid().ToString();
            using (AmqpMessage amqpMessage = AmqpMessage.Create(new Data { Value = new ArraySegment<byte>(bytes) }))
            {
                amqpMessage.Properties.MessageId = messageId;
                amqpMessage.Properties.CorrelationId = correlationId;
                amqpMessage.Properties.ContentType = "application/json";
                amqpMessage.Properties.ContentEncoding = "UTF-8";

                amqpMessage.ApplicationProperties = null;

                var messageConverter = new AmqpMessageConverter();

                // Act
                receivedMessage = messageConverter.ToMessage(amqpMessage);
            }

            // Assert
            Assert.NotNull(receivedMessage);
            Assert.Equal(receivedMessage.Body, bytes);
            Assert.Equal(receivedMessage.SystemProperties.Count, 4);
            Assert.Equal(receivedMessage.Properties.Count, 0);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MessageId], messageId);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MsgCorrelationId], correlationId);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.ContentType], "application/json");
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.ContentEncoding], "UTF-8");
        }
Exemplo n.º 3
0
        public void ToMessageTest_AllProperties()
        {
            // Arrange
            IMessage receivedMessage;

            byte[] bytes           = { 1, 2, 3, 4 };
            string messageId       = Guid.NewGuid().ToString();
            string correlationId   = Guid.NewGuid().ToString();
            string contentType     = "application/json";
            string contentEncoding = "UTF-8";
            string to             = "d1";
            string userId         = "userId1";
            var    expiryTime     = new DateTime(2018, 2, 3, 02, 03, 04, DateTimeKind.Utc);
            string creationTime   = new DateTime(2018, 1, 1, 02, 03, 04, DateTimeKind.Utc).ToString("o");
            var    enqueuedTime   = new DateTime(2018, 4, 5, 04, 05, 06, DateTimeKind.Utc);
            byte   deliveryCount  = 10;
            string lockToken      = Guid.NewGuid().ToString();
            ulong  sequenceNumber = 100;
            string messageSchema  = "testSchema";
            string operation      = "foo";
            string outputName     = "output1";

            using (AmqpMessage amqpMessage = AmqpMessage.Create(new Data {
                Value = new ArraySegment <byte>(bytes)
            }))
            {
                amqpMessage.Properties.MessageId       = messageId;
                amqpMessage.Properties.CorrelationId   = correlationId;
                amqpMessage.Properties.ContentType     = contentType;
                amqpMessage.Properties.ContentEncoding = contentEncoding;
                amqpMessage.Properties.To                 = to;
                amqpMessage.Properties.UserId             = new ArraySegment <byte>(Encoding.UTF8.GetBytes(userId));
                amqpMessage.Properties.AbsoluteExpiryTime = expiryTime;

                amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsEnqueuedTimeKey]    = enqueuedTime;
                amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsDeliveryCountKey]   = deliveryCount;
                amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsLockTokenName]      = lockToken;
                amqpMessage.MessageAnnotations.Map[Amqp.Constants.MessageAnnotationsSequenceNumberName] = sequenceNumber;

                amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesMessageSchemaKey] = messageSchema;
                amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesCreationTimeKey]  = creationTime;
                amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesOperationKey]     = operation;
                amqpMessage.ApplicationProperties.Map[Amqp.Constants.MessagePropertiesOutputNameKey]    = outputName;

                amqpMessage.ApplicationProperties.Map["Prop1"] = "Value1";
                amqpMessage.ApplicationProperties.Map["Prop2"] = "Value2";

                var messageConverter = new AmqpMessageConverter();

                // Act
                receivedMessage = messageConverter.ToMessage(amqpMessage);
            }

            // Assert
            Assert.NotNull(receivedMessage);
            Assert.Equal(receivedMessage.Body, bytes);
            Assert.Equal(receivedMessage.SystemProperties.Count, 15);
            Assert.Equal(receivedMessage.Properties.Count, 2);

            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MessageId], messageId);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MsgCorrelationId], correlationId);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.ContentType], contentType);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.ContentEncoding], contentEncoding);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.To], to);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.UserId], userId);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.ExpiryTimeUtc], expiryTime.ToString("o"));
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.EnqueuedTime], enqueuedTime.ToString("o"));
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.DeliveryCount], deliveryCount.ToString());
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.LockToken], lockToken);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.SequenceNumber], sequenceNumber.ToString());
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.MessageSchema], messageSchema);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.CreationTime], creationTime);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.Operation], operation);
            Assert.Equal(receivedMessage.SystemProperties[SystemProperties.OutputName], outputName);

            Assert.Equal(receivedMessage.Properties["Prop1"], "Value1");
            Assert.Equal(receivedMessage.Properties["Prop2"], "Value2");
        }