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);
        }
Esempio n. 2
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);
        }
        public void Setup()
        {
            var factory = new DictionaryConverterCache();

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

            _dictionary =
                converter.GetDictionary(new ValuesImpl("Hello", 27, new DateTime(2012, 10, 1), null, 123.45m));
        }
Esempio n. 4
0
        public void Setup()
        {
            var factory = new DictionaryConverterCache();

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

            _expected   = new ValuesImpl("Hello", 27, new DateTime(2012, 10, 1), null, 123.45m);
            _dictionary =
                converter.GetDictionary(_expected);
        }