Example #1
0
        public void ProductCollection_AddProductsPPAPTest()
        {
            ProductCollection products = new ProductCollection();

            products.AddNew("Pen");
            products.AddNew("Pineapple");
            products.AddNew("Apple");
            products.AddNew("Pen");

            Assert.IsTrue(products.Count == 4);

            System.Collections.Generic.List <Product> prods = new System.Collections.Generic.List <Product>();
            prods.GroupBy(x => x.Name);

            var results = products.GroupBy(x => x.Name)
                          .Select(x => new { Name = x.Key, Count = x.Count() });

            XmlSource.Save(products, "OrderPPAP.xml");

            /* Debugger results:
             * Apple: 3
             * Banana: 1
             */

            //TODO: figure out the syntax to access the count groupings.
            // debugger shows it properly but adding to the watch window results in an error.
        }
        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);
        }