コード例 #1
0
        void CheckObjectContent(Test exp, Test t)
        {
            AssertEquals("t.a", exp.a, t.a);
            AssertEquals("t.b", exp.b, t.b);
            AssertEquals("t.bbis", exp.bbis, t.bbis);
            AssertEquals("t.c", exp.c, t.c);

            AssertNotNull("t.parts", t.parts);
            CheckParts("t.parts", exp.parts, t.parts);

            TestPart.AssertEquals("t.part", exp.part, t.part);

            AssertionHelper.AssertEqualsArray("t.strings", exp.strings, t.strings);
            AssertionHelper.AssertEqualsArray("t.ushorts", exp.ushorts, t.ushorts);

            TA.AssertEquals("t.ta", exp.ta, t.ta);

            AssertNotNull("t.tam2", t.tam2);
            CheckTaArray("t.tam2", exp.tam2, t.tam2);

            AssertNotNull("t.tam3", t.tam3);
            CheckTaArray("t.tam3", exp.tam3, t.tam3);

            AssertNotNull("t.flatParts", t.flatParts);
            CheckParts("t.flatParts", exp.flatParts, t.flatParts);

            // Null element is ignored
            AssertNotNull("t.flatParts2", t.flatParts2);
            AssertEquals("t.flatParts2.Length", 3, t.flatParts2.Length);
            TA.AssertEquals("t.flatParts2 0", exp.flatParts2[0], t.flatParts2[0]);
            TA.AssertEquals("t.flatParts2 1", exp.flatParts2[1], t.flatParts2[1]);
            TA.AssertEquals("t.flatParts2 2", exp.flatParts2[3], t.flatParts2[2]);

            AssertNotNull("t.anot", t.anot);
            AssertEquals("t.anot.lo", ((AnotherTestPart)exp.anot).lo, ((AnotherTestPart)t.anot).lo);

            TestPart.AssertEquals("t.ob", exp.ob as TestPart, t.ob as TestPart);
            TestPart.AssertEquals("t.ob2", exp.ob2 as TestPart, t.ob2 as TestPart);

            AssertionHelper.AssertEqualsXml("t.oneElem", exp.oneElem, t.oneElem);
            AssertionHelper.AssertEqualsXml("t.oneElem2", exp.oneElem2, t.oneElem2);

            // One of the elements was null and it is ignored
            AssertNotNull("t.someElems", t.someElems);
            AssertEquals("t.someElems.Length", 2, t.someElems.Length);
            AssertionHelper.AssertEqualsXml("t.someElems[0]", exp.someElems[0], t.someElems[0]);
            AssertionHelper.AssertEqualsXml("t.someElems[1]", exp.someElems[2], t.someElems[1]);

            AssertNotNull("t.extraElems", t.extraElems);
            AssertEquals("t.extraElems.Length", exp.extraElems.Length, t.extraElems.Length);
            for (int n = 0; n < exp.extraElems.Length; n++)
            {
                AssertionHelper.AssertEqualsXml("t.extraElems[" + n + "]", exp.extraElems[n], t.extraElems[n]);
            }

            AssertNotNull("t.extraElems23", t.extraElems23);
            AssertEquals("t.extraElems23.Length", exp.extraElems23.Length, t.extraElems23.Length);
            for (int n = 0; n < t.extraElems23.Length; n++)
            {
                AssertionHelper.AssertEqualsXml("t.extraElems23[" + n + "]", exp.extraElems23[n], t.extraElems23[n]);
            }

            AssertionHelper.AssertEqualsXml("t.extraElemsRest", exp.extraElemsRest, t.extraElemsRest);

            UnknownAttributeTester.AssertEquals("t.uktester", exp.uktester, t.uktester);

            AssertEquals("t.ob3", exp.ob3, t.ob3);
            AssertEquals("t.ob4", exp.ob4, t.ob4);
            AssertEquals("t.op1", exp.op1, t.op1);

            AssertionHelper.AssertEqualsArray("t.opArray", exp.opArray, t.opArray);

            AssertEquals("t.ukOpt", exp.ukOpt, t.ukOpt);
            AssertEquals("t.opAtt", exp.opAtt, t.opAtt);

            AssertionHelper.AssertEqualsArray("t.byteArray", exp.byteArray, t.byteArray);
            AssertionHelper.AssertEqualsArray("t.byteByteArray", exp.byteByteArray, t.byteByteArray);

            AssertNotNull("t.ttList", t.ttList);
            AssertionHelper.AssertEqualsArray("t.ttList", exp.ttList.ToArray(), t.ttList.ToArray());

            AssertNotNull("t.RoList", t.RoList);
            AssertEquals("t.RoList.Count", exp.RoList.Count, t.RoList.Count);
            for (int n = 0; n < exp.RoList.Count; n++)
            {
                TestPart.AssertEquals("t.RoList " + n, (TestPart)exp.RoList[n], (TestPart)t.RoList[n]);
            }

            AssertEquals("t.struc.aa", exp.struc.aa, t.struc.aa);
            AssertEquals("t.struc.cc", exp.struc.cc, t.struc.cc);

            AssertNotNull("t.multiList", t.multiList);
            AssertEquals("t.multiList.Count", exp.multiList.Length, t.multiList.Length);
            for (int n = 0; n < exp.multiList.Length; n++)
            {
                AssertionHelper.AssertEqualsArray("t.multiList " + n, exp.multiList[n].ToArray(), t.multiList[n].ToArray());
            }

            AssertEquals("t.defElem", exp.defElem, t.defElem);
            AssertEquals("t.defAttr", exp.defAttr, t.defAttr);

            CustomHashtable.AssertEquals("t.special", exp.special, t.special);

            AssertEquals("t.attqname", exp.attqname, t.attqname);

            AssertNotNull("t.dbscontainer", t.dbscontainer);
            DblStringContainer tdbca   = t.dbscontainer.at as DblStringContainer;
            DblStringContainer expdbca = exp.dbscontainer.at as DblStringContainer;

            AssertNotNull("t.dbscontainer.at", tdbca);

            AssertNotNull("t.dbscontainer.dbca", tdbca);
            AssertionHelper.AssertEqualsArray("t.dbscontainer.at.doublestring", expdbca.doublestring, tdbca.doublestring);

            AnotherTestPart tat   = tdbca.at as AnotherTestPart;
            AnotherTestPart expat = expdbca.at as AnotherTestPart;

            AssertNotNull("t.dbscontainer.dbca.at", tat);
            AssertEquals("t.dbscontainer.dbca.at.lo", expat.lo, tat.lo);
        }
