void ReadData() { StreamingContext context = new StreamingContext(StreamingContextStates.Other); SurrogateSelector sel = new SurrogateSelector(); sel.AddSurrogate(typeof(Point), context, new PointSurrogate()); sel.AddSurrogate(typeof(FalseISerializable), context, new FalseISerializableSurrogate()); BinaryFormatter f = new BinaryFormatter(sel, context); object list = f.Deserialize(ms); object[][] originalMsgData = null; IMessage[] calls = null; IMessage[] resps = null; originalMsgData = ProcessMessages(null, null); calls = new IMessage[originalMsgData.Length]; resps = new IMessage[originalMsgData.Length]; for (int n = 0; n < originalMsgData.Length; n++) { calls[n] = (IMessage)f.Deserialize(ms); resps[n] = (IMessage)f.DeserializeMethodResponse(ms, null, (IMethodCallMessage)calls[n]); } f.Binder = new TestBinder(); object btbob = f.Deserialize(ms); ms.Close(); List expected = CreateTestData(); List actual = (List)list; expected.CheckEquals(actual, "List"); for (int i = 0; i < actual.children.Length - 1; ++i) { if (actual.children [i].next != actual.children [i + 1]) { Assert.Fail("Deserialization did not restore pointer graph"); } } BinderTester_A bta = CreateBinderTestData(); Assert.AreEqual(btbob.GetType(), typeof(BinderTester_B), "BinderTest.class"); BinderTester_B btb = btbob as BinderTester_B; if (btb != null) { Assert.AreEqual(btb.x, bta.x, "BinderTest.x"); Assert.AreEqual(btb.y, bta.y, "BinderTest.y"); } CheckMessages("MethodCall", originalMsgData, ProcessMessages(null, calls)); CheckMessages("MethodResponse", originalMsgData, ProcessMessages(null, resps)); }
BinderTester_A CreateBinderTestData() { BinderTester_A bta = new BinderTester_A(); bta.x = 11; bta.y = "binder tester"; return(bta); }
void WriteData() { StreamingContext context = new StreamingContext(StreamingContextStates.Other); SurrogateSelector sel = new SurrogateSelector(); sel.AddSurrogate(typeof(Point), context, new PointSurrogate()); sel.AddSurrogate(typeof(FalseISerializable), context, new FalseISerializableSurrogate()); List list = CreateTestData(); BinderTester_A bta = CreateBinderTestData(); ms = new MemoryStream(); BinaryFormatter f = new BinaryFormatter(sel, new StreamingContext(StreamingContextStates.Other)); f.Serialize(ms, list); ProcessMessages(ms, null); f.Serialize(ms, bta); ms.Flush(); ms.Position = 0; }
BinderTester_A CreateBinderTestData () { BinderTester_A bta = new BinderTester_A(); bta.x = 11; bta.y = "binder tester"; return bta; }