Example #1
0
        static void Main(string[] args)
        {
            var binPath = @"TestFiles\Cars.bin";
            var xmlPath = @"TestFiles\Cars.xml";

            var carCollection = new BinCarCollection(binPath);
            var firstCar      = new CarModel()
            {
                Date      = DateTime.Today,
                BrandName = "Alfa Romeo New",
                Price     = 11000
            };
            var secondCar = new CarModel()
            {
                Date      = DateTime.Today,
                BrandName = "Toyota Land Cruiser",
                Price     = 15000
            };

            //create a bin file
            carCollection.Create(new List <CarModel> {
                firstCar
            });

            //add a car to the bin file
            carCollection.AddItem(secondCar, 0);

            //delete second car from the bin file
            carCollection.DeleteItem(1);

            //convert the bin file to xml file
            CarCollectionConverter.Convert(binPath, xmlPath);
        }
Example #2
0
        public void Convert_BinToXml()
        {
            var binSource = @"TestFiles\cars_source.bin";
            var xmlTarget = @"TestFiles\cars_target.xml";

            var binCollection = new BinCarCollection(binSource);

            binCollection.Create(Constants.Cars);

            CarCollectionConverter.Convert(binSource, xmlTarget);

            var xmlCollection = new XmlCarCollection(xmlTarget);
            var cars          = xmlCollection.GetAllItems();

            Assert.AreEqual(3, cars.Count);

            Assert.AreEqual(Constants.Cars[0].Date, cars[0].Date);
            Assert.AreEqual(Constants.Cars[0].BrandName, cars[0].BrandName);
            Assert.AreEqual(Constants.Cars[0].Price, cars[0].Price);

            Assert.AreEqual(Constants.Cars[1].Date, cars[1].Date);
            Assert.AreEqual(Constants.Cars[1].BrandName, cars[1].BrandName);
            Assert.AreEqual(Constants.Cars[1].Price, cars[1].Price);

            Assert.AreEqual(Constants.Cars[2].Date, cars[2].Date);
            Assert.AreEqual(Constants.Cars[2].BrandName, cars[2].BrandName);
            Assert.AreEqual(Constants.Cars[2].Price, cars[2].Price);
        }