コード例 #2
0
        Test BuildTestObject()
        {
            XmlDocument doc = new XmlDocument();

            Test t = new UknTestPart();

            t.a                 = 1;
            t.b                 = "hola";
            t.bbis              = t.b;
            t.c                 = 44;
            t.parts             = new TestPart[3];
            t.parts[0]          = new TestPart();
            t.parts[0].name     = "un";
            t.parts[0].bval     = true;
            t.parts[1]          = new TestPart();
            t.parts[1].name     = "dos";
            t.parts[1].bval     = false;
            t.parts[2]          = t.parts[0];
            t.part              = t.parts[1];
            t.strings           = new string[] { "un", "dos", null, "tres" };
            t.ushorts           = new ushort[] { 1, 2, 3 };
            t.ta                = new TB();
            t.ta.extraTextNodes = new XmlNode[] { doc.CreateTextNode("AA"), doc.CreateTextNode("BB") };

            t.tam2 = new TA[][][]
            {
                new TA[][] { new TA[] { new TA(), new TA() }, new TA[] { new TA(), new TA() } },
                new TA[][] { new TA[] { new TB(), new TA() }, new TA[] { new TB(), new TA() } },
                new TA[][] { new TA[] { new TA(), new TB() }, new TA[] { new TA(), new TA() } }
            };

            t.tam3      = t.tam2;
            t.flatParts = t.parts;

            t.flatParts2 = new TA[] { new TA(), new TB(), null, new TB() };

            t.anot = new AnotherTestPart();
            ((AnotherTestPart)t.anot).lo = 1234567890;

            t.ob  = t.parts[1];
            t.ob2 = t.parts[1];

            XmlElement e1 = doc.CreateElement("explicitElement");
            XmlElement e2 = doc.CreateElement("subElement");

            e2.SetAttribute("unAtrib", "val");
            doc.AppendChild(e1);
            e1.AppendChild(e2);

            t.oneElem      = e1;
            t.oneElem2     = e1;
            t.someElems    = new XmlNode[3];
            t.someElems[0] = e1;
            t.someElems[1] = null;
            t.someElems[2] = e2;

            t.extraElems    = new XmlElement[1];
            t.extraElems[0] = doc.CreateElement("extra1");
            t.extraElems[0].SetAttribute("val", "1");

            t.extraElems23    = new XmlElement[2];
            t.extraElems23[0] = doc.CreateElement("extra2");
            t.extraElems23[0].SetAttribute("val", "2");
            t.extraElems23[1] = doc.CreateElement("extra3");
            t.extraElems23[1].SetAttribute("val", "3");

            t.extraElemsRest = doc.CreateElement("extra4");
            t.extraElemsRest.SetAttribute("val", "4");

            t.uktester    = new UnknownAttributeTester();
            t.uktester.aa = "hihi";

            t.uktester.extraAtts          = new XmlAttribute[3];
            t.uktester.extraAtts[0]       = doc.CreateAttribute("extraAtt1");
            t.uktester.extraAtts[0].Value = "val1";
            t.uktester.extraAtts[1]       = doc.CreateAttribute("extraAtt2");
            t.uktester.extraAtts[1].Value = "val2";
            t.uktester.extraAtts[2]       = doc.CreateAttribute("extraAtt3");
            t.uktester.extraAtts[2].Value = "val3";

            t.ob3 = 12345;
            t.ob4 = (float)54321.12;

            t.op1     = option.AA;
            t.opArray = new option[] { option.CC, option.BB, option.AA };
            t.ukOpt   = option.DD;
            t.opAtt   = option.BB;

            t.byteArray     = new byte[] { 11, 33, 55, 222 };
            t.byteByteArray = new byte[][] { t.byteArray, t.byteArray };

            t.ttList = new ArrayList();
            t.ttList.Add("two");
            t.ttList.Add("strings");
            //			t.extraText = "Additional text";

            t.RoList = new ArrayList();
            t.RoList.Add(t.parts[0]);
            t.RoList.Add(t.parts[1]);

/*			t.struc = new OneStruct();
 *                      t.struc.aa = 776655;
 *                      t.struc.cc = "this is a struct";
 */
            t.multiList    = new ArrayList[2];
            t.multiList[0] = new ArrayList();
            t.multiList[0].Add(22);
            t.multiList[0].Add(33);
            t.multiList[1] = new ArrayList();
            t.multiList[1].Add(888);
            t.multiList[1].Add(999);

            // XmlSerializer does not deserialize default values explicitly.
            //t.defElem = "theDefValue";
            //t.defAttr = "theDefValue";

            t.special = new CustomHashtable();
            t.special.Add("one", "1");
            t.special.Add("two", "2");
            t.special.Add("three", "3");

            t.attqname = new XmlQualifiedName("thename", "thenamespace");

            DblStringContainer dbc = new DblStringContainer();

            dbc.doublestring = new string [][] { null, new string[] { "hello" } };
            AnotherTestPart at = new AnotherTestPart();

            at.lo  = 567;
            dbc.at = at;

            DblStringContainerAnm dbca = new DblStringContainerAnm();

            dbca.at        = dbc;
            t.dbscontainer = dbca;

            return(t);
        }
