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 : TestCase
19 public void TestClass1 ()
21 DerivedClass1 derived = new DerivedClass1 ();
22 derived.anotherInt = 69;
23 MemberInfo [] members = FormatterServices.GetSerializableMembers (derived.GetType ());
24 Assert ("#01", members != null);
25 AssertEquals ("#02", 3, members.Length);
27 object [] data = FormatterServices.GetObjectData (derived, members);
28 Assert ("#03", data != null);
29 AssertEquals ("#04", 3, data.Length);
31 DerivedClass1 o = (DerivedClass1) FormatterServices.GetUninitializedObject (derived.GetType ());
32 Assert ("#05", o != null);
34 o = (DerivedClass1) FormatterServices.PopulateObjectMembers (o, members, data);
35 Assert ("#06", o != null);
36 AssertEquals ("#07", "hola", o.Hello);
37 AssertEquals ("#08", 21, o.IntBase);
38 AssertEquals ("#09", 1, o.IntDerived);
39 AssertEquals ("#10", 69, o.anotherInt);
40 AssertEquals ("#11", "hey", DerivedClass1.hey);
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