public void ObjectMapConfig_CustomStructConverter()
        {
            var config = new ObjectMapConfig();
            config.AddConverter(DayOfWeekConverter);

            config.PropertyMapRules.Clear();
            var rule = new PropertyNameMappingRule();
            rule.PropertyNameMaps.Add("Value", "DayOfWeek");
            config.PropertyMapRules.Add(rule);

            var u1 = new User();
            u1.Value = "Friday";
            var u2 = config.Map(u1, new User());

            Assert.AreEqual(DayOfWeek.Friday, u2.DayOfWeek);
        }
        public void ObjectMapConfig_CustomClassConverter()
        {
            var config = new ObjectMapConfig();
            config.AddConverter<MapPoint>(MapPointConverter);

            config.PropertyMapRules.Clear();
            var rule = new PropertyNameMappingRule();
            rule.PropertyNameMaps.Add("Value", "MapPoint");
            config.PropertyMapRules.Add(rule);

            var u1 = new User();
            u1.Value = "23, 45";
            var u2 = config.Map(u1, new User());

            Assert.AreEqual(23m, u2.MapPoint.Latitude);
            Assert.AreEqual(45m, u2.MapPoint.Longitude);
        }
        public void ObjectMapConfig_DefaultTypeConverter()
        {
            var config = new ObjectMapConfig();
            var rules = config.PropertyMapRules.ToArray();
            config.PropertyMapRules.Clear();

            config.PropertyMapRules.Clear();
            var rule = new PropertyNameMappingRule();
            rule.PropertyNameMaps.Add("Value", "Int32");
            rule.PropertyNameMaps.Add("Value", "DateTime");
            rule.PropertyNameMaps.Add("Value", "Decimal");
            rule.PropertyNameMaps.Add("Value", "DayOfWeek");
            config.PropertyMapRules.Add(rule);

            var u1 = new User();
            {
                u1.Value = "23";
                var u2 = config.Map(u1, new User());
                Assert.AreEqual(23, u2.Int32);
            }
            {
                u1.Value = "2014/12/17 00:00:00";
                var u2 = config.Map(u1, new User());
                Assert.AreEqual(new DateTime(2014, 12, 17), u2.DateTime);
            }
            {
                u1.Value = "23.4";
                var u2 = config.Map(u1, new User());
                Assert.AreEqual(23.4m, u2.Decimal);
            }
            {
                u1.Value = "Friday";
                var u2 = config.Map(u1, new User());
                Assert.AreEqual(DayOfWeek.Friday, u2.DayOfWeek);
            }
        }
        public void ObjectMapConfig_Map_Object_Object_Convert_Failure()
        {
            var config = new ObjectMapConfig();
            config.PropertyMapRules.Clear();

            var rule = new PropertyNameMappingRule();
            rule.PropertyNameMaps.Add("Value", "Decimal");
            config.PropertyMapRules.Add(rule);

            var u1 = new User();
            u1.Value = "abc";
            var u2 = config.Map(u1, new User());
            //Not changed...
            Assert.AreEqual(20.4m, u2.Decimal);
        }
        public void ObjectMapConfig_Map_FromDecimalToInt32()
        {
            var config = new ObjectMapConfig();
            config.PropertyMapRules.Clear();

            var rule = new PropertyNameMappingRule();
            rule.PropertyNameMaps.Add("Int32", "Decimal");
            config.PropertyMapRules.Add(rule);

            var u1 = new User();
            u1.Int32 = 23;
            var u2 = config.Map(u1, new User());

            Assert.AreEqual(23m, u2.Decimal);
        }