コード例 #1
0
        public void Catalog_InitializeTest()
        {
            Catalog c          = new Catalog();
            string  outputFile = "catalog.xml";

            c.AddNew("Apple", 0.75M, DateTime.MinValue, new DateTime(2001, 12, 31, 23, 59, 59));
            c.AddNew("Apple", 0.75M, new DateTime(2002, 01, 01), null);
            c.AddNew("Banana", 1.0M, DateTime.MinValue, null);
            c.AddNew("Orange Juice", 1.1M, DateTime.MinValue, new DateTime(1983, 06, 09, 23, 59, 59));
            c.AddNew("Orange Juice", 2.0M, new DateTime(1983, 06, 10), null);
            c.AddNew("Pineapple", 5.0M, DateTime.MinValue, null);
            c.AddNew("Pen", 0.99M, DateTime.MinValue, null);

            XmlSource.Save(c, outputFile);

            Catalog c2 = XmlSource.Load(typeof(Catalog), outputFile) as Catalog;

            Assert.IsTrue(c2 != null, "Catalog was not rehydrated successfully");

            Assert.IsTrue(c2.Count == c.Count, "Catalog items serialized and rehydrated are not the same count");

            Assert.IsTrue(c2.Count > 0, "No objects were rehydrated");

//            if (System.IO.File.Exists(outputFile))
//                System.IO.File.Delete(outputFile);
        }
コード例 #2
0
        public void XmlDataSource_SerializeCollectionCompareTest()
        {
            string outputFile = @".\products.xml";

            IProductCollection products = new ProductCollection();

            products.AddNew("Apple");
            products.AddNew("Banana");
            products.AddNew("Apple");
            products.AddNew("Apple");

            XmlSource.Save(products, outputFile);


            IProductCollection products2 = XmlSource.Load(typeof(ProductCollection), outputFile) as IProductCollection;

            Assert.IsNotNull(products2, "ProductCollection could not be rehydrated");
            Assert.AreEqual(products.Count, products2.Count, "ProductCollection was not rehydrated with an incorrect count");

            //Cleanup
            System.IO.File.Delete(outputFile);
        }