コード例 #1
0
ファイル: CallbackTests.cs プロジェクト: CXuesong/XSerializer
 public void CallbackTest()
 {
     var s = new XSerializer(typeof(MyClass));
     var obj = new MyClass("Callback Test");
     var doc = s.GetSerializedDocument(obj);
     Trace.WriteLine(doc);
     var obj1 = (MyClass)s.Deserialize(doc, null);
     Assert.AreEqual(obj.myString, obj1.myString);
 }
コード例 #2
0
 public void AnyElementTest()
 {
     var s = new XSerializer(typeof(MyClass));
     var obj = new MyClass("AnyElement / AnyAttribute Test")
     {
         attr = new[] {new XAttribute("a1", "value1"), new XAttribute("a2", DateTime.UtcNow)}
     };
     obj.Elem.Add(new XElement("customElement", "content1"));
     obj.Elem.Add(new XElement("customElement", 12345));
     obj.Elem.Add(new XElement("customElement", Guid.NewGuid()));
     var doc = s.GetSerializedDocument(obj);
     Trace.WriteLine(doc);
     var obj1 = (MyClass)s.Deserialize(doc, null);
     Assert.AreEqual(obj.myString, obj1.myString);
     Assert.AreEqual(obj.attr.Count, obj1.attr.Count);
     Assert.AreEqual(obj.Elem.Count, obj1.Elem.Count);
 }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: deadman2000/Expressions
        public void TestCall()
        {
            MyClass mc = new MyClass();

            Assert.AreEqual(40, Expression.GetProperty(mc, "myVar")); // Variable
            Assert.AreEqual(50, Expression.GetProperty(mc, "MyProp")); // Property

            Assert.AreEqual("abc", Expression.Call(mc, "StringMethod")); // Method
            Assert.AreEqual(null, Expression.Call(mc, "VoidMethod")); // Void method
            Assert.AreEqual("_xyz", Expression.Call(mc, "StringMethod", "xyz")); // Method with argument
            Assert.AreEqual(110d, Expression.Call(mc, "Increment", 60)); // Method with argument

            Assert.AreEqual(69, Expression.GetProperty(typeof(MyClass), "MyStaticProperty")); // Static propery
            Assert.AreEqual("abcabc", Expression.Call(typeof(MyClass), "MyStaticMethod", "abc")); // Static method

            // Privates test
            try
            {
                Expression.GetProperty(mc, "PrivateProp"); // Private property
                Assert.Fail();
            }
            catch { }

            try
            {
                Expression.GetProperty(mc, "PrivateVar"); // Private property
                Assert.Fail();
            }
            catch { }

            try
            {
                Expression.Call(mc, "PrivateMethod"); // Private method
                Assert.Fail();
            }
            catch { }
        }
コード例 #4
0
        public void EmptyTest()
        {
            MyClass myClass = new MyClass();

            myClass.deneme();
        }