public void SerializeWithAllSerializableHeaders()
        {
            IDictionary <string, object> map = new Dictionary <string, object>();

            map.Add("name", "joe");
            map.Add("age", 42);
            MessageHeaders input  = new MessageHeaders(map);
            MessageHeaders output = (MessageHeaders)SerializeAndDeserialize(input);

            Assert.That(output.Get("name"), Is.EqualTo("joe"));
            Assert.That(output.Get("age"), Is.EqualTo(42));
        }
Beispiel #2
0
        public void TestNullHeaderValueWithTypedAccess()
        {
            IDictionary <string, object> map = new Dictionary <string, object>();
            var headers = new MessageHeaders(map);

            Assert.Null(headers.Get <string>("nosuchattribute"));
        }
        public void TestNullHeaderValue()
        {
            IDictionary <string, object> map = new Dictionary <string, object>();
            MessageHeaders headers           = new MessageHeaders(map);

            Assert.That(headers.Get("nosuchattribute"), Is.Null);
        }
Beispiel #4
0
        public void FromTypeShouldPopulateWithTypeNameByDefault()
        {
            typeMapper.FromType(typeof(SimpleTrade), headers);
            var className = headers.Get <string>(typeMapper.ClassIdFieldName);

            Assert.Equal(typeof(SimpleTrade).ToString(), className);
        }
Beispiel #5
0
        public void TestHeaderValueAccessWithIncorrectType()
        {
            IDictionary <string, object> map = new Dictionary <string, object>();

            map.Add("test", 123);
            var headers = new MessageHeaders(map);

            Assert.Throws <InvalidCastException>(() => headers.Get <string>("test"));
        }
Beispiel #6
0
        public void TestTypedAccessOfHeaderValue()
        {
            IDictionary <string, object> map = new Dictionary <string, object>();

            map.Add("test", 123);
            var headers = new MessageHeaders(map);

            Assert.Equal(123, headers.Get <int>("test"));
        }
        public void TestHeaderValueAccessWithIncorrectType()
        {
            const int value = 123;
            IDictionary <string, object> map = new Dictionary <string, object>();

            map.Add("test", value);
            MessageHeaders headers = new MessageHeaders(map);

            Assert.That(headers.Get <string>("test"), Is.EqualTo(value));
        }
        public void SetWithSameKeyShouldReplaceValue()
        {
            // Given
            const string key     = "key";
            var          value1  = new byte[] { 1, 2, 3, 4, 5 };
            var          value2  = new byte[] { 6, 7, 8, 9, 0 };
            var          headers = new MessageHeaders();

            // When
            headers.Set(key, value1);
            var actualValue1 = headers.Get(key);

            headers.Set(key, value2);
            var actualValue2 = headers.Get(key);

            // Then
            Assert.AreEqual(value1, actualValue1);
            Assert.AreEqual(value2, actualValue2);
        }
        public void ShouldSetAndGetData()
        {
            // Given
            const string key1    = "key1";
            const string key2    = "key2";
            var          value1  = new byte[] { 1, 2, 3, 4, 5 };
            var          value2  = new byte[] { 6, 7, 8, 9, 0 };
            var          headers = new MessageHeaders();

            // When
            headers.Set(key1, value1);
            headers.Set(key2, value2);
            var actualValue1 = headers.Get(key1);
            var actualValue2 = headers.Get(key2);

            // Then
            Assert.AreEqual(value1, actualValue1);
            Assert.AreEqual(value2, actualValue2);
        }
Beispiel #10
0
        private Properties GetStringTypedHeaders(IMessage message)
        {
            Properties     properties = new Properties();
            MessageHeaders headers    = message.Headers;

            foreach (string key in headers.Keys)
            {
                object value = headers.Get(key);
                if (value is string)
                {
                    properties.SetProperty(key, (string)value);
                }
            }
            return(properties);
        }
        public void ShouldSetAndGetObjectInMessageHeaders()
        {
            // Given
            var key   = Guid.NewGuid().ToString();
            var value = new SomeEntity {
                Id = Guid.NewGuid()
            };
            var headers = new MessageHeaders();

            // When
            headers.Set(key, value);
            var actualValue = headers.Get <SomeEntity>(key);

            // Then
            Assert.IsNotNull(actualValue);
            Assert.AreEqual(value.Id, actualValue.Id);
        }
 public void TestTypedAccessOfHeaderValue()
 {
     const int value = 123;
     IDictionary<string, object> map = new Dictionary<string, object>();
     map.Add("test", value);
     MessageHeaders headers = new MessageHeaders(map);
     Assert.That(headers.Get<int>("test"), Is.EqualTo(value));
 }
 public void TestNullHeaderValueWithTypedAccess()
 {
     IDictionary<string, object> map = new Dictionary<string, object>();
     MessageHeaders headers = new MessageHeaders(map);
     Assert.That(headers.Get<string>("nosuchattribute"), Is.Null);
 }