public void FlattenedSerializableHandles_RecursiveHandles()
        {
            FlattenedSerializableStub stub1 = new FlattenedSerializableStub("begone, foul fiend", 123);
            FlattenedSerializableStub stub2 = new FlattenedSerializableStub("befoul, gone fiend", 125);

            stub1.Data3 = stub2;
            stub2.Data3 = stub1;

            FlattenedSerializationInfo serializationInfo = new FlattenedSerializationInfo();

            serializationInfo.AddHandle(stub1);
            object[] data = serializationInfo.GetData();

            FlattenedDeserializationInfo deserializationInfo = new FlattenedDeserializationInfo(data);

            deserializationInfo.GetValueForHandle <FlattenedSerializableStub> ();
            // The following would be expected if this worked
            //FlattenedSerializableStub deserializedStub1 = deserializationInfo.GetValueForHandle<FlattenedSerializableStub> ();
            //FlattenedSerializableStub deserializedStub2 = deserializedStub1.Data3;

            //Assert.AreNotSame (deserializedStub1, deserializedStub2);
            //Assert.AreEqual ("begone, foul fiend", deserializedStub1.Data1);
            //Assert.AreEqual (123, deserializedStub1.Data2);
            //Assert.AreSame (deserializedStub2, deserializedStub1.Data3);

            //Assert.AreEqual ("befoul, gone fiend", deserializedStub2.Data1);
            //Assert.AreEqual (125, deserializedStub2.Data2);
            //Assert.AreSame (deserializedStub1, deserializedStub2.Data3);
        }
        public void FlattenedSerializableHandles_WithOtherHandles()
        {
            FlattenedSerializableStub stub1 = new FlattenedSerializableStub("begone, foul fiend", 123);
            FlattenedSerializableStub stub2 = new FlattenedSerializableStub("befoul, gone fiend", 125);

            stub1.Data3 = stub2;

            FlattenedSerializationInfo serializationInfo = new FlattenedSerializationInfo();

            serializationInfo.AddHandle(stub1);
            object[] data = serializationInfo.GetData();

            FlattenedDeserializationInfo deserializationInfo = new FlattenedDeserializationInfo(data);
            FlattenedSerializableStub    deserializedStub1   = deserializationInfo.GetValueForHandle <FlattenedSerializableStub> ();
            FlattenedSerializableStub    deserializedStub2   = deserializedStub1.Data3;

            Assert.That(deserializedStub2, Is.Not.SameAs(deserializedStub1));
            Assert.That(deserializedStub1.Data1, Is.EqualTo("begone, foul fiend"));
            Assert.That(deserializedStub1.Data2, Is.EqualTo(123));
            Assert.That(deserializedStub1.Data3, Is.SameAs(deserializedStub2));

            Assert.That(deserializedStub2.Data1, Is.EqualTo("befoul, gone fiend"));
            Assert.That(deserializedStub2.Data2, Is.EqualTo(125));
            Assert.That(deserializedStub2.Data3, Is.Null);
        }
        public void FlattenedSerializables_Null()
        {
            FlattenedSerializationInfo serializationInfo = new FlattenedSerializationInfo();

            serializationInfo.AddValue <FlattenedSerializableStub> (null);
            object[] data = serializationInfo.GetData();

            FlattenedDeserializationInfo deserializationInfo = new FlattenedDeserializationInfo(data);
            FlattenedSerializableStub    deserializedStub    = deserializationInfo.GetValue <FlattenedSerializableStub> ();

            Assert.That(deserializedStub, Is.Null);
        }
        public void FlattenedSerializables()
        {
            FlattenedSerializableStub  stub = new FlattenedSerializableStub("begone, foul fiend", 123);
            FlattenedSerializationInfo serializationInfo = new FlattenedSerializationInfo();

            serializationInfo.AddValue(stub);
            object[] data = serializationInfo.GetData();

            FlattenedDeserializationInfo deserializationInfo = new FlattenedDeserializationInfo(data);
            FlattenedSerializableStub    deserializedStub    = deserializationInfo.GetValue <FlattenedSerializableStub> ();

            Assert.That(deserializedStub.Data1, Is.EqualTo("begone, foul fiend"));
            Assert.That(deserializedStub.Data2, Is.EqualTo(123));
        }
        public void ArrayWithFlattenedSerializables()
        {
            FlattenedSerializableStub stub1 = new FlattenedSerializableStub("begone, foul fiend", 123);
            FlattenedSerializableStub stub2 = new FlattenedSerializableStub("'twas brillig, and the slithy toves", 124);

            object[] stubs = new object[] { stub1, stub2 };
            FlattenedSerializationInfo serializationInfo = new FlattenedSerializationInfo();

            serializationInfo.AddArray(stubs);
            object[] data = serializationInfo.GetData();

            FlattenedDeserializationInfo deserializationInfo = new FlattenedDeserializationInfo(data);

            object[] deserializedStubs = deserializationInfo.GetArray <object> ();

            Assert.That(deserializedStubs.Length, Is.EqualTo(2));
            Assert.That(((FlattenedSerializableStub)deserializedStubs[0]).Data1, Is.EqualTo("begone, foul fiend"));
            Assert.That(((FlattenedSerializableStub)deserializedStubs[0]).Data2, Is.EqualTo(123));
            Assert.That(((FlattenedSerializableStub)deserializedStubs[1]).Data1, Is.EqualTo("'twas brillig, and the slithy toves"));
            Assert.That(((FlattenedSerializableStub)deserializedStubs[1]).Data2, Is.EqualTo(124));
        }
Exemplo n.º 6
0
 protected FlattenedSerializableStub(FlattenedDeserializationInfo info)
 {
     Data1 = info.GetValue <string> ();
     Data2 = info.GetIntValue();
     Data3 = info.GetValueForHandle <FlattenedSerializableStub> ();
 }