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); }
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); }
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()); }
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); }
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); }
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); }
public void WritePropertyToDictionary(IDictionary <string, object> dictionary, T obj) { IDictionary <string, object> value = _converter.GetDictionary(_property.Get(obj)); dictionary.Add(_property.Property.Name, value); }