[Test] public void BlendInOtherData() { Random rnd = new Random(); string rawDataA = "Hello World"; long rawDataB = 17; TestObject data = new TestObject(rnd); string rawDataResultA; long rawDataResultB; TestObject dataResult; using (MemoryStream stream = new MemoryStream()) using (Serializer formatter = Serializer.Create(stream, this.PrimaryFormat)) { using (BinaryWriter binWriter = new BinaryWriter(stream.NonClosing())) { binWriter.Write(rawDataA); formatter.WriteObject(data); binWriter.Write(rawDataB); } stream.Position = 0; using (BinaryReader binReader = new BinaryReader(stream.NonClosing())) { rawDataResultA = binReader.ReadString(); formatter.ReadObject(out dataResult); rawDataResultB = binReader.ReadInt64(); } } Assert.IsTrue(rawDataA.Equals(rawDataResultA)); Assert.IsTrue(rawDataB.Equals(rawDataResultB)); Assert.IsTrue(data.Equals(dataResult)); }
[Test] public void SerializeMetaComplexObject() { Random rnd = new Random(); TestObject data = new TestObject(rnd); TestObject dataResult; this.TestWriteRead(data, out dataResult, true); Assert.IsTrue(data.Equals(dataResult)); }
[Test] public void SerializeMetaRandomAccess() { Random rnd = new Random(); TestObject dataA = new TestObject(rnd); TestObject dataB = new TestObject(rnd); TestObject dataResultA; TestObject dataResultB; this.TestRandomAccess(dataA, dataB, out dataResultA, out dataResultB, true); Assert.IsTrue(dataA.Equals(dataResultA)); Assert.IsTrue(dataB.Equals(dataResultB)); }
[Test] public void ConvertFormat([ValueSource("OtherFormats")] Type to) { Random rnd = new Random(); TestObject data = new TestObject(rnd); TestObject dataResult; using (MemoryStream stream = new MemoryStream()) { // Write old format using (Serializer formatterWrite = Serializer.Create(stream, this.PrimaryFormat)) { formatterWrite.WriteObject(data); } // Read stream.Position = 0; using (Serializer formatterRead = Serializer.Create(stream)) { formatterRead.ReadObject(out dataResult); } // Write new format using (Serializer formatterWrite = Serializer.Create(stream, to)) { formatterWrite.WriteObject(data); } // Read stream.Position = 0; using (Serializer formatterRead = Serializer.Create(stream)) { formatterRead.ReadObject(out dataResult); } } Assert.IsTrue(data.Equals(dataResult)); }