public void TestNullableProperties_CanWrite(string clusterId, string correlationId, string messageId)
        {
            // Arrange
            var subject = new 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 = ((IAmqpWriteable)subject).WriteTo(span);

            // Read from Stream
            var propertiesFromStream = new ReadOnlyBasicProperties(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());

            // Verify Basic Properties
            var basicProperties = new BasicProperties(propertiesFromStream);

            Assert.Equal(clusterId, basicProperties.ClusterId);
            Assert.Equal(correlationId, basicProperties.CorrelationId);
            Assert.Equal(messageId, basicProperties.MessageId);
            Assert.Equal(isClusterIdPresent, basicProperties.IsClusterIdPresent());
            Assert.Equal(isCorrelationIdPresent, basicProperties.IsCorrelationIdPresent());
            Assert.Equal(isMessageIdPresent, basicProperties.IsMessageIdPresent());
        }
Ejemplo n.º 2
0
        private void TestBasicPropertiesNoneClone(BasicProperties bp)
        {
            // Do not set any member and clone
            BasicProperties bpClone = bp.Clone() as BasicProperties;

            // Set members in source object
            bp.ContentType     = "foo_1";
            bp.ContentEncoding = "foo_2";
            bp.Headers         = new Dictionary <string, object>
            {
                { "foo_3", "foo_4" },
                { "foo_5", "foo_6" }
            };
            bp.DeliveryMode = 2;
            // Persistent also changes DeliveryMode's value to 2
            bp.Persistent    = true;
            bp.Priority      = 12;
            bp.CorrelationId = "foo_7";
            bp.ReplyTo       = "foo_8";
            bp.Expiration    = "foo_9";
            bp.MessageId     = "foo_10";
            bp.Timestamp     = new AmqpTimestamp(123);
            bp.Type          = "foo_11";
            bp.UserId        = "foo_12";
            bp.AppId         = "foo_13";
            bp.ClusterId     = "foo_14";

            // Check that no member is present in clone
            Assert.AreEqual(false, bpClone.IsContentTypePresent());
            Assert.AreEqual(false, bpClone.IsContentEncodingPresent());
            Assert.AreEqual(false, bpClone.IsHeadersPresent());
            Assert.AreEqual(false, bpClone.IsDeliveryModePresent());
            Assert.AreEqual(false, bpClone.IsPriorityPresent());
            Assert.AreEqual(false, bpClone.IsCorrelationIdPresent());
            Assert.AreEqual(false, bpClone.IsReplyToPresent());
            Assert.AreEqual(false, bpClone.IsExpirationPresent());
            Assert.AreEqual(false, bpClone.IsMessageIdPresent());
            Assert.AreEqual(false, bpClone.IsTimestampPresent());
            Assert.AreEqual(false, bpClone.IsTypePresent());
            Assert.AreEqual(false, bpClone.IsUserIdPresent());
            Assert.AreEqual(false, bpClone.IsAppIdPresent());
            Assert.AreEqual(false, bpClone.IsClusterIdPresent());
        }