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());
        }
Example #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());
        }
        public void TestPersistentPropertyChangesDeliveryMode_PersistentFalseDelivery1()
        {
            // Arrange
            var subject = new Framing.BasicProperties();

            // Act
            subject.Persistent = false;

            // Assert
            Assert.AreEqual(1, subject.DeliveryMode);
            Assert.AreEqual(false, subject.Persistent);
        }
        public void TestPersistentPropertyChangesDeliveryMode_PersistentTrueDelivery2()
        {
            // Arrange
            var subject = new Framing.BasicProperties();

            // Act
            subject.Persistent = true;

            // Assert
            Assert.AreEqual(2, subject.DeliveryMode);
            Assert.AreEqual(true, subject.Persistent);
        }
        public void TestSetPersistentMethodChangesDeliveryMode_PersistentTrueDelivery2()
        {
            // Arrange
            var subject = new Framing.BasicProperties();

            // Act
            subject.SetPersistent(true);

            // Assert
            Assert.AreEqual(2, subject.DeliveryMode);
            Assert.AreEqual(true, subject.Persistent);
        }
        public void TestPersistentPropertyChangesDeliveryMode_PersistentFalseDelivery1()
        {
            // Arrange
            var subject = new Framing.BasicProperties();

            // Act
            subject.Persistent = false;

            // Assert
            Assert.AreEqual(1, subject.DeliveryMode);
            Assert.AreEqual(false, subject.Persistent);
        }
Example #7
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
            });
        public void HeaderFrame()
        {
            const int Channel    = 3;
            const int BodyLength = 10;

            var basicProperties = new Framing.BasicProperties {
                AppId = "A"
            };
            int payloadSize = basicProperties.GetRequiredPayloadBufferSize();
            var frameBytes  = new byte[Impl.Framing.Header.FrameSize + BodyLength + payloadSize];

            Impl.Framing.Header.WriteTo(frameBytes, Channel, basicProperties, BodyLength);

            Assert.AreEqual(20, Impl.Framing.Header.FrameSize);
            Assert.AreEqual(Constants.FrameHeader, frameBytes[0]);
            Assert.AreEqual(0, frameBytes[1]);                    // channel
            Assert.AreEqual(Channel, frameBytes[2]);              // channel
            Assert.AreEqual(0, frameBytes[3]);                    // payload size
            Assert.AreEqual(0, frameBytes[4]);                    // payload size
            Assert.AreEqual(0, frameBytes[5]);                    // payload size
            Assert.AreEqual(12 + payloadSize, frameBytes[6]);     // payload size
            Assert.AreEqual(0, frameBytes[7]);                    // ProtocolClassId
            Assert.AreEqual(ClassConstants.Basic, frameBytes[8]); // ProtocolClassId
            Assert.AreEqual(0, frameBytes[9]);                    // Weight
            Assert.AreEqual(0, frameBytes[10]);                   // Weight
            Assert.AreEqual(0, frameBytes[11]);                   // BodyLength
            Assert.AreEqual(0, frameBytes[12]);                   // BodyLength
            Assert.AreEqual(0, frameBytes[13]);                   // BodyLength
            Assert.AreEqual(0, frameBytes[14]);                   // BodyLength
            Assert.AreEqual(0, frameBytes[15]);                   // BodyLength
            Assert.AreEqual(0, frameBytes[16]);                   // BodyLength
            Assert.AreEqual(0, frameBytes[17]);                   // BodyLength
            Assert.AreEqual(BodyLength, frameBytes[18]);          // BodyLength
            Assert.AreEqual(0b0000_0000, frameBytes[19]);         // Presence
            Assert.AreEqual(0b0000_1000, frameBytes[20]);         // Presence
            Assert.AreEqual(1, frameBytes[21]);                   // AppId Length
            Assert.AreEqual((byte)'A', frameBytes[22]);           // AppId payload
            Assert.AreEqual(Constants.FrameEnd, frameBytes[23]);
        }
Example #12
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());
        }