2 // System.Runtime.Serialization.FormatterServicesTests: NUnit test
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (c) 2002 Ximian Inc. (http://www.ximian.com)
10 using NUnit.Framework;
12 using System.Reflection;
13 using System.Runtime.Serialization;
15 namespace MonoTests.System.Runtime.Serialization
17 public class FormatterServicesTests
19 public void TestClass1 ()
21 DerivedClass1 derived = new DerivedClass1 ();
22 derived.anotherInt = 69;
23 MemberInfo [] members = FormatterServices.GetSerializableMembers (derived.GetType ());
24 Assert.IsTrue (members != null, "#01");
25 Assert.AreEqual (3, members.Length, "#02");
27 object [] data = FormatterServices.GetObjectData (derived, members);
28 Assert.IsTrue (data != null, "#03");
29 Assert.AreEqual (3, data.Length, "#04");
31 DerivedClass1 o = (DerivedClass1) FormatterServices.GetUninitializedObject (derived.GetType ());
32 Assert.IsTrue (o != null, "#05");
34 o = (DerivedClass1) FormatterServices.PopulateObjectMembers (o, members, data);
35 Assert.IsTrue (o != null, "#06");
36 Assert.AreEqual ("hola", o.Hello, "#07");
37 Assert.AreEqual (21, o.IntBase, "#08");
38 Assert.AreEqual (1, o.IntDerived, "#09");
39 Assert.AreEqual (69, o.anotherInt, "#10");
40 Assert.AreEqual ("hey", DerivedClass1.hey, "#11");
47 public string hello = "hola";
48 static int intBase = 21;
50 public override int GetHashCode ()
52 return base.GetHashCode ();
55 public override bool Equals (object o)
57 BaseClass1 bc = o as BaseClass1;
64 return (hello == bc.hello);
83 class DerivedClass1 : BaseClass1
85 private int intDerived = 1;
86 [NonSerialized] public int publicint = 2;
87 public int anotherInt = 22;
88 public static string hey = "hey";
97 public void SomeMethod ()
102 public override int GetHashCode ()
104 return base.GetHashCode ();
107 public override bool Equals (object o)
109 DerivedClass1 dc = o as DerivedClass1;
113 if (anotherInt != 22 || hey != "hey")
116 return (anotherInt == dc.anotherInt);
119 public int IntDerived