Ejemplo n.º 1
0
        public void StreamRoundtripTest()
        {
            var formatter = new RawFormatter();

            using (var data = new MemoryStream(new byte[0]))
                using (var stream = new MemoryStream())
                {
                    formatter.Serialize(data, stream, typeof(Stream));
                    stream.Position = 0;
                    Assert.IsTrue(data.ToArray().SequenceEqual(((MemoryStream)formatter.Deserialize(stream, typeof(Stream))).ToArray()));
                }

            using (var data = new MemoryStream(new byte[] { 2, 0, 240, 3, 255 }))
                using (var stream = new MemoryStream())
                {
                    formatter.Serialize(data, stream, typeof(Stream));
                    stream.Position = 0;
                    Assert.IsTrue(data.ToArray().SequenceEqual(((MemoryStream)formatter.Deserialize(stream, typeof(Stream))).ToArray()));
                }
        }
Ejemplo n.º 2
0
        public void XElementRoundtripTest()
        {
            var formatter = new RawFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(new XElement("X"), stream, typeof(XElement));
                stream.Position = 0;
                Assert.IsTrue(XNode.DeepEquals(new XElement("X"), (XElement)formatter.Deserialize(stream, typeof(XElement))));
            }

            var xml = new XElement("Abc", new XElement("Def", new XAttribute("ghi", "jkl"), "mno"));

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(xml, stream, typeof(XElement));
                stream.Position = 0;
                Assert.IsTrue(XNode.DeepEquals(xml, (XElement)formatter.Deserialize(stream, typeof(XElement))));
            }
        }
Ejemplo n.º 3
0
        public void ByteRoundtripTest()
        {
            var formatter = new RawFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(new byte[0], stream, typeof(byte[]));
                stream.Position = 0;
                Assert.IsTrue(new byte[0].SequenceEqual((byte[])formatter.Deserialize(stream, typeof(byte[]))));
            }

            var bytes = new byte[] { 2, 0, 240, 3, 255 };

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(bytes, stream, typeof(byte[]));
                stream.Position = 0;
                Assert.IsTrue(bytes.SequenceEqual((byte[])formatter.Deserialize(stream, typeof(byte[]))));
            }
        }
Ejemplo n.º 4
0
        public void StringRoundtripTest()
        {
            var formatter = new RawFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(string.Empty, stream, typeof(string));
                stream.Position = 0;
                Assert.AreEqual(string.Empty, formatter.Deserialize(stream, typeof(string)));
            }

            const string text = "test";

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(text, stream, typeof(string));
                stream.Position = 0;
                Assert.AreEqual(text, formatter.Deserialize(stream, typeof(string)));
            }
        }