public void GetObjectData_IEqualityComparer () { EqualityComparer comparer = new EqualityComparer (); UnitTestNameObjectCollectionBase coll = new UnitTestNameObjectCollectionBase (5, comparer); coll.Add ("a", "1"); coll.Add ("b", "2"); coll._IsReadOnly = true; SerializationInfo si = new SerializationInfo (typeof (UnitTestNameObjectCollectionBase), new FormatterConverter ()); coll.GetObjectData (si, new StreamingContext ()); foreach (SerializationEntry se in si) { switch (se.Name) { case "KeyComparer": Assert.AreSame (comparer, se.Value, se.Name); break; case "ReadOnly": Assert.IsTrue ((bool) se.Value, se.Name); break; case "Count": Assert.AreEqual (2, se.Value, se.Name); break; case "Values": Assert.AreEqual (2, (se.Value as object[]).Length, se.Name); break; case "Keys": Assert.AreEqual (2, (se.Value as string[]).Length, se.Name); break; case "Version": Assert.AreEqual (4, se.Value, se.Name); break; default: string msg = String.Format ("Unexpected {0} information of type {1} with value '{2}'.", se.Name, se.ObjectType, se.Value); Assert.Fail (msg); break; } } }
public void GetObjectData_IEqualityComparer () { EqualityComparer comparer = new EqualityComparer (); OrderedDictionary coll = new OrderedDictionary (comparer); coll.Add ("a", "1"); coll.Add ("b", "2"); coll = coll.AsReadOnly (); SerializationInfo si = new SerializationInfo (typeof (OrderedDictionary), new FormatterConverter ()); coll.GetObjectData (si, new StreamingContext ()); foreach (SerializationEntry se in si) { switch (se.Name) { case "KeyComparer": Assert.AreSame (comparer, se.Value, se.Name); break; case "ReadOnly": Assert.IsTrue ((bool) se.Value, se.Name); break; case "InitialCapacity": Assert.AreEqual (0, se.Value, se.Name); break; case "ArrayList": Assert.AreEqual (2, ((object[]) se.Value).Length, se.Name); break; default: string msg = String.Format ("Unexpected {0} information of type {1} with value '{2}'.", se.Name, se.ObjectType, se.Value); Assert.Fail (msg); break; } } }