Exemplo n.º 1
0
        public void WhenConvertingAsposeCarsXmlFileToBinary_ThenValidDataStored()
        {
            var tempFilePath = Path.GetTempFileName();

            try
            {
                _supporter.Convert(BaseFilePath + XmlExt, tempFilePath, CarFileFormat.Binary, true);

                var expectedHash = CarTestHelper.ComputeHashString(tempFilePath);
                Assert.AreEqual(expectedHash, "1d56edb154f10056969880c90c07c493");
            }
            finally
            {
                File.Delete(tempFilePath);
            }
        }
Exemplo n.º 2
0
        public void WhenConvertingAsposeCarsBinaryFileToJson_ThenValidDataStored()
        {
            var tempFilePath = Path.GetTempFileName();

            try
            {
                _supporter.Convert(BaseFilePath + BinaryExt, tempFilePath, _jsonFileFormat, true);

                var expectedHash = CarTestHelper.ComputeHashString(tempFilePath);
                Assert.AreEqual(expectedHash, "f851e486c27e363c129009705d29bb96");
            }
            finally
            {
                File.Delete(tempFilePath);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                var demoCars = CreateDefaultCarCollection();
                Console.WriteLine("Creating default Car Collection binary file " + BinaryDemoFileName);
                _carSupporter.Save(BinaryDemoFileName, CarFileFormat.Binary, true, demoCars);

                Console.WriteLine("Creating default Car Collection XML file " + XmlDemoFileName);
                _carSupporter.Save(XmlDemoFileName, CarFileFormat.Xml, true, demoCars);

                Console.WriteLine("Converting XML Car Collection file to a binary file " + BinaryFileName);
                _carSupporter.Convert(XMLFileName, BinaryFileName, CarFileFormat.Binary, true);

                Console.WriteLine("Reading Car Collection file " + XMLFileName);
                var cars = _carSupporter.Load(XMLFileName);

                Console.WriteLine("Adding a new record to the default Car Collection file");
                demoCars.CarRecords.Add(cars.CarRecords[0]);

                Console.WriteLine("Creating modified Car Collection binary file " + ModifiedBinaryFileName);
                _carSupporter.Save(ModifiedBinaryFileName, CarFileFormat.Binary, true, demoCars);

                Console.WriteLine("Updating the first record in the default Car Collection file (price = 99999)");
                demoCars.CarRecords[0].Price = 99999;

                Console.WriteLine("Creating modified Car Collection XML file " + ModifiedXMLFileName);
                _carSupporter.Save(ModifiedXMLFileName, CarFileFormat.Xml, true, demoCars);

                Console.WriteLine("Deleting the second record in the default Car Collection file");
                demoCars.CarRecords.RemoveAt(1);

                var jsonFormat = CarCollectionSupporter.AddFileFormat <CarCollectionJsonSerializer>();

                Console.WriteLine("Creating modified Car Collection JSON file " + ModifiedJsonFileName);
                _carSupporter.Save(ModifiedJsonFileName, jsonFormat, true, demoCars);
            }
            catch (IOException e)
            {
                Console.WriteLine("Cannot perform operation because of this error: " + e.Message);
            }

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }