コード例 #1
0
        public void testMapObjects()
        {
            GenericListContainer input = new GenericListContainer("");

            input.stringToStringMapPropC      = new Dictionary <string, string>();
            input.stringToStringMapPropC["0"] = "zero";
            input.stringToStringMapPropC["1"] = "one";
            input.stringToStringMapPropC["2"] = "two";
            input.stringToStringMapPropC["3"] = "three";

            input.intToStringMapPropC    = new Dictionary <int, string>();
            input.intToStringMapPropC[0] = "zero";
            input.intToStringMapPropC[1] = "one";
            input.intToStringMapPropC[2] = "two";
            input.intToStringMapPropC[3] = "three";


            string json = mapping.getObject2Json().toJson(input);

            GenericListContainer output = (GenericListContainer)mapping.getJson2Object().toObject(json, typeof(GenericListContainer));

            Func <GenericListContainer, string, string> extractValue;

            extractValue = (glc, strKey) => { return(glc.stringToStringMapPropC[strKey]); };
            foreach (string strKey in  input.stringToStringMapPropC.Keys)
            {
                Assert.AreEqual(extractValue(input, strKey), extractValue(output, strKey), "checking key " + strKey);
            }

            Func <GenericListContainer, int, string> extractIValue;

            extractIValue = (glc, iKey) => { return(glc.intToStringMapPropC[iKey]); };
            foreach (int iKey in input.intToStringMapPropC.Keys)
            {
                Assert.AreEqual(extractIValue(input, iKey), extractIValue(output, iKey), "checking key " + iKey);
            }
        }