public void TestDictionary()
        {
            string xml = @"<userInfo userName='******' email='*****@*****.**' age='27'>   
                                <colleagues> 
                                     <colleague>
                                        <key>1</key>
                                        <value>
                                            <userName>zfx</userName>
                                            <email>[email protected]</email>
                                            <age>100</age> 
                                        </value>
                                    </colleague>
                                    <colleague>
                                        <key>2</key>
                                        <value>
                                            <userName>zk</userName>
                                            <email>[email protected]</email>
                                            <age>30</age> 
                                        </value>
                                    </colleague>
                                </colleagues>   
                            </userInfo>";

            UserInfo user = SuperConfig.Mapping <UserInfo>(XElement.Parse(xml));

            Assert.AreEqual(user.UserName, "Emrys");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.AreEqual(user.Age, 27);

            Assert.AreEqual(user.Colleagues[1].Age, 100);
            Assert.AreEqual(user.Colleagues[1].UserName, "zfx");
            Assert.AreEqual(user.Colleagues[2].Email, "*****@*****.**");
        }
        public void TestDictionarySimple()
        {
            var dic = SuperConfig.Mapping <Dictionary <int, string> >("dictionaryIntString");

            Assert.AreEqual(dic.First().Key, 1);
            Assert.AreEqual(dic.Last().Value, "b");
        }
        public void TestDictionaryNoEntity()
        {
            string xml = @"<colleagues> 
                              <colleague>
                                <key>1</key>
                                <value>
                                    <userName>zfx</userName>
                                    <email>[email protected]</email>
                                    <age>100</age> 
                                </value>
                            </colleague>
                            <colleague>
                                <key>2</key>
                                <value>
                                    <userName>zk</userName>
                                    <email>[email protected]</email>
                                    <age>30</age> 
                                </value>
                            </colleague>
                         </colleagues>";

            var dic = SuperConfig.Mapping <Dictionary <int, UserInfo> >(XElement.Parse(xml));



            Assert.AreEqual(dic[1].Age, 100);
            Assert.AreEqual(dic[1].UserName, "zfx");
            Assert.AreEqual(dic[2].Email, "*****@*****.**");
        }
        public void TestListSimple()
        {
            var listString = SuperConfig.Mapping <List <string> >("listString");

            Assert.AreEqual(listString.First(), "a");
            Assert.AreEqual(listString.Count, 4);
        }
Esempio n. 5
0
        public void TestValueAttributes()
        {
            string         xml            = "<testValueClass name='Emrys' age='18'><colors>1</colors></testValueClass>";
            XElement       XElement       = XElement.Parse(xml);
            TestValueClass testValueClass = SuperConfig.Mapping(typeof(TestValueClass), XElement) as TestValueClass;

            Assert.AreEqual(testValueClass.Name, "Emrys");
            Assert.AreEqual(testValueClass.Age, 18);
        }
Esempio n. 6
0
        public void TestValueElement()
        {
            string         xml            = "<testValueClass><name>Emrys</name><age>18</age></testValueClass>";
            XElement       XElement       = XElement.Parse(xml);
            TestValueClass testValueClass = SuperConfig.Mapping(typeof(TestValueClass), XElement) as TestValueClass;

            Assert.AreEqual(testValueClass.Name, "Emrys");
            Assert.AreEqual(testValueClass.Age, 18);
        }
        public void TestKeyValueNoEntity()
        {
            string xml = @"<sports  key='1' value='PingPong'>
                           </sports>";

            KeyValuePair <int, string> keyValue = SuperConfig.Mapping <KeyValuePair <int, string> >(XElement.Parse(xml));

            Assert.AreEqual(keyValue.Key, 1);
            Assert.AreEqual(keyValue.Value, "PingPong");
        }
        public void TestKeyValueAndSimpleTypeCache()
        {
            var sport     = SuperConfig.Mapping <KeyValuePair <int, string> >("sport");
            var superStar = SuperConfig.Mapping <KeyValuePair <int, string> >("superStar");

            Assert.AreEqual(sport.Key, 2);
            Assert.AreEqual(sport.Value, "Football");
            Assert.AreEqual(superStar.Key, 7);
            Assert.AreEqual(superStar.Value, "Jackchen");
        }
