public void EmPropertyCollection_WithNestedCollection_ToString_GetExpected()
        {
            var nestedComplex = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <string>("Nstring", "Nval"),
                new EmProperty <int>("Nint", 10),
            });

            var properties = new List <EmProperty>
            {
                new EmProperty <string>("String", "Val"),
                new EmProperty <int>("Int", 12),
                new EmPropertyList <float>("FloatList", new List <float> {
                    1.0f, 2.1f, 3.2f
                }),
                nestedComplex
            };


            var testProp = new TestSimpleCollection("TestKey", properties);

            const string expectedValue = "TestKey:" +
                                         "(" +
                                         "String:Val;" +
                                         "Int:12;" +
                                         "FloatList:1,2.1,3.2;" +
                                         "Nested:" +
                                         "(" +
                                         "Nstring:Nval;" +
                                         "Nint:10;" +
                                         ");" +
                                         ");";

            Assert.AreEqual(expectedValue, testProp.ToString());
        }
        public void EmPropertyCollection_FromString_GoodString_GetExpected(string stValue, string escapedValue)
        {
            string testValue = "TestKey:" +
                               "(" +
                               $"String:{escapedValue};" +
                               "Int:12;" +
                               "FloatList:1,2.1,3.2;" +
                               ");";

            var properties = new List <EmProperty>()
            {
                new EmProperty <string>("String"),
                new EmProperty <int>("Int"),
                new EmPropertyList <float>("FloatList"),
            };

            var testProp = new TestSimpleCollection("TestKey", properties);

            testProp.FromString(testValue);

            Assert.AreEqual(stValue, ((EmProperty <string>)testProp["String"]).Value);
            Assert.AreEqual(12, ((EmProperty <int>)testProp["Int"]).Value);

            Assert.AreEqual(3, ((EmPropertyList <float>)testProp["FloatList"]).Count);
            Assert.AreEqual(1.0f, ((EmPropertyList <float>)testProp["FloatList"])[0]);
            Assert.AreEqual(2.1f, ((EmPropertyList <float>)testProp["FloatList"])[1]);
            Assert.AreEqual(3.2f, ((EmPropertyList <float>)testProp["FloatList"])[2]);
        }
