예제 #1
0
        public void FromStream()
        {
            // Prerequisites
            const string path = "test-result.proto";

            var serializer = new SerializerProtobuf<Vehicle>();
            var vehicleA = new Vehicle
            {
                SpeedMax = 50,
                CurrentSpeed = 20
            };

            // Process
            var streamWriter = new StreamWriter(path);
            serializer.Save(vehicleA, streamWriter.BaseStream);
            streamWriter.Close();

            var streamReader = new StreamReader(path);
            Vehicle vehicleB = serializer.Instantiate(streamReader.BaseStream);
            streamReader.Close();

            // Test
            Assert.IsTrue(vehicleB.SpeedMax == vehicleA.SpeedMax);
            Assert.IsTrue(vehicleB.CurrentSpeed != vehicleA.CurrentSpeed);
        }
예제 #2
0
        public void FromPathByModel()
        {
            // Prerequisites
            const string path = "test-result.proto";

            var serializer = new SerializerProtobuf<Vehicle, VehicleData>();
            var vehicleA = new Vehicle
            {
                SpeedMax = 50,
                CurrentSpeed = 20
            };

            // Process
            serializer.Save(vehicleA, path);

            Vehicle vehicleB = serializer.Instantiate(path);

            // Test
            Assert.IsTrue(vehicleB.SpeedMax == vehicleA.SpeedMax);
        }
예제 #3
0
        public void InitializationFromStream()
        {
            // Prerequisites
            const string path = "test-result.proto";

            var serializer = new SerializerProtobuf<Vehicle, VehicleData>();
            var vehicleA = new Vehicle
            {
                SpeedMax = 50,
                CurrentSpeed = 20
            };
            var vehicleB = new Vehicle
            {
                SpeedMax = 100,
                CurrentSpeed = 40
            };

            // Process
            var streamWriter = new StreamWriter(path);
            serializer.Save(vehicleA, streamWriter.BaseStream);
            streamWriter.Close();

            var streamReader = new StreamReader(path);
            serializer.Load(vehicleB, streamReader.BaseStream);
            streamReader.Close();

            // Test
            Assert.IsTrue(vehicleB.SpeedMax == vehicleA.SpeedMax);
        }