Esempio n. 9
0
        public void TestKeyValue()
        {
            string            xml            = @"<TestKeyValueClass>
                            <keyValueTest>
                                <key>Emrys</key>
                                <value>18</value>
                            </keyValueTest>
                            </TestKeyValueClass>";
            XElement          XElement       = XElement.Parse(xml);
            TestKeyValueClass testValueClass = (TestKeyValueClass)SuperConfig.Mapping(typeof(TestKeyValueClass), XElement);

            Assert.AreEqual(testValueClass.KeyValueTest.Key, "Emrys");
            Assert.AreEqual(testValueClass.KeyValueTest.Value, 18);
        }
Esempio n. 10
0
        public void TestListSimple()
        {
            string        xml      = @"<testListClass>
                            <colors>
                             <item>blue</item>
                             <item>red</item>
                             <item>orgin</item>
                           </colors>
                            </testListClass>";
            XElement      XElement = XElement.Parse(xml);
            TestListClass t        = (TestListClass)SuperConfig.Mapping(typeof(TestListClass), XElement);

            Assert.AreEqual(t.Colors.First(), "blue");
            Assert.AreEqual(t.Colors.Last(), "orgin");
        }
Esempio n. 11
0
        public void TestKeyValueAttributes()
        {
            string xml = @"<userInfo userName='******' email='*****@*****.**' age='27'>   
                                <sports key='1' value='PingPong'></sports>   
                            </userInfo>";

            UserInfo user = SuperConfig.Mapping <UserInfo>(XElement.Parse(xml));

            Assert.AreEqual(user.UserName, "Emrys");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.AreEqual(user.Age, 27);

            Assert.AreEqual(user.Sports.Key, 1);
            Assert.AreEqual(user.Sports.Value, "PingPong");
        }
Esempio n. 12
0
        public void TestListNoEntity()
        {
            string xml = @"<list>   
                                <item>1</item>
                                <item>2</item>                
                                <item>3</item>                
                                <item>4</item>                
                                <item>5</item>                
                                <item>6</item>                
                            </list>";

            var list = SuperConfig.Mapping <List <int> >(XElement.Parse(xml));

            Assert.AreEqual(list.First(), 1);
            Assert.AreEqual(list.Count, 6);
        }
Esempio n. 13
0
        public void TestListModel()
        {
            string xml = @"<TestListModel>
                            <testValue>
                                <item name='Emrys' age='18'><colors>1</colors></item>
                               <item name='Emrys' age='18'><colors>1</colors></item>
                               <item name='Emrys' age='180'><colors>1</colors></item>
                           </testValue>
                          </TestListModel>";

            XElement      XElement = XElement.Parse(xml);
            TestListModel t        = (TestListModel)SuperConfig.Mapping(typeof(TestListModel), XElement);

            Assert.AreEqual(t.TestValue.First().Name, "Emrys");
            Assert.AreEqual(t.TestValue.Last().Age, 180);
        }
Esempio n. 14
0
        public void TestValueAttributesElements()
        {
            string xml = @"<userInfo userName='******' email='*****@*****.**' age='27'>   
                                <blogUrl>http://www.cnblogs.com/emrys5/</blogUrl>
                                <favoriteColor>Blue</favoriteColor>
                                <dislikeColor>2</dislikeColor> 
                            </userInfo>";

            UserInfo user = SuperConfig.Mapping <UserInfo>(XElement.Parse(xml));

            Assert.AreEqual(user.UserName, "Emrys");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.AreEqual(user.Age, 27);
            Assert.AreEqual(user.BlogUrl, "http://www.cnblogs.com/emrys5/");
            Assert.AreEqual(user.FavoriteColor, Color.Blue);
            Assert.AreEqual(user.DislikeColor, Color.Black);
        }
