Esempio n. 1
0
        public void TestSingleDelegate()
        {
            var temp = new DelegateTestClass();

            temp.Target = new DelegateTargetTestClass();
            temp.Del    = new DelegateTestClass.DelegateTest(temp.Target.MyHandler);
            Assert.NotNull(temp.Target);
            Assert.NotNull(temp.Del);

            temp.Target.Value = "Serialized.";

            var doc = XmlSerializer.Serialize(temp, 1, "delegate_test");
            //doc.Save(Application.dataPath + "/t.xml");

            var temp2 = XmlDeserializer.Deserialize(doc.InnerXml, 1) as DelegateTestClass;

            Assert.NotNull(temp2);
            Assert.NotNull(temp2.Target);
            Assert.NotNull(temp2.Del);

            Assert.AreNotSame(temp, temp2);
            Assert.AreNotSame(temp.Target, temp2.Target);
            Assert.AreNotSame(temp.Del, temp2.Del);

            Assert.AreEqual("Serialized.", temp2.Target.Value);

            temp2.Del("Invoked."); //already asserted for null value
            Assert.AreEqual("Invoked.", temp2.Target.Value);
        }
Esempio n. 2
0
        public void TestMultiDelegate()
        {
            var temp = new DelegateTestClass();

            temp.Target = new DelegateTargetTestClass();
            temp.Del    = temp.Target.MyHandler1;
            temp.Del   += temp.Target.MyHandler2;
            Assert.NotNull(temp.Target);
            Assert.NotNull(temp.Del);
            Assert.AreEqual(2, temp.Del.GetInvocationList().Length);

            temp.Del("");
            Assert.AreEqual("Not Changed._X_O", temp.Target.Value);
            temp.Target.Value = "Serialized.";

            var doc = XmlSerializer.Serialize(temp, 1, "delegate_test");
            //doc.Save(Application.dataPath + "/t.xml");

            var temp2 = XmlDeserializer.Deserialize(doc.InnerXml, 1) as DelegateTestClass;

            Assert.NotNull(temp2);
            Assert.NotNull(temp2.Target);
            Assert.NotNull(temp2.Del);

            Assert.AreNotSame(temp, temp2);
            Assert.AreNotSame(temp.Target, temp2.Target);
            Assert.AreNotSame(temp.Del, temp2.Del);

            Assert.AreEqual("Serialized.", temp2.Target.Value);
            Assert.AreEqual(2, temp2.Del.GetInvocationList().Length);

            temp2.Del(""); //already asserted for null value
            Assert.AreEqual("Serialized._X_O", temp2.Target.Value);
        }