Beispiel #1
0
        public void FromPath()
        {
            // Prerequisites
            const string path = "test-result.xml";

            var serializer = new SerializerXml<Passenger>();
            var passengerA = new Passenger
            {
                Name = "John",
                Age = 20
            };

            // Process
            serializer.Save(passengerA, path);
            Passenger passengerB = serializer.Instantiate(path);

            // Test
            Assert.IsTrue(passengerB.Name == passengerA.Name);
            Assert.IsTrue(passengerB.Age == passengerA.Age);
        }
Beispiel #2
0
        public void FromStream()
        {
            // Prerequisites
            var serializer = new SerializerXml<Passenger>();
            var vehicleA = new Passenger
            {
                Name = "John",
                Age = 20
            };

            // Process
            var stringWriter = new StringWriter();
            serializer.Save(vehicleA, stringWriter);

            var stringReader = new StringReader(stringWriter.ToString());
            Passenger vehicleB = serializer.Instantiate(stringReader);

            // Test
            Assert.IsTrue(vehicleB.Name == vehicleA.Name);
            Assert.IsTrue(vehicleB.Age == vehicleA.Age);
        }
        public void FromStream()
        {
            // Prerequisites
            var serializer = new XmlSerializer(typeof(Passenger));
            var passengerA = new Passenger
            {
                Name = "John",
                Age = 20
            };

            // Process
            var stringWriter = new StringWriter();
            serializer.Save(passengerA, stringWriter);

            var stringReader = new StringReader(stringWriter.ToString());
            var passengerB = serializer.Instantiate<Passenger>(stringReader);

            // Test
            Assert.IsTrue(passengerB.Name == passengerA.Name);
            Assert.IsTrue(passengerB.Age == passengerA.Age);
        }