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());
        }
Пример #2
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());
        }