コード例 #1
0
        public void Should_map_an_anonymous_object_to_the_settings()
        {
            var converterCache = new DynamicObjectConverterCache(new DynamicImplementationBuilder());
            var cache          = new DictionaryConverterCache();

            var source = new
            {
                Host        = "localhost",
                VirtualHost = "vortex",
                Username    = "******",
                Password    = "******",
                Port        = 5672,
            };

            IDictionaryConverter         converter  = cache.GetConverter(source.GetType());
            IDictionary <string, object> dictionary = converter.GetDictionary(source);

            IObjectConverter objectConverter = converterCache.GetConverter(typeof(RabbitMqSettings));

            var settings = (RabbitMqSettings)objectConverter.GetObject(dictionary);

            Assert.IsNotNull(settings);

            Assert.AreEqual("localhost", settings.Host);
            Assert.AreEqual("vortex", settings.VirtualHost);
            Assert.AreEqual("joe", settings.Username);
            Assert.AreEqual("guess", settings.Password);
            Assert.AreEqual(5672, settings.Port);
            Assert.AreEqual(0, settings.Heartbeat);

            Assert.IsNull(settings.Options);
        }
コード例 #2
0
        public void WritePropertyToDictionary(IDictionary <string, object> dictionary, T obj)
        {
            object value = _property.Get(obj);

            if (value == null)
            {
                return;
            }

            var values = value as IList <TElement>;

            if (values == null)
            {
                return;
            }

            var elements = new object[values.Count];

            for (int i = 0; i < values.Count; i++)
            {
                elements[i] = _elementConverter.GetDictionary(values[i]);
            }

            dictionary.Add(_property.Property.Name, elements);
        }
コード例 #3
0
        public void WritePropertyToDictionary(IDictionary <string, object> dictionary, T obj)
        {
            object value = _property.Get(obj);

            if (value == null)
            {
                return;
            }

            var values = value as IDictionary <TKey, TValue>;

            if (values == null)
            {
                return;
            }

            var elements = new List <object>();

            foreach (var element in values)
            {
                elements.Add(new object[] { element.Key, _elementConverter.GetDictionary(element.Value) });
            }

            dictionary.Add(_property.Property.Name, elements.ToArray());
        }
コード例 #4
0
        public void Setup()
        {
            var factory = new DictionaryConverterCache();

            IDictionaryConverter converter = factory.GetConverter(typeof(ValuesImpl));

            _expected   = new ValuesImpl("Hello", 27, new DateTime(2012, 10, 1), null, 123.45m);
            _dictionary =
                converter.GetDictionary(_expected);
        }
コード例 #5
0
        public void WritePropertyToDictionary(IDictionary <string, object> dictionary, T obj)
        {
            object value = _property.Get(obj);

            var values = value as IDictionary <TKey, TValue>;

            if (values == null)
            {
                return;
            }

            var elementArray = values.Select(element => new object[] { element.Key, _elementConverter.GetDictionary(element.Value) })
                               .ToArray <object>();

            dictionary.Add(_property.Property.Name, elementArray);
        }
コード例 #6
0
        public void WritePropertyToDictionary(IDictionary <string, object> dictionary, T obj)
        {
            var value = _property.Get(obj);

            if (!(value is TElement[] values))
            {
                return;
            }

            var elements = new IDictionary <string, object> [values.Length];

            for (var i = 0; i < values.Length; i++)
            {
                elements[i] = _elementConverter.GetDictionary(values[i]);
            }

            dictionary.Add(_property.Property.Name, elements);
        }
コード例 #7
0
        public void WritePropertyToDictionary(IDictionary <string, object> dictionary, T obj)
        {
            IDictionary <string, object> value = _converter.GetDictionary(_property.Get(obj));

            dictionary.Add(_property.Property.Name, value);
        }