コード例 #1
0
ファイル: MiniMapperTest.cs プロジェクト: OLAPADE1/commerce
        public void CanMapAnonymousType()
        {
            var from = new
            {
                Prop1   = "Prop1",
                Prop2   = "Prop2",
                Prop3   = "Prop3",
                Address = new
                {
                    FirstName = "John",
                    LastName  = "Doe",
                    Age       = 24
                }
            };

            var to = new MapClass2();

            MiniMapper.Map(from, to);

            Assert.AreEqual(from.Prop1, to.Prop1);
            Assert.AreEqual(from.Prop2, to.Prop2);
            Assert.AreEqual(from.Prop3, to.Prop3);

            var dict = to.Address;

            Assert.AreEqual(dict.Count, 3);
            Assert.AreEqual(dict["FirstName"], from.Address.FirstName);
            Assert.AreEqual(dict["LastName"], from.Address.LastName);
            Assert.AreEqual(dict["Age"], from.Address.Age);
        }
コード例 #2
0
ファイル: MiniMapperTest.cs プロジェクト: OLAPADE1/commerce
        public void CanMap2()
        {
            var from = new MapClass2
            {
                Prop1 = "Prop1",
                Prop2 = "Prop2",
                Prop3 = "Prop3"
            };

            from.Address["FirstName"] = "John";
            from.Address["LastName"]  = "Doe";
            from.Address["Age"]       = 24;

            var to = MiniMapper.Map <MapClass2, MapClass1>(from);

            Assert.AreEqual(from.Prop1, to.Prop1);
            Assert.AreEqual(from.Prop2, to.Prop2);
            Assert.AreEqual(from.Prop3, to.Prop3);

            var dict = from.Address;

            Assert.AreEqual(dict.Count, 3);
            Assert.AreEqual(dict["FirstName"], to.Address.FirstName);
            Assert.AreEqual(dict["LastName"], to.Address.LastName);
            Assert.AreEqual(dict["Age"], to.Address.Age);
        }