public void CustomerQueryExceptionTest() { // arrange var options = new DbContextOptionsBuilder <StoreApp_DbContext>() .UseInMemoryDatabase(databaseName: "CustomerQueryExceptionTest") .Options; CustomerQueries check = new CustomerQueries(); // assert check.CustomerSearch("yes", "no"); }
/// <summary> /// input/output for the process of looking up customers by name with all /// the validation taking place along the way and finally displaying /// the customers meeting the search parameters. /// </summary> public void CustomerSearch() { CustomerCreation validation = new CustomerCreation(); Console.WriteLine("Please enter a customer's partial or full first name."); string firstName = Console.ReadLine(); if (firstName == "cancel") { return; } // check if valid first name while (firstName != "" && !validation.IsValidName(firstName)) { Console.WriteLine("Invalid first name, please enter another or an empty string."); firstName = Console.ReadLine(); if (firstName == "cancel") { return; } } Console.WriteLine("Please enter a customer's partial or full last name."); string lastName = Console.ReadLine(); if (lastName == "cancel") { return; } // check if valid last name while (lastName != "" && !validation.IsValidName(lastName)) { Console.WriteLine("Invalid last name, please enter another or an empty string."); lastName = Console.ReadLine(); if (lastName == "cancel") { return; } } CustomerQueries search = new CustomerQueries(); var searchedCustomers = search.CustomerSearch(firstName, lastName); // check if any customers have this first/last name if (searchedCustomers.Count() == 0) { Console.WriteLine("There are no Customers matching the search parameters"); } else { // display list of customers fitting the first/last name Console.WriteLine($"ID\tFirst Name\tLast Name\tUsername"); foreach (var c in searchedCustomers) { Console.WriteLine($"{c.CustomerID}\t{c.FirstName}" + $"\t\t{c.LastName}\t\t{c.UserName}"); } Console.Write("Search Complete! "); } Console.WriteLine("Press enter to return to the menu"); Console.ReadLine(); }