Пример #1
0
        static void TestSerialization()
        {
            string testName = "Serialization";
            Begin(testName);
            Suppliers sups = new Suppliers();
            sups.Add(Suppliers.CreateSupplier(21, "MyCompany", "Mark", "CEO", "1234 Here St. PO Box 123", "Dallas", "Texas", "12344", "USA", "555123123",
                    "1231231234", "www.MyCompany.com", SupplierTypes.Supply));
            sups.Add(Suppliers.CreateSupplier(22, "ThisCompany", "Bob", "Lackey", "1234 There", "Washington", "Maryland", "1234", "ASU", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Product));
            sups.Add(Suppliers.CreateSupplier(23, "phifzer", "Bob", "Lackey", "1234 There", "Here", "Markland", "1234", "BBB", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Service));
            sups.Add(Suppliers.CreateSupplier(24, "phisher", "Bob", "Lackey", "1234 There", "There", "Texas", "1234", "UAS", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Service));
            sups.Add(Suppliers.CreateSupplier(25, "phish", "Bob", "Lackey", "1234 There", "Anywhere", "Maryland", "1234", "ASU", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Product));
            sups.Add(Suppliers.CreateSupplier(26, "petunia", "Bob", "Lackey", "1234 There", "Anywher", "Maryland", "1234", "ASU", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Product));
            ShowCollection(sups.GetEnumerator());

            #region Serialize suppliers collection
            Test("Serialize suppliers collection");
            try
            {
                using (FileStream fs = new FileStream("SerializedSuppliers.xml", FileMode.Create,
                    FileAccess.Write, FileShare.None))
                {
                    SoapFormatter sf = new SoapFormatter();
                    sf.Serialize(fs, sups);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Serialization Complete");
            #endregion

            #region Restore the Suppliers
            Test("Restore the Suppliers");
            sups = null;
            try
            {
                using (FileStream fs = new FileStream("SerializedSuppliers.xml", FileMode.Open,
                    FileAccess.Read, FileShare.None))
                {
                    SoapFormatter sf = new SoapFormatter();
                    sups = (Suppliers)sf.Deserialize(fs);
                    //showCollection(sups.GetEnumerator());
                    //foreach (int i in sups)
                    //{
                    //    Console.WriteLine(i.ToString());
                    //}
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            ShowCollection(sups.GetEnumerator());
            #endregion


            End(testName);
            Wait();
        }
Пример #2
0
        static void TestSuppliers()
        {
            string testName = "Suppliers";
            Begin(testName);

            #region Add Method and IEnumerable
            Test("Add Method and IEnumerable");
            Suppliers sups = new Suppliers();
            sups.Add(Suppliers.CreateSupplier(21, "MyCompany", "Mark", "CEO", "1234 Here St. PO Box 123", "Dallas", "Texas", "12344", "USA", "555123123",
                    "1231231234", "www.MyCompany.com", SupplierTypes.Supply));
            sups.Add(Suppliers.CreateSupplier(22, "ThisCompany", "Bob", "Lackey", "1234 There", "Washington", "Maryland", "1234", "ASU", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Product));
            sups.Add(Suppliers.CreateSupplier(23, "phifzer", "Bob", "Lackey", "1234 There", "Here", "Markland", "1234", "BBB", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Service));
            sups.Add(Suppliers.CreateSupplier(24, "phisher", "Bob", "Lackey", "1234 There", "There", "Texas", "1234", "UAS", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Service));
            sups.Add(Suppliers.CreateSupplier(25, "phish", "Bob", "Lackey", "1234 There", "Anywhere", "Maryland", "1234", "ASU", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Product));
            sups.Add(Suppliers.CreateSupplier(26, "petunia", "Bob", "Lackey", "1234 There", "Anywher", "Maryland", "1234", "ASU", "1231231234",
                "1231231234", "www.thiscompany.com", SupplierTypes.Product));

            //OR Using the Static methods in teh DataAccess.Da class:
            //****if you use this the dupes test wont return and error since i have it looking for a specific object.****
            //sups.Add(new Supplier(DataAccess.DA.GetSupplier(21)));
            //sups.Add(new Supplier(DataAccess.DA.GetSupplier(22)));
            //sups.Add(new Supplier(DataAccess.DA.GetSupplier(23)));
            //sups.Add(new Supplier(DataAccess.DA.GetSupplier(24)));
            //sups.Add(new Supplier(DataAccess.DA.GetSupplier(25)));
            //sups.Add(new Supplier(DataAccess.DA.GetSupplier(26)));
            ShowCollection(sups.GetEnumerator());

            #endregion

            #region Count Method
            Test("Count Method");
            Console.WriteLine(sups.Count.ToString());
            #endregion

            #region Type Checking in Add Method
            Test("Type checking in Add method");
            try
            {
                sups.Add("String Instance");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion

            #region RemoveAt
            Test("RemoveAt");
            for (int i = 0; i < 3; i++) 
                sups.RemoveAt(0);
            ShowCollection(sups.GetEnumerator());
            #endregion

            #region Insert
            Test("Insert");
            sups.Insert(0, Suppliers.CreateSupplier(50001, "MyCompany", "Mark", "CEO", "1234 Here St. PO Box 123", "Dallas", "Texas", "12344", "USA", "555123123",
                    "1231231234", "www.MyCompany.com", SupplierTypes.Supply));
            ShowCollection(sups.GetEnumerator());
            #endregion

            #region Insert Detects Duplicates
            Test("Insert Detect Duplicates");
            try
            {
                sups.Insert(2, Suppliers.CreateSupplier(26, "petunia", "Bob", "Lackey", "1234 There", "Anywher", "Maryland", "1234", "ASU", "1231231234",
                    "1231231234", "www.thiscompany.com", SupplierTypes.Product));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion

            #region InvalidIndex
            Test("Invalid Index");
            try
            {
                Console.WriteLine(sups[10].ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion

            #region Type Checking in Indexer
            Test("Type Checking in Indexer");
            try
            {
                sups[1] = "String Instance";
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            #endregion

            #region Indexer Detects Duplicates
            Test("Indexer Detects Duplicates");
            try
            {
                sups[2] = Suppliers.CreateSupplier(26, "petunia", "Bob", "Lackey", "1234 There", "Anywher", "Maryland", "1234", "ASU", "1231231234",
                    "1231231234", "www.thiscompany.com", SupplierTypes.Product);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            #endregion

            #region CopyTo
            Test("CopyTo");
            int x = sups.Count;
            Supplier[] myArray = new Supplier[x];
            sups.CopyTo(myArray);
            ShowCollection(myArray.GetEnumerator());
            #endregion

            #region GetTypeEnumerator
            Test("GetTypeEnumerator");
            ShowCollection(sups.GetTypeEnumerator(SupplierTypes.Product));           
            #endregion

            #region GetReverseEnumerator
            Test("GetReverseEnumerator");
            ShowCollection(sups.GetReverseEnumerator());
            #endregion

            #region Sort on TypeCompanyName
            Test("Sort on TypeCompanyName");
            sups.Sort(Supplier.GetSortByTypeCompanyName());
            ShowCollection(sups.GetEnumerator());
            #endregion

            #region Sort on CountryRegionCity
            Test("Sort on CountryRegionCity");
            sups.Sort(Supplier.GetSortByCountryRegionCity());
            foreach (Supplier s in sups)
                Console.WriteLine("ID: {0,5}\tCountry: {1}\tRegion: {2,10}\tCity: {3}", s.ID.ToString(), s.Country, s.Region, s.City);
            #endregion

            #region IComparable
            Test("IComparable");
            sups.Sort();
            ShowCollection(sups.GetEnumerator());
            #endregion

            End(testName);
            Wait();
        }