public void TestProperties_ReplyTo([Values(null, "foo_1", "fanout://name/key")] string replyTo)
        {
            // Arrange
            var subject = new Framing.BasicProperties
            {
                // Act
                ReplyTo = replyTo,
            };

            // Assert
            bool isReplyToPresent = replyTo != null;
            PublicationAddress result;

            PublicationAddress.TryParse(replyTo, out result);
            string replyToAddress = result?.ToString();

            Assert.AreEqual(isReplyToPresent, subject.IsReplyToPresent());

            Span <byte> span   = new byte[1024];
            var         writer = new Impl.ContentHeaderPropertyWriter(span);

            subject.WritePropertiesTo(ref writer);

            // Read from Stream
            var propertiesFromStream = new Framing.BasicProperties();
            var reader = new Impl.ContentHeaderPropertyReader(span.Slice(0, writer.Offset));

            propertiesFromStream.ReadPropertiesFrom(ref reader);

            Assert.AreEqual(replyTo, propertiesFromStream.ReplyTo);
            Assert.AreEqual(isReplyToPresent, propertiesFromStream.IsReplyToPresent());
            Assert.AreEqual(replyToAddress, propertiesFromStream.ReplyToAddress?.ToString());
        }
Exemplo n.º 2
0
        public void TestProperties_ReplyTo(string replyTo)
        {
            // Arrange
            var subject = new Framing.BasicProperties
            {
                // Act
                ReplyTo = replyTo,
            };

            // Assert
            bool isReplyToPresent = replyTo != null;

            PublicationAddress.TryParse(replyTo, out PublicationAddress result);
            string replyToAddress = result?.ToString();

            Assert.Equal(isReplyToPresent, subject.IsReplyToPresent());

            Span <byte> span   = new byte[1024];
            int         offset = subject.WritePropertiesTo(span);

            // Read from Stream
            var propertiesFromStream = new Framing.BasicProperties(span.Slice(0, offset));

            Assert.Equal(replyTo, propertiesFromStream.ReplyTo);
            Assert.Equal(isReplyToPresent, propertiesFromStream.IsReplyToPresent());
            Assert.Equal(replyToAddress, propertiesFromStream.ReplyToAddress?.ToString());
        }