Esempio n. 15
0
        public void TestArrayNoEntity()
        {
            string xml = @"<users> 
                                <user userName='******' email='*****@*****.**' age='35'></user>
                                <user>
                                    <userName>wy</userName>
                                    <email>[email protected]</email>
                                    <age>30</age> 
                                </user> 
                            </users>";

            var array = SuperConfig.Mapping <UserInfo[]>(XElement.Parse(xml));


            Assert.AreEqual(array.First().UserName, "hx");
            Assert.AreEqual(array.Last().Age, 30);
        }
Esempio n. 16
0
        public void TestDictionaryClass()
        {
            string xml = @"<testDictionary>
                            <testDictionary>
                                <item key='emrys'>
                                   <value name='Emrys' age='18' colors='Blue'></value>
                                </item> 
                           </testDictionary>
                          </testDictionary>";

            XElement XElement = XElement.Parse(xml);

            TestDictionaryClass t = SuperConfig <TestDictionaryClass> .Mapping(XElement);


            Assert.AreEqual(t.TestDictionary["emrys"].Name, "Emrys");
            Assert.AreEqual(t.TestDictionary["emrys"].Colors, Colors.Blue);
        }
Esempio n. 17
0
        public void TestListSimple()
        {
            string xml = @"<userInfo userName='******' email='*****@*****.**' age='27'>   
                                <language> 
                                    <value>Putonghua</value>
                                    <value>Huaipu</value>
                                    <value>English</value>
                                </language>   
                            </userInfo>";

            UserInfo user = SuperConfig.Mapping <UserInfo>(XElement.Parse(xml));

            Assert.AreEqual(user.UserName, "Emrys");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.AreEqual(user.Age, 27);

            Assert.AreEqual(user.Language.First(), "Putonghua");
            Assert.AreEqual(user.Language.Last(), "English");
        }
        public void TestSetSectionArray()
        {
            var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cfg", "SetSection.config");

            var array = SuperConfig.Mapping <string[]>("arrayString", configFilePath, null, (sectionName, filePath, convertCaseStrategy) =>
            {
                XElement xElement   = XElement.Load(filePath);
                var caseSectionName = convertCaseStrategy.ConvertCase(sectionName);
                var sectionElement  = xElement.Elements().Where(i => i.Name == caseSectionName).FirstOrDefault();
                if (sectionElement == null)
                {
                    throw new Exception("dot find section:" + sectionName);
                }

                return(new Section()
                {
                    XElement = sectionElement
                });
            });

            Assert.AreEqual(array.First(), "a");
        }
Esempio n. 19
0
        public void TestList()
        {
            string xml = @"<userInfo userName='******' email='*****@*****.**' age='27'>   
                                <family> 
                                    <item userName='******' email='*****@*****.**' age='50'></item>
                                    <item>
                                        <userName>ly</userName>
                                        <email>[email protected]</email>
                                        <age>30</age> 
                                    </item> 
                                </family>   
                            </userInfo>";

            UserInfo user = SuperConfig.Mapping <UserInfo>(XElement.Parse(xml));

            Assert.AreEqual(user.UserName, "Emrys");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.AreEqual(user.Age, 27);

            Assert.AreEqual(user.Family.First().Age, 50);
            Assert.AreEqual(user.Family.Last().UserName, "ly");
        }
Esempio n. 20
0
        public void TestArray()
        {
            string xml = @"<userInfo userName='******' email='*****@*****.**' age='27'>   
                                <friends> 
                                    <friend userName='******' email='*****@*****.**' age='35'></friend>
                                    <friend>
                                        <userName>wy</userName>
                                        <email>[email protected]</email>
                                        <age>30</age> 
                                    </friend> 
                                </friends>   
                            </userInfo>";

            UserInfo user = SuperConfig.Mapping <UserInfo>(XElement.Parse(xml));

            Assert.AreEqual(user.UserName, "Emrys");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.AreEqual(user.Age, 27);

            Assert.AreEqual(user.Friends.First().Age, 35);
            Assert.AreEqual(user.Friends.Last().UserName, "wy");
        }
Esempio n. 21
0
 public object Mapping(XElement element, Type type)
 {
     return(SuperConfig.Mapping(type, element, ConvertCaseStrategy));
 }