コード例 #3
0
		Test BuildTestObject ()
		{
			XmlDocument doc = new XmlDocument();

			Test t = new UknTestPart();
			t.a = 1;
			t.b = "hola";
			t.bbis = t.b;
			t.c = 44;
			t.parts = new TestPart[3];
			t.parts[0] = new TestPart();
			t.parts[0].name = "un";
			t.parts[0].bval = true;
			t.parts[1] = new TestPart();
			t.parts[1].name = "dos";
			t.parts[1].bval = false;
			t.parts[2] = t.parts[0];
			t.part = t.parts[1];
			t.strings = new string[] { "un", "dos", null, "tres" };
			t.ushorts = new ushort[] { 1,2,3 };
			t.ta = new TB();
			t.ta.extraTextNodes = new XmlNode[] { doc.CreateTextNode ("AA"), doc.CreateTextNode ("BB") };

			t.tam2 = new TA[][][]
					{
						new TA[][] { new TA[] {new TA(), new TA()}, new TA[] {new TA(), new TA()}},
						new TA[][] { new TA[] {new TB(), new TA()}, new TA[] {new TB(), new TA()}},
						new TA[][] { new TA[] {new TA(), new TB()}, new TA[] {new TA(), new TA()}} 
					};

			t.tam3 = t.tam2;
			t.flatParts = t.parts;

			t.flatParts2 = new TA[] {new TA(), new TB(), null, new TB()};

			t.anot = new AnotherTestPart ();
			((AnotherTestPart)t.anot).lo = 1234567890;

			t.ob = t.parts[1];
			t.ob2 = t.parts[1];

			XmlElement e1 = doc.CreateElement ("explicitElement");
			XmlElement e2 = doc.CreateElement ("subElement");
			e2.SetAttribute ("unAtrib","val");
			doc.AppendChild (e1);
			e1.AppendChild (e2);

			t.oneElem = e1;
			t.oneElem2 = e1;
			t.someElems = new XmlNode[3];
			t.someElems[0] = e1;
			t.someElems[1] = null;
			t.someElems[2] = e2;

			t.extraElems = new XmlElement[1];
			t.extraElems[0] = doc.CreateElement ("extra1");
			t.extraElems[0].SetAttribute ("val","1");

			t.extraElems23 = new XmlElement[2];
			t.extraElems23[0] = doc.CreateElement ("extra2");
			t.extraElems23[0].SetAttribute ("val","2");
			t.extraElems23[1] = doc.CreateElement ("extra3");
			t.extraElems23[1].SetAttribute ("val","3");

			t.extraElemsRest = doc.CreateElement ("extra4");
			t.extraElemsRest.SetAttribute ("val","4");

			t.uktester = new UnknownAttributeTester();
			t.uktester.aa = "hihi";

			t.uktester.extraAtts = new XmlAttribute[3];
			t.uktester.extraAtts[0] = doc.CreateAttribute ("extraAtt1");
			t.uktester.extraAtts[0].Value = "val1";
			t.uktester.extraAtts[1] = doc.CreateAttribute ("extraAtt2");
			t.uktester.extraAtts[1].Value = "val2";
			t.uktester.extraAtts[2] = doc.CreateAttribute ("extraAtt3");
			t.uktester.extraAtts[2].Value = "val3";

			t.ob3 = 12345;
			t.ob4 = (float)54321.12;

			t.op1 = option.AA;
			t.opArray = new option[] { option.CC, option.BB, option.AA };
			t.ukOpt = option.DD;
			t.opAtt = option.BB;

			t.byteArray = new byte[] { 11,33,55,222 };
			t.byteByteArray = new byte[][] { t.byteArray, t.byteArray };

			t.ttList = new ArrayList();
			t.ttList.Add ("two");
			t.ttList.Add ("strings");
			//			t.extraText = "Additional text";

			t.RoList = new ArrayList ();
			t.RoList.Add (t.parts[0]);
			t.RoList.Add (t.parts[1]);

/*			t.struc = new OneStruct();
			t.struc.aa = 776655;
			t.struc.cc = "this is a struct";
*/
			t.multiList = new ArrayList[2];
			t.multiList[0] = new ArrayList ();
			t.multiList[0].Add (22);
			t.multiList[0].Add (33);
			t.multiList[1] = new ArrayList ();
			t.multiList[1].Add (888);
			t.multiList[1].Add (999);

			// XmlSerializer does not deserialize default values explicitly.
			//t.defElem = "theDefValue";
			//t.defAttr = "theDefValue";

			t.special = new CustomHashtable ();
			t.special.Add ("one","1");
			t.special.Add ("two","2");
			t.special.Add ("three","3");

			t.attqname = new XmlQualifiedName ("thename","thenamespace");

			DblStringContainer dbc = new DblStringContainer ();
			dbc.doublestring = new string [][] { null, new string[] {"hello"} };
			AnotherTestPart at = new AnotherTestPart ();
			at.lo = 567;
			dbc.at = at;

			DblStringContainerAnm dbca = new DblStringContainerAnm ();
			dbca.at = dbc;
			t.dbscontainer = dbca;
			
			return t;
		}