Exemplo n.º 1
0
        public void BuildBasicPropertiesByConfiguration()
        {
            const String contentType = "application/json";
            const String contentEncoding = "UTF-8";
            const String messageId = "one-id";
            const Int64 timestamp = 123456789L;
            var collection = new HeaderCollection(new Dictionary<String, Object>(StringComparer.OrdinalIgnoreCase)
                                                      {
                                                          { "content_type", contentType },
                                                          { "content_encoding", contentEncoding }
                                                      });
            const String key = "foo";
            const String value = "bar";
            collection.AddHeader(key, value);
            var resolver = new Mock<IMessageTypeResolver>();
            resolver.Setup(_ => _.Resolve<Foo>()).Returns(EmptyMessageBinding.Instance);
            var newId = new Mock<INewId>();
            newId.Setup(_ => _.Next()).Returns(messageId);
            var dateTimeProvider = new Mock<IDateTimeProvider>();
            dateTimeProvider.Setup(_ => _.UtcNow()).Returns(timestamp.ToDateTimeOffset());
            var message = new OutboundMessage<Foo>(new Foo(), collection);
            var properties = message.BuildBasicProperties(resolver.Object, dateTimeProvider.Object, newId.Object);

            Assert.Equal(messageId, properties.MessageId);
            Assert.Equal(new AmqpTimestamp(timestamp), properties.Timestamp);
            Assert.Equal(contentType, properties.ContentType);
            Assert.Equal(contentEncoding, properties.ContentEncoding);
        }
Exemplo n.º 2
0
        public void BuildBasicProperties()
        {
            const String contentType = "application/xml";
            const String contentEncoding = "UTF-16";
            const String messageId = "one-id";
            const Int64 timestamp = 123456789L;
            const String replyExchangeName = "reply-queue-name";
            const String replyRoutingKey = "reply-queue-name";
            String correlationId = Guid.NewGuid().ToString();
            var directReplyConfiguration = new DirectReplyConfiguration(replyExchangeName, replyRoutingKey);
            var collection = new HeaderCollection(new Dictionary<String, Object>(StringComparer.OrdinalIgnoreCase)
                                                      {
                                                          { "message_id", messageId },
                                                          { "timestamp", timestamp },
                                                          { "content_type", contentType },
                                                          { "content_encoding", contentEncoding },
                                                          { "correlation_id", correlationId },
                                                          { "reply_configuration", directReplyConfiguration }
                                                      });
            const String key = "foo";
            const String value = "bar";
            collection.AddHeader(key, value);
            var resolver = new Mock<IMessageTypeResolver>();
            resolver.Setup(_ => _.Resolve<Foo>()).Returns(EmptyMessageBinding.Instance);
            var message = new OutboundMessage<Foo>(new Foo(), collection);
            var properties = message.BuildBasicProperties(resolver.Object, null, null);

            Assert.Equal(messageId, properties.MessageId);
            Assert.Equal(new AmqpTimestamp(timestamp), properties.Timestamp);
            Assert.Equal(contentType, properties.ContentType);
            Assert.Equal(contentEncoding, properties.ContentEncoding);
            Assert.Equal(correlationId, properties.CorrelationId);
            Assert.Equal(directReplyConfiguration.ToString(), properties.ReplyTo);
            Assert.Equal(value, collection[key]);
        }
Exemplo n.º 3
0
 public void KeyComparison()
 {
     const String key = "foo";
     var collection = new HeaderCollection();
     collection.AddHeader(key, "some-value");
     Assert.True(collection.Headers.ContainsKey(key.ToUpperInvariant()));
 }
Exemplo n.º 4
0
 public void KeyComparison()
 {
     const String key = "foo";
     const String value = "some-value";
     var collection = new HeaderCollection();
     collection.AddHeader(key, value);
     Assert.Equal(value, collection[key.ToUpperInvariant()]);
 }
Exemplo n.º 5
0
        public void AddOrRemoveReservedHeaders()
        {
            var collection = new HeaderCollection();

            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("message_id", "one-id"));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("timestamp", 12345678L));

            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("message_id"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("timestamp"));
        }
Exemplo n.º 6
0
        public void AddOrRemoveReservedHeaders()
        {
            var collection = new HeaderCollection();

            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("message_id", "one-id"));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("timestamp", 12345678L));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("content_type", "application/json"));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("content_encoding", "UTF-8"));

            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("message_id"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("timestamp"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("content_type"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("content_encoding"));
        }
Exemplo n.º 7
0
        public void BuildBasicProperties()
        {
            var collection = new HeaderCollection(new Dictionary<String, Object>(StringComparer.OrdinalIgnoreCase)
                                                      {
                                                          { "message_id", "one-id" },
                                                          { "timestamp", 123456789L }
                                                      });
            const String key = "foo";
            const String value = "bar";
            collection.AddHeader(key, value);
            var properties = new BasicProperties { Headers = new Dictionary<String, Object>() };
            collection.HydrateProperties(properties);

            Assert.Null(properties.MessageId);
            Assert.Equal(new AmqpTimestamp(0L), properties.Timestamp);
            Assert.True(collection.Headers.ContainsKey(key));
        }
Exemplo n.º 8
0
        public void AddOrRemoveReservedHeaders()
        {
            var collection = new HeaderCollection();

            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("message_id", "one-id"));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("timestamp", 12345678L));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("content_type", "application/json"));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("content_encoding", "UTF-8"));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("correlation_id", Guid.NewGuid().ToString()));
            Assert.Throws<InvalidOperationException>(() => collection.AddHeader("reply_to", "reply-queue-name"));

            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("message_id"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("timestamp"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("content_type"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("content_encoding"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("correlation_id"));
            Assert.Throws<InvalidOperationException>(() => collection.RemoveHeader("reply_to"));
        }
Exemplo n.º 9
0
 public void HeaderIndexer()
 {
     var collection = new HeaderCollection();
     Assert.Throws<InvalidOperationException>(() => collection["message_id"]);
     Assert.Throws<InvalidOperationException>(() => collection["timestamp"]);
     Assert.Throws<InvalidOperationException>(() => collection["content_type"]);
     Assert.Throws<InvalidOperationException>(() => collection["content_encoding"]);
     Assert.Throws<InvalidOperationException>(() => collection["correlation_id"]);
     Assert.Throws<InvalidOperationException>(() => collection["reply_to"]);
 }
Exemplo n.º 10
0
 internal OutboundMessage(TMessage content, HeaderCollection headers)
 {
     Content = content;
     Headers = headers;
 }
Exemplo n.º 11
0
 internal ConsumedMessage(TMessage content, HeaderCollection headers, String consumerTag)
 {
     Content     = content;
     Headers     = headers;
     ConsumerTag = consumerTag;
 }