示例#1
0
        private static void Serialize(object source, SharpSerializer serializer, Func <byte[], byte[]> dataCallback)
        {
            byte[] data;

            // Serializing
            using (var stream = new MemoryStream())
            {
                // serialize
                serializer.Serialize(source, stream);

                data = stream.ToArray();
            }


            // Modifying data
            if (dataCallback != null)
            {
                data = dataCallback(data);
            }

            // Deserializing
            using (var stream = new MemoryStream(data))
            {
                // deserialize
                var unused = serializer.Deserialize(stream);

                // it comes never here
            }
        }
示例#2
0
        private static void Serialize(HelloWorldTestCase testCase, SharpSerializer serializer)
        {
            using (var stream = new MemoryStream())
            {
                // serialize
                serializer.Serialize(testCase.Source, stream);

                // reset stream
                stream.Position = 0;

                // deserialize
                var result = serializer.Deserialize(stream);

                // reset stream to test if it is not closed
                // the stream will be closed by the user
                stream.Position = 0;

                // Fix assertions
                Assert.AreEqual(testCase.Source.GetType(), result.GetType());

                // Custom assertions
                testCase.MakeAssertion(result);
            }
        }