static void TestCustomerList2Index() { CustomerList2 cl = new CustomerList2(); Customer c = new Customer(); Customer c2 = new Customer("Nohm", "Chomskey", "*****@*****.**"); for (int i = 0; i < 4; i++) { cl.Add(c); } cl.Add(c2); for (int i = 0; i < 10; i++) { cl.Add(c); } Console.WriteLine("Testing indexer getter for CustomerList2. Placing 15 items in the list."); Console.WriteLine("Expecting 15 customers to be in the list."); Console.WriteLine("Getting " + cl.Count + " customers"); Console.WriteLine("Testing indexer setter for CustomerList2."); cl[5] = c2; Console.WriteLine("Expecting the customer at index 4 to be Nohm Chomskey."); Console.WriteLine("The customer at index 4 is " + cl[5].FirstName + " " + cl[5].LastName); Console.WriteLine(); }
static void TestCustomerList2Constructor() { CustomerList2 cList = new CustomerList2(); Console.WriteLine("Testing constructor"); Console.WriteLine("Default constructor. Expecting count of 0 " + cList.Count); Console.WriteLine("Default constructor. Expecting empty string " + cList); Console.WriteLine(); }
static void TestCustomerList2Fill() { CustomerList2 cList2 = new CustomerList2(); cList2.Fill(); Console.WriteLine("Testing Fill"); Console.WriteLine("Expecting count of 5 " + cList2.Count); Console.WriteLine("Expecting list of 5 customers: \n" + cList2); Console.WriteLine(); }
static void TestCustomerList2Indexers() { CustomerList2 cList2 = new CustomerList2(); Customer c1 = new Customer("John", "Smith", "*****@*****.**"); Customer c3 = new Customer("Jake", "Andrews", "*****@*****.**"); cList2.Add(c1); cList2.Add("Elsa", "Jacobs", "*****@*****.**"); cList2 += c3; Console.WriteLine("Testing indexer"); Console.WriteLine("Get product with index 0"); Customer c4 = cList2[0]; Console.WriteLine("Expecting John. " + c4); Console.WriteLine("Should not change list. Expecting count of 3 " + cList2.Count); Console.WriteLine("Expecting list of 3 customers. John is the first element in list:\n" + cList2); }
static void TestCustomerList2ToString() { CustomerList2 cl = new CustomerList2(); List <Customer> customers; customers = CustomerDB.GetCustomers(); Console.WriteLine("Testing CustomerList2 ToString."); Console.Write("Expecting "); for (int i = 0; i < customers.Count; i++) { Console.WriteLine(customers[i]); } cl.Fill(); Console.Write("Getting "); Console.WriteLine(cl); }
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 TestCustomerList2Foreach() { CustomerList2 cl = new CustomerList2(); List <Customer> customers; customers = CustomerDB.GetCustomers(); Console.WriteLine("Testing CustomerList2."); Console.Write("Expecting "); cl.Fill(); Console.Write("Getting "); foreach (Customer c in cl) { Console.WriteLine(c); } Console.WriteLine(); }
/// <summary> /// CUSTOMER LIST 2 TESTING STARTS HERE /// </summary> static void TestCustomerList2AddRemove() { CustomerList2 cl = new CustomerList2(); Customer c = new Customer("Nohm", "Chomskey", "*****@*****.**"); cl.Add(c); Console.WriteLine("Testing add customer for CustomerList2."); Console.WriteLine("Expecting Nohm, Chomskey, [email protected], with one item in the list."); Console.WriteLine("Getting " + cl[0].GetDisplayText() + " with a total of " + cl.Count + " items."); Console.WriteLine(); cl.Remove(c); Console.WriteLine("Testing remove customer for CustomerList2."); Console.WriteLine("Removing Nohm Chomskey. Expecting empty list."); Console.WriteLine("Getting " + cl.Count + " customers."); Console.WriteLine(); }
static void TestCustomerList2OverrideAddRemove() { CustomerList2 cl = new CustomerList2(); Customer c = new Customer("Nohm", "Chomskey", "*****@*****.**"); cl += c; Console.WriteLine("Testing overloaded + operator for CustomerList2."); Console.WriteLine("Expecting Nohm, Chomskey, [email protected]. with one item in the list."); Console.WriteLine("Getting " + cl[0].GetDisplayText() + " with a total of " + cl.Count + " items."); Console.WriteLine(); cl -= c; Console.WriteLine("Testing overloaded - operator for CustomerList2."); Console.WriteLine("Removing Nohm Chomskey. Expecting empty list."); Console.WriteLine("Getting " + cl.Count + " customers."); 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 TestCustomerList2Fill() { CustomerList2 cl = new CustomerList2(); List <Customer> customers; customers = CustomerDB.GetCustomers(); Console.WriteLine("Testing CustomerList2 fill."); Console.Write("Expecting "); for (int i = 0; i < customers.Count; i++) { Console.WriteLine(customers[i]); } cl.Fill(); Console.Write("Getting "); for (int i = 0; i < cl.Count; i++) { Console.WriteLine(cl[i].GetDisplayText()); } Console.WriteLine(); }
static void TestCustomerList2Save() { CustomerList2 cl = new CustomerList2(); Customer c = new Customer("Henry", "Davenport", "*****@*****.**"); List <Customer> customers; Console.WriteLine("Testing CustomerList2 save."); Console.Write("Expecting "); customers = CustomerDB.GetCustomers(); customers.Add(c); for (int i = 0; i < customers.Count; i++) { Console.WriteLine(customers[i].GetDisplayText()); } for (int i = 0; i < customers.Count; i++) { cl.Add(customers[i]); } Console.Write("Getting "); cl.Save(); customers = CustomerDB.GetCustomers(); for (int i = 0; i < customers.Count; i++) { Console.WriteLine(customers[i].GetDisplayText()); } Console.WriteLine(); customers.RemoveAt(customers.IndexOf(c)); CustomerList2 cl2 = new CustomerList2(); for (int i = 0; i < customers.Count; i++) { cl2.Add(customers[i]); } cl2.Save(); }
static void TestCustomerList2Find() { CustomerList2 cl = new CustomerList2(); Customer c = new Customer(); Customer c2 = new Customer("Nohm", "Chomskey", "*****@*****.**"); Customer c3; for (int i = 0; i < 4; i++) { cl.Add(c); } cl.Add(c2); for (int i = 0; i < 10; i++) { cl.Add(c); } Console.WriteLine("Testing email indexer for CustomerList2."); Console.WriteLine("Expecting to find the customer with the email nohm@chomskey and not the email [email protected]."); if (cl["*****@*****.**"].Email == "*****@*****.**") { c3 = cl["*****@*****.**"]; Console.WriteLine("Found " + c3.FirstName + " " + c3.LastName + " with the email " + c3.Email); } else { Console.WriteLine("Customer with email [email protected] not found."); }; if (cl["*****@*****.**"].Email == "*****@*****.**") { c3 = cl["*****@*****.**"]; Console.WriteLine("Found " + c3.FirstName + " " + c3.LastName + " with the email " + c3.Email); } else { Console.WriteLine("Customer with email [email protected] not found."); } Console.WriteLine(); }
static void TestCustomerList2Remove() { CustomerList2 cList2 = new CustomerList2(); Customer c1 = new Customer("John", "Smith", "*****@*****.**"); Customer c3 = new Customer("Jake", "Andrews", "*****@*****.**"); cList2.Add(c1); cList2.Add("Elsa", "Jacobs", "*****@*****.**"); cList2 += c3; Console.WriteLine("Testing Remove"); Console.WriteLine("Remove"); cList2.Remove(c1); Console.WriteLine("Expecting count of 2 " + cList2.Count); Console.WriteLine("Expecting list of 2 customers: Removed John: \n" + cList2); cList2 -= c3; Console.WriteLine("- operator"); Console.WriteLine("Expecting count of 1 " + cList2.Count); Console.WriteLine("Expecting list of 1 customer. Removed Jake: \n" + cList2); Console.WriteLine(); }
static void TestCustomerList2Add() { CustomerList2 cList = new CustomerList2(); Customer c1 = new Customer( "Mickey", "Mouse", "*****@*****.**"); Customer c3 = new Customer( "Minnie", "Mouse", "*****@*****.**"); Console.WriteLine("Testing Add"); cList.Add(c1); Console.WriteLine("Add that takes a Customer parameter"); Console.WriteLine("Expecting count of 1 " + cList.Count); Console.WriteLine("Expecting list of 1 Customers:\n" + cList); cList.Add("Donald", "Duck", "*****@*****.**"); Console.WriteLine("Add that takes individual Customer attributes and constructs a Customer"); Console.WriteLine("Expecting count of 2 " + cList.Count); Console.WriteLine("Expecting list of 2 Customers:\n" + cList); cList += c3; Console.WriteLine("+ operator"); Console.WriteLine("Expecting count of 3 " + cList.Count); Console.WriteLine("Expecting list of 3 Customers:\n" + cList); Console.WriteLine(); }
static void TestCustomerList2Add() { CustomerList2 cList2 = new CustomerList2(); Customer c1 = new Customer("John", "Smith", "*****@*****.**"); Customer c3 = new Customer("Jake", "Andrews", "*****@*****.**"); Console.WriteLine("Testing Add"); cList2.Add(c1); Console.WriteLine("Add that takes a customer parameter"); Console.WriteLine("Expecting count of 1 " + cList2.Count); Console.WriteLine("Expecting list of 1 customer: \n" + cList2); cList2.Add("Elsa", "Jacobs", "*****@*****.**"); Console.WriteLine("Add that takes individual customer attributes and constructs customer"); Console.WriteLine("Expecting count of 2 " + cList2.Count); Console.WriteLine("Expecting list of 2 customers: \n" + cList2); cList2 += c3; Console.WriteLine("+ operator"); Console.WriteLine("Expecting count of 3 " + cList2.Count); Console.WriteLine("Expecting list of 3 customers:\n" + cList2); Console.WriteLine(); }
static void TestCustomerList2Count() { CustomerList2 cl = new CustomerList2(); Customer c = new Customer(); for (int i = 0; i < 15; i++) { cl += c; } Console.WriteLine("Testing counter variable for CustomerList2."); Console.WriteLine("Expecting 15 items in the list."); Console.WriteLine("Getting a total of " + cl.Count + " customers."); Console.WriteLine(); for (int i = 0; i < 7; i++) { cl -= c; } Console.WriteLine("Removing 7 items. Expecing 8 items to be left in the list."); Console.WriteLine("Getting " + cl.Count + " customers."); Console.WriteLine(); }