static void TestWSCustomer() { WholesaleCustomer wC = new WholesaleCustomer("Mickey", "Mouse", "*****@*****.**", "Disney"); Console.WriteLine("Testing the overloaded constructor"); Console.WriteLine("Expecting Mickey with Disney as company " + wC); }
static void TestWholeSaleCustomer() { Console.WriteLine("Testing WholeSaleCustomer constructor."); WholesaleCustomer wholecus1 = new WholesaleCustomer("Bob", "Vance", "*****@*****.**", "Vance Refrigeration"); WholesaleCustomer wholecus2 = new WholesaleCustomer("Trevor", "Rogers", "*****@*****.**", "Freelance Programmer"); Console.WriteLine("Expecting Bob Vance, [email protected] (Vance Refrigeration).\n" + wholecus1.GetDisplayText()); Console.WriteLine("Expecting Trevor Rogers, [email protected] (Freelance Programmer).\n" + wholecus2.GetDisplayText()); }
// WholesaleCustomer Class Test static void TestWholesaleCustomer() { Console.WriteLine("Testing Wholesale Class"); WholesaleCustomer wholecust1 = new WholesaleCustomer("Brandon", "Bobs", "*****@*****.**", "Bobs Motors"); WholesaleCustomer wholecust2 = new WholesaleCustomer("Mary", "Scampi", "*****@*****.**", "Scampi Shrimp"); Console.WriteLine("Expecting Brandon Bobs, bbobs@bobsmotors (Bobs Motors) \n" + wholecust1.GetDisplayText()); Console.WriteLine("Expecting Mary Scampi, [email protected] (Scampi Shrimp) \n" + wholecust2.GetDisplayText()); Console.WriteLine(); }
static void TestCustomerGetters() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Console.WriteLine("Testing getters"); Console.WriteLine("First name. Expecting Nohm. " + c1.FirstName); Console.WriteLine("Last name. Expecting Chomskey. " + c1.LastName); Console.WriteLine("Email. Expecting [email protected]. " + c1.Email); Console.WriteLine("Company name. Expecting Frank's Haircutting. " + ws.Company); Console.WriteLine("Home phone number. Expecting 5416669876. " + rs.HomePhone); Console.WriteLine(); }
static void TestWSCustomer() { WholesaleCustomer wC = new WholesaleCustomer("Mickey", "Mouse", "*****@*****.**", "Disney"); // Creates new wholesale customer Console.WriteLine("Testing the overloaded constructor"); Console.WriteLine("Expecting Mickey with Disney as company " + wC); // WC works because we overrode ToString Console.WriteLine("Testing setters"); wC.Company = "Disney"; Console.WriteLine("Expecting Disney " + wC.Company); Console.WriteLine("Testing getters"); Console.WriteLine("Expecting Disney" + " " + wC.Company); }
static void TestCustomerToString() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Console.WriteLine("Testing ToString"); Console.WriteLine("Expecting Nohm, Chomskey, [email protected]. " + c1.GetDisplayText()); Console.WriteLine("Getting Nohm, Chomskey, [email protected]. " + c1.ToString()); Console.WriteLine("Testing WholesaleCustomer ToString and RetailCustomer ToString."); Console.WriteLine("Expecting default values."); Console.WriteLine(ws.ToString()); Console.WriteLine(rs.ToString()); Console.WriteLine(); }
static void TestCustomerPolymorphism() { Console.WriteLine("Polymorphism tested with GetDisplayText"); Customer cust1 = new Customer("Jake", "Last", "*****@*****.**"); WholesaleCustomer wholecust1 = new WholesaleCustomer("Brandon", "Bobs", "*****@*****.**", "Bobs Motors"); RetailCustomer retailcust1 = new RetailCustomer("Aaron", "Baker", "*****@*****.**", "(555) 555-5555"); Console.WriteLine("GetDisplay Text from Customer Class"); Console.WriteLine("Expecting Jake Last, [email protected] \n" + cust1.GetDisplayText()); Console.WriteLine("GetDisplayText from WholesaleCustomer Class"); Console.WriteLine("Expecting Expecting Brandon Bobs, bbobs@bobsmotors (Bobs Motors) \n" + wholecust1.GetDisplayText()); Console.WriteLine("GetDisplayText from RetailCustomer Class"); Console.WriteLine("Expecting Aaron Baker, [email protected] ph: (555) 555-5555 \n" + retailcust1.GetDisplayText()); Console.WriteLine(); }
static void TestCustomerSetters() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Console.WriteLine("Testing setters"); c1.FirstName = "Kyle"; c1.LastName = "Normand"; c1.Email = "*****@*****.**"; ws.Company = "Noble Barns Emporium"; rs.HomePhone = "5419999999"; Console.WriteLine("Expecting Kyle, Normand, [email protected]."); Console.WriteLine("Getting " + c1.GetDisplayText()); Console.WriteLine("Expecting Noble Barns Emporium and 5419999999"); Console.WriteLine("Getting " + ws.Company + " and " + rs.HomePhone); Console.WriteLine(); }
static void TestCustomerList2() { Console.WriteLine("Testing retail and wholesale in same list."); CustomerList2 cList = new CustomerList2(); WholesaleCustomer wc1 = new WholesaleCustomer("Amy", "Johnson", "*****@*****.**", "LCC"); RetailCustomer rc1 = new RetailCustomer("Juan", "Lopez", "*****@*****.**", "(541)-123-4567"); cList.Add(wc1); cList += rc1; Console.WriteLine("Expecting list containing a wholesale customer, 'Amy Johnson', and a retail customer, 'Juan Lopez'\n" + cList); string allFirstNames = ""; foreach (Customer c in cList) { allFirstNames = allFirstNames + " " + c.FirstName; } Console.WriteLine(allFirstNames); }
static void TestCustomerConstructors() { Customer c1 = new Customer(); WholesaleCustomer ws = new WholesaleCustomer(); RetailCustomer rs = new RetailCustomer(); Customer c2 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer ws2 = new WholesaleCustomer("Nohm", "Chomskey", "*****@*****.**", "Ben's Boxing"); RetailCustomer rs2 = new RetailCustomer("Nohm", "Chomskey", "*****@*****.**", "5415555555"); Console.WriteLine("Testing both constructors"); Console.WriteLine("Default constructor. Expecting default values. " + c1.GetDisplayText()); Console.WriteLine("Overloaded constructor. Expecting Nohm Chomskey, nohmchomskey.com. "); Console.WriteLine("Getting " + c2.GetDisplayText()); Console.WriteLine("Testing WholesaleCustomer's constructors and RetailCustomer's constructors."); Console.WriteLine("Expecting default values."); Console.WriteLine("WholesaleCustomer: " + ws.GetDisplayText() + " RetailCustomer: " + rs.GetDisplayText()); Console.WriteLine("Expecting Nohm, Chomskey, [email protected], Ben's boxing and Nohm, Chomskey, [email protected], 5415555555"); Console.WriteLine("Overloaded WholesaleCustomer: " + ws2.GetDisplayText() + " Overloaded RetailCustomer: " + rs2.GetDisplayText()); Console.WriteLine(); }
// CustomerList2 Combo Tests static void TestCustomerList2Combo() { Console.WriteLine("Testing Wholesale and Retail in same list"); CustomerList2 cList2 = new CustomerList2(); // Add wholesale customers to the list WholesaleCustomer wholecust1 = new WholesaleCustomer("Brandon", "Bobs", "*****@*****.**", "Bobs Motors"); cList2.Add(wholecust1); WholesaleCustomer wholecust2 = new WholesaleCustomer("Mary", "Scampi", "*****@*****.**", "Scampi Shrimp"); cList2.Add(wholecust2); // Add retail customers to the list w/overloaded operators RetailCustomer retailcust1 = new RetailCustomer("Aaron", "Baker", "*****@*****.**", "(555) 555-5555"); cList2 += retailcust1; RetailCustomer retailcust2 = new RetailCustomer("Cathi", "Davis", "*****@*****.**", "(555) 777-7777"); cList2 += retailcust2; Console.WriteLine("Expecting list of 4 customers, 1st 2 wholesale, next 2 retail \n" + cList2); Console.WriteLine(); Console.WriteLine("Testing foreach"); Console.WriteLine("All first names. Expecting: Brandon Mary Aaron Cathi"); string allFirstNames = ""; //foreach loop to get all first names in both lists, then combine foreach (Customer cust in cList2) { allFirstNames = allFirstNames + cust.FirstName + " "; } Console.WriteLine(allFirstNames); Console.WriteLine(); Console.WriteLine("Testing Remove and - operator"); cList2.Remove(wholecust2); cList2 -= retailcust2; Console.WriteLine("Expecting 1 retail and 1 wholesale \n" + cList2); }
static void TestCustomerExceptions() { Customer c1 = new Customer("Nohm", "Chomskey", "*****@*****.**"); WholesaleCustomer c2 = new WholesaleCustomer(); RetailCustomer c3 = new RetailCustomer(); Console.WriteLine("Testing customer set exceptions"); Console.WriteLine("Attempting to set first name, last name, and email to more than 30 characters, expecting an exception from each."); try { c1.FirstName = "11111111111111111111111111111111111111111111111111111111111111111111"; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine(); try { c1.LastName = "11111111111111111111111111111111111111111111111111111111111111111111"; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine(); try { c1.Email = "11111111111111111111111111111111111111111111111111111111111111111111@."; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine("Attempting to set Company name to more than 30 characters, and an invalid phone number expecting an exception from each."); try { c2.Company = "11111111111111111111111111111111111111111111111111111111111111111111"; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } try { c3.HomePhone = "David66666666."; Console.WriteLine("Exception not caught."); } catch (Exception e) { Console.WriteLine("Exception caught with message " + e); } Console.WriteLine(); }