예제 #3
0
        public void EmPropertyCollectionList_WithMultiEntries_FromString_GetExpected()
        {
            const string testValue = "NestedComplexList:" +
                                     "(" +
                                     "Nstring:Val1;" +
                                     "Nint:2;" +
                                     ")," +
                                     "(" +
                                     "Nstring:Val3;," +
                                     "Nint:4;" +
                                     ");";

            var complexStructure = new List <EmProperty>
            {
                new EmProperty <string>("Nstring"),
                new EmProperty <int>("Nint"),
            };

            var twoKeyCollection = new TestSimpleCollection("NestedComplexList", complexStructure);

            var compList = new EmPropertyCollectionList <TestSimpleCollection>("NestedComplexList", twoKeyCollection);

            compList.FromString(testValue);

            Assert.AreEqual(2, compList.Collections.Count);

            Assert.AreEqual("Val1", ((EmProperty <string>)compList[0]["Nstring"]).Value);
            Assert.AreEqual(2, ((EmProperty <int>)compList[0]["Nint"]).Value);

            Assert.AreEqual("Val3", ((EmProperty <string>)compList[1]["Nstring"]).Value);
            Assert.AreEqual(4, ((EmProperty <int>)compList[1]["Nint"]).Value);
        }
        public void EmPropertyCollection_WithNestedCollection_ToAndFromString_DataPreserved()
        {
            var nestedComplexOrig = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <string>("Nstring", "Nval"),
                new EmProperty <int>("Nint", 10),
            });

            const string text   = "Val : has ; special";
            const int    number = 12;

            var list = new List <float> {
                1.0f, 2.1f, 3.2f
            };

            var propertiesOrig = new List <EmProperty>
            {
                new EmProperty <string>("String", text),
                new EmProperty <int>("Int", number),
                new EmPropertyList <float>("FloatList", list),
                nestedComplexOrig
            };

            var orig = new TestSimpleCollection("TestKey", propertiesOrig);

            var nestedComplex = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <string>("Nstring"),
                new EmProperty <int>("Nint"),
            });

            var properties = new List <EmProperty>
            {
                new EmProperty <string>("String"),
                new EmProperty <int>("Int"),
                new EmPropertyList <float>("FloatList"),
                nestedComplex
            };

            var deserialized = new TestSimpleCollection("TestKey", properties);

            string originalSerialized = orig.ToString();

            deserialized.FromString(originalSerialized);

            string serialized = deserialized.ToString();

            Assert.AreEqual(originalSerialized, serialized);

            Assert.AreEqual(text, ((EmProperty <string>)deserialized["String"]).Value);
            Assert.AreEqual(number, ((EmProperty <int>)deserialized["Int"]).Value);

            Assert.AreEqual(list.Count, ((EmPropertyList <float>)deserialized["FloatList"]).Count);
            Assert.AreEqual(list[0], ((EmPropertyList <float>)deserialized["FloatList"])[0]);
            Assert.AreEqual(list[1], ((EmPropertyList <float>)deserialized["FloatList"])[1]);
            Assert.AreEqual(list[2], ((EmPropertyList <float>)deserialized["FloatList"])[2]);

            Assert.AreEqual("Nval", ((EmProperty <string>)((EmPropertyCollection)deserialized["Nested"])["Nstring"]).Value);
            Assert.AreEqual(10, ((EmProperty <int>)((EmPropertyCollection)deserialized["Nested"])["Nint"]).Value);
        }
        public void EmPropertyCollection_WithNestedCollection_ToAndFromString_DataPreserved()
        {
            var nestedComplexOrig = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <string>("Nstring", "Nval"),
                new EmProperty <int>("Nint", 10),
            });

            var propertiesOrig = new List <EmProperty>
            {
                new EmProperty <string>("String", "Val"),
                new EmProperty <int>("Int", 12),
                new EmPropertyList <float>("FloatList", new List <float> {
                    1.0f, 2.1f, 3.2f
                }),
                nestedComplexOrig
            };

            var orig = new TestSimpleCollection("TestKey", propertiesOrig);

            var nestedComplex = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <string>("Nstring"),
                new EmProperty <int>("Nint"),
            });

            var properties = new List <EmProperty>
            {
                new EmProperty <string>("String"),
                new EmProperty <int>("Int"),
                new EmPropertyList <float>("FloatList"),
                nestedComplex
            };

            var deserialized = new TestSimpleCollection("TestKey", properties);

            string originalSerialized = orig.ToString();

            deserialized.FromString(originalSerialized);

            string serialized = deserialized.ToString();

            Assert.AreEqual(originalSerialized, serialized);

            Assert.AreEqual("Val", ((EmProperty <string>)deserialized["String"]).Value);
            Assert.AreEqual(12, ((EmProperty <int>)deserialized["Int"]).Value);

            Assert.AreEqual(3, ((EmPropertyList <float>)deserialized["FloatList"]).Count);
            Assert.AreEqual(1.0f, ((EmPropertyList <float>)deserialized["FloatList"])[0]);
            Assert.AreEqual(2.1f, ((EmPropertyList <float>)deserialized["FloatList"])[1]);
            Assert.AreEqual(3.2f, ((EmPropertyList <float>)deserialized["FloatList"])[2]);

            Assert.AreEqual("Nval", ((EmProperty <string>)((EmPropertyCollection)deserialized["Nested"])["Nstring"]).Value);
            Assert.AreEqual(10, ((EmProperty <int>)((EmPropertyCollection)deserialized["Nested"])["Nint"]).Value);
        }
        public void EmPropertyCollection_WithNestedCollection_PrettyPrint_GetExpected()
        {
            const string testValue = "TestKey: " +
                                     "(" +
                                     "String: Val;" +
                                     "Int: 12;" +
                                     "FloatList: 1,2.1,3.2;" +
                                     "Nested:" +
                                     "(" +
                                     "Nstring: Nval;" +
                                     "Nint: 10;" +
                                     ");" +
                                     ");";

            const string expectedValue = "TestKey: \r\n" +
                                         "(\r\n" +
                                         "    String: Val;\r\n" +
                                         "    Int: 12;\r\n" +
                                         "    FloatList: 1,2.1,3.2;\r\n" +
                                         "    Nested: \r\n" +
                                         "    (\r\n" +
                                         "        Nstring: Nval;\r\n" +
                                         "        Nint: 10;\r\n" +
                                         "    );\r\n" +
                                         ");\r\n";

            var nestedComplex = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <string>("Nstring"),
                new EmProperty <int>("Nint"),
            });

            var properties = new List <EmProperty>
            {
                new EmProperty <string>("String"),
                new EmProperty <int>("Int"),
                new EmPropertyList <float>("FloatList"),
                nestedComplex
            };

            var testProp = new TestSimpleCollection("TestKey", properties);

            testProp.FromString(testValue);

            string actualValue = testProp.PrettyPrint();

            Assert.AreEqual(expectedValue, actualValue);
        }
        public void EmPropertyCollection_WithNestedCollection_FromString_GetExpected()
        {
            const string testValue = "TestKey:" +
                                     "(" +
                                     "String:Val;" +
                                     "Int:12;" +
                                     "FloatList:1,2.1,3.2;" +
                                     "Nested:" +
                                     "(" +
                                     "Nstring:Nval;" +
                                     "Nint:10;" +
                                     ");" +
                                     ");";

            var nestedComplex = new TestSimpleCollection("Nested", new List <EmProperty>
            {
                new EmProperty <int>("Nint"),
                new EmProperty <string>("Nstring"),
            });

            var properties = new List <EmProperty>
            {
                new EmProperty <int>("Int"),
                new EmProperty <string>("String"),
                new EmPropertyList <float>("FloatList"),
                nestedComplex
            };

            var testProp = new TestSimpleCollection("TestKey", properties);

            testProp.FromString(testValue);

            Assert.AreEqual("Val", ((EmProperty <string>)testProp["String"]).Value);
            Assert.AreEqual(12, ((EmProperty <int>)testProp["Int"]).Value);

            Assert.AreEqual(3, ((EmPropertyList <float>)testProp["FloatList"]).Count);
            Assert.AreEqual(1.0f, ((EmPropertyList <float>)testProp["FloatList"])[0]);
            Assert.AreEqual(2.1f, ((EmPropertyList <float>)testProp["FloatList"])[1]);
            Assert.AreEqual(3.2f, ((EmPropertyList <float>)testProp["FloatList"])[2]);

            Assert.AreEqual("Nval", ((EmProperty <string>)((EmPropertyCollection)testProp["Nested"])["Nstring"]).Value);
            Assert.AreEqual(10, ((EmProperty <int>)((EmPropertyCollection)testProp["Nested"])["Nint"]).Value);
        }
        public void EmPropertyCollection_NoNestedComplex_ToString_GetExpected(string stValue, string escapedValue)
        {
            var properties = new List <EmProperty>()
            {
                new EmProperty <string>("String", stValue),
                new EmProperty <int>("Int", 12),
                new EmPropertyList <float>("FloatList", new List <float> {
                    1.0f, 2.1f, 3.2f
                }),
            };

            var testProp = new TestSimpleCollection("TestKey", properties);

            string expectedValue = "TestKey:" +
                                   "(" +
                                   $"String:{escapedValue};" +
                                   "Int:12;" +
                                   "FloatList:1,2.1,3.2;" +
                                   ");";

            Assert.AreEqual(expectedValue, testProp.ToString());
        }