Exemple #1
0
        public void Second_Level_Nested_Objects_Should_Work()
        {
            var flatObject = new Dictionary <string, string>()
            {
                { "Address_Country_Symbol", "ro" },
                { "Address_Country_Name", "Romania" },
                { "Address_Street", "Victory Street" },
                { "Address_PhoneNumber", "321321423" },
                { "Username", "John" },
                { "Email", "*****@*****.**" },
            };
            var unflattenedObject = new DictionaryFlattener().Unflatten(flatObject);

            Assert.IsTrue(unflattenedObject.ContainsKey("Username"));
            Assert.AreEqual("John", unflattenedObject["Username"]);
            Assert.IsTrue(unflattenedObject.ContainsKey("Email"));
            Assert.AreEqual("*****@*****.**", unflattenedObject["Email"]);
            Assert.IsTrue(unflattenedObject.ContainsKey("Address"));
            var address = unflattenedObject["Address"] as Dictionary <StringSegment, object>;

            Assert.IsNotNull(address);
            Assert.IsTrue(address.ContainsKey("Street"));
            Assert.AreEqual("Victory Street", address["Street"]);
            Assert.IsTrue(address.ContainsKey("PhoneNumber"));
            Assert.AreEqual("321321423", address["PhoneNumber"]);
            Assert.IsTrue(address.ContainsKey("Country"));
            var country = address["Country"] as Dictionary <StringSegment, object>;

            Assert.IsNotNull(country);
            Assert.IsTrue(country.ContainsKey("Symbol"));
            Assert.AreEqual("ro", country["Symbol"]);
            Assert.IsTrue(country.ContainsKey("Name"));
            Assert.AreEqual("Romania", country["Name"]);
        }
Exemple #2
0
        public void Simple_Objects_Are_Same()
        {
            var flatObject = new Dictionary <string, string>()
            {
                { "Username", "John" },
                { "Email", "*****@*****.**" }
            };
            var unflattenedObject = new DictionaryFlattener().Unflatten(flatObject);

            Assert.IsTrue(unflattenedObject.ContainsKey("Username"));
            Assert.AreEqual("John", unflattenedObject["Username"]);
            Assert.IsTrue(unflattenedObject.ContainsKey("Email"));
            Assert.AreEqual("*****@*****.**", unflattenedObject["Email"]);
        }