Exemplo n.º 3
0
        public void TestNullableProperties_CanWrite(
            [Values(null, "cluster1")] string clusterId,
            [Values(null, "732E39DC-AF56-46E8-B8A9-079C4B991B2E")] string correlationId,
            [Values(null, "7D221C7E-1788-4D11-9CA5-AC41425047CF")] string messageId
            )
        {
            // Arrange
            var subject = new Framing.BasicProperties
            {
                // Act
                ClusterId     = clusterId,
                CorrelationId = correlationId,
                MessageId     = messageId
            };

            // Assert
            bool isClusterIdPresent = clusterId != null;

            Assert.AreEqual(isClusterIdPresent, subject.IsClusterIdPresent());

            bool isCorrelationIdPresent = correlationId != null;

            Assert.AreEqual(isCorrelationIdPresent, subject.IsCorrelationIdPresent());

            bool isMessageIdPresent = messageId != null;

            Assert.AreEqual(isMessageIdPresent, subject.IsMessageIdPresent());

            using (var outputStream = new MemoryStream())
            {
                var binaryWriter = new NetworkBinaryWriter(outputStream);
                var writer       = new Impl.ContentHeaderPropertyWriter(binaryWriter);
                subject.WritePropertiesTo(writer);

                // Read from Stream
                outputStream.Seek(0L, SeekOrigin.Begin);
                var propertiesFromStream = new Framing.BasicProperties();
                var reader = new Impl.ContentHeaderPropertyReader(new NetworkBinaryReader(outputStream));
                propertiesFromStream.ReadPropertiesFrom(reader);

                Assert.AreEqual(clusterId, propertiesFromStream.ClusterId);
                Assert.AreEqual(correlationId, propertiesFromStream.CorrelationId);
                Assert.AreEqual(messageId, propertiesFromStream.MessageId);
                Assert.AreEqual(isClusterIdPresent, propertiesFromStream.IsClusterIdPresent());
                Assert.AreEqual(isCorrelationIdPresent, propertiesFromStream.IsCorrelationIdPresent());
                Assert.AreEqual(isMessageIdPresent, propertiesFromStream.IsMessageIdPresent());
            }
        }
        public void TestNullableProperties_CanWrite(
            [Values(null, "cluster1")] string clusterId,
            [Values(null, "732E39DC-AF56-46E8-B8A9-079C4B991B2E")] string correlationId,
            [Values(null, "7D221C7E-1788-4D11-9CA5-AC41425047CF")] string messageId
            )
        {
            // Arrange
            var subject = new Framing.BasicProperties
            {
                // Act
                ClusterId     = clusterId,
                CorrelationId = correlationId,
                MessageId     = messageId
            };

            // Assert
            bool isClusterIdPresent = clusterId != null;

            Assert.AreEqual(isClusterIdPresent, subject.IsClusterIdPresent());

            bool isCorrelationIdPresent = correlationId != null;

            Assert.AreEqual(isCorrelationIdPresent, subject.IsCorrelationIdPresent());

            bool isMessageIdPresent = messageId != null;

            Assert.AreEqual(isMessageIdPresent, subject.IsMessageIdPresent());

            Span <byte> span   = new byte[1024];
            var         writer = new Impl.ContentHeaderPropertyWriter(span);

            subject.WritePropertiesTo(ref writer);

            // Read from Stream
            var propertiesFromStream = new Framing.BasicProperties();
            var reader = new Impl.ContentHeaderPropertyReader(span.Slice(0, writer.Offset));

            propertiesFromStream.ReadPropertiesFrom(ref reader);

            Assert.AreEqual(clusterId, propertiesFromStream.ClusterId);
            Assert.AreEqual(correlationId, propertiesFromStream.CorrelationId);
            Assert.AreEqual(messageId, propertiesFromStream.MessageId);
            Assert.AreEqual(isClusterIdPresent, propertiesFromStream.IsClusterIdPresent());
            Assert.AreEqual(isCorrelationIdPresent, propertiesFromStream.IsCorrelationIdPresent());
            Assert.AreEqual(isMessageIdPresent, propertiesFromStream.IsMessageIdPresent());
        }
        public void TestSimpleProperties()
        {
            Framing.BasicProperties prop = new Framing.BasicProperties
            {
                ContentType = "text/plain"
            };
            int bytesNeeded = prop.GetRequiredPayloadBufferSize();

            byte[] bytes  = new byte[bytesNeeded];
            int    offset = prop.WritePropertiesTo(bytes);

            Check(bytes.AsMemory().Slice(0, offset), new byte[] {
                0x80, 0x00,                                                // props flags
                0x0A,                                                      // shortstr len
                0x74, 0x65, 0x78, 0x74, 0x2F, 0x70, 0x6C, 0x61, 0x69, 0x6E // text/plain
            });
        }
        public void TestFullProperties()
        {
            Framing.BasicProperties prop = new Framing.BasicProperties
            {
                AppId           = "A",
                ContentType     = "B",
                ContentEncoding = "C",
                ClusterId       = "D",
                CorrelationId   = "E",
                DeliveryMode    = 1,
                Expiration      = "F",
                MessageId       = "G",
                Priority        = 2,
                Timestamp       = new AmqpTimestamp(3),
                Type            = "H",
                ReplyTo         = "I",
                UserId          = "J",
                Headers         = new Dictionary <string, object>(0)
            };
            int bytesNeeded = prop.GetRequiredPayloadBufferSize();

            byte[] bytes  = new byte[bytesNeeded];
            int    offset = prop.WritePropertiesTo(bytes);

            Check(bytes.AsMemory().Slice(0, offset), new byte[] {
                0b1111_1111, 0b1111_1100,                       // props flags (all set)
                0x01, 0x42,                                     // ContentType
                0x01, 0x43,                                     // ContentEncoding
                0x00, 0x00, 0x00, 0x00,                         // Headers (length 0)
                0x01,                                           // DeliveryMode
                0x02,                                           // Priority
                0x01, 0x45,                                     // CorrelationId
                0x01, 0x49,                                     // ReplyTo
                0x01, 0x46,                                     // Expiration
                0x01, 0x47,                                     // MessageId
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // Timestamp
                0x01, 0x48,                                     // Type
                0x01, 0x4A,                                     // UserId
                0x01, 0x41,                                     // AppId
                0x01, 0x44,                                     // ClusterId
            });
Exemplo n.º 7
0
        public void TestNullableProperties_CanWrite(string clusterId, string correlationId, string messageId)
        {
            // Arrange
            var subject = new Framing.BasicProperties
            {
                // Act
                ClusterId     = clusterId,
                CorrelationId = correlationId,
                MessageId     = messageId
            };

            // Assert
            bool isClusterIdPresent = clusterId != null;

            Assert.Equal(isClusterIdPresent, subject.IsClusterIdPresent());

            bool isCorrelationIdPresent = correlationId != null;

            Assert.Equal(isCorrelationIdPresent, subject.IsCorrelationIdPresent());

            bool isMessageIdPresent = messageId != null;

            Assert.Equal(isMessageIdPresent, subject.IsMessageIdPresent());

            Span <byte> span   = new byte[1024];
            int         offset = subject.WritePropertiesTo(span);

            // Read from Stream
            var propertiesFromStream = new Framing.BasicProperties(span.Slice(0, offset));

            Assert.Equal(clusterId, propertiesFromStream.ClusterId);
            Assert.Equal(correlationId, propertiesFromStream.CorrelationId);
            Assert.Equal(messageId, propertiesFromStream.MessageId);
            Assert.Equal(isClusterIdPresent, propertiesFromStream.IsClusterIdPresent());
            Assert.Equal(isCorrelationIdPresent, propertiesFromStream.IsCorrelationIdPresent());
            Assert.Equal(isMessageIdPresent, propertiesFromStream.IsMessageIdPresent());
        }