Beispiel #1
0
        [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));
        }