Ejemplo n.º 1
0
        public void SingleObjectTest()
        {
            MapFactory.ResetAllMaps();
            var target = new InnType {
                DateTimeValue = DateTime.Now, DesimalValue = (decimal)100.212, StringValue = "test", MyEnum = Mock.MyEnum.something
            };
            var map = MapFactory.CreateEmptyMapRule <InnType, OutType>();

            map.AddMap <InnType, OutType>(new Dictionary <string, string>
            {
                { "DateTimeValue", "DateTimeValue1" },
                { "DesimalValue", "DesimalValue1" },
                { "StringValue", "StringValue1" }
            });
            map.GetRule <InnType, OutType>().Add(r => r.MyEnum, r => r.MyEnumName).Add(r => r.MyEnum, r => r.MyEnumVal);

            var result = target.Map().To <OutType>(map);

            Assert.IsNotNull(result);
            Assert.AreEqual(target.DateTimeValue.ToString("g"), result.DateTimeValue1);
            Assert.AreEqual(target.DesimalValue, result.DesimalValue1);
            Assert.AreEqual(target.StringValue, result.StringValue1);
            Assert.AreEqual("something", result.MyEnumName);
            Assert.AreEqual(2, result.MyEnumVal);
        }
Ejemplo n.º 2
0
        public void ListObjectTestType2()
        {
            MapFactory.ResetAllMaps();
            var target = new List <InnType>
            {
                new InnType {
                    DateTimeValue = DateTime.Now, DesimalValue = (decimal)100.212, StringValue = "test"
                },
                new InnType {
                    DateTimeValue = DateTime.Now, DesimalValue = (decimal)100.212, StringValue = "test"
                },
                new InnType {
                    DateTimeValue = DateTime.Now, DesimalValue = (decimal)100.212, StringValue = "test"
                }
            };
            var map = MapFactory.CreateEmptyMapRule <InnType, OutType2>();

            map.AddMap <InnType, OutType2>(new Dictionary <string, string>
            {
                { "DateTimeValue", "DateTimeValue" },
                { "DesimalValue", "DesimalValue1" },
                { "StringValue", "StringValue" }
            });
            var result = target.Map().To <OutType2>(map);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count());
        }