Пример #1
0
        public void ValueOperationsWorkWhenNotEmpty()
        {
            var message     = CreateEmptydDataBodyMessage();
            var systemProps = new AmqpSystemProperties(message);

            message.Properties.MessageId = new AmqpMessageId("test");
            message.MessageAnnotations.Add("first", "one");

            var unexpectedKey  = Guid.NewGuid().ToString();
            var expectedValues = new HashSet <object> {
                message.Properties.MessageId
            };

            foreach (var value in message.MessageAnnotations.Values)
            {
                expectedValues.Add(value);
            }

            // Count

            Assert.That(systemProps.Count, Is.EqualTo(expectedValues.Count), "The number of items was incorrect.");

            // System property values are correct.

            Assert.That(systemProps[Properties.MessageIdName], Is.EqualTo(message.Properties.MessageId), "The message identifier did not match when read through the indexer.");
            Assert.That(systemProps.TryGetValue(Properties.MessageIdName, out var messageId), Is.True, "The message identifier was not contained when read through TryGetValue.");
            Assert.That(messageId, Is.EqualTo(message.Properties.MessageId), "The message identifier did not match when read through TryGetValue.");

            // Message annotation values are correct.

            foreach (var key in message.MessageAnnotations.Keys)
            {
                Assert.That(systemProps[key], Is.EqualTo(message.MessageAnnotations[key]), $"The message annotation, { key }, did not match when read through the indexer.");
                Assert.That(systemProps.TryGetValue(key, out var currentValue), Is.True, $"The message annotation, { key }, was not contained when read through TryGetValue.");
                Assert.That(currentValue, Is.EqualTo(message.MessageAnnotations[key]), $"The message annotation, { key }, did not match when read through TryGetValue.");
            }

            // Unexpected values are not returned.

            Assert.That(() => systemProps[unexpectedKey], Throws.InstanceOf <KeyNotFoundException>(), "The unexpected key should result in an exception when read through the indexer.");
            Assert.That(systemProps.TryGetValue(unexpectedKey, out var unexpectedValue), Is.False, "The unexpected key should not succeed for TryGetValue.");

            // Enumerated Values match the expected set.

            foreach (var value in systemProps.Values)
            {
                Assert.That(expectedValues.Contains(value), Is.True, $"The value, { value }, was in the properties but is unexpected.");
            }
        }
Пример #2
0
        public void ValueOperationsWorkWhenEmpty()
        {
            var message       = CreateEmptydDataBodyMessage();
            var systemProps   = new AmqpSystemProperties(message);
            var unexpectedKey = Guid.NewGuid().ToString();

            // Count

            Assert.That(systemProps.Count, Is.EqualTo(0), "The number of items was incorrect.");

            // Unexpected values are not returned.

            Assert.That(() => systemProps[unexpectedKey], Throws.InstanceOf <KeyNotFoundException>(), "The unexpected key should result in an exception when read through the indexer.");
            Assert.That(systemProps.TryGetValue(unexpectedKey, out var unexpectedValue), Is.False, "The unexpected key should not succeed for TryGetValue.");

            // Enumerated Values are empty.

            foreach (var value in systemProps.Values)
            {
                Assert.Fail($"The value, { value }, was found in the set that should be empty.");
            }
        }