public void ValidUserNameTest() { // arrange CustomerCreation validation = new CustomerCreation(); // act string usernameTest1 = "72838meah"; string usernameTest2 = "pie"; string usernameTest3 = "pie@2019withme"; // assert Assert.True(validation.IsValidUserName(usernameTest1)); Assert.True(validation.IsValidUserName(usernameTest2)); Assert.False(validation.IsValidUserName(usernameTest3)); }
/// <summary> /// input/output for the process of adding a new customer with all /// the validation taking place along the way and finally adding /// a new customer with the given information. /// </summary> public void AddNewCustomer() { // create new instance using (StoreApp_DbContext db = new StoreApp_DbContext()) { CustomerCreation createCustomer = new CustomerCreation(); Customer newCustomer = new Customer(); Console.WriteLine("What's the first name of the Customer?"); newCustomer.FirstName = Console.ReadLine(); if (newCustomer.FirstName == "cancel") { return; } while (!createCustomer.IsValidInputName(newCustomer.FirstName)) { Console.WriteLine("Invalid first name, please enter another ."); newCustomer.FirstName = Console.ReadLine(); if (newCustomer.FirstName == "cancel") { return; } } Console.WriteLine("What's the last name of the customer?"); newCustomer.LastName = Console.ReadLine(); if (newCustomer.LastName == "cancel") { return; } while (!createCustomer.IsValidInputName(newCustomer.LastName)) { Console.WriteLine("Invalid last name, please enter another"); newCustomer.LastName = Console.ReadLine(); if (newCustomer.LastName == "cancel") { return; } } Console.WriteLine("What would you like the username for the customer to be?"); newCustomer.UserName = Console.ReadLine(); if (newCustomer.UserName == "cancel") { return; } while (!createCustomer.IsValidUserName(newCustomer.UserName)) { Console.WriteLine("Invalid username, has to be 8 to 20 characters."); newCustomer.UserName = Console.ReadLine(); if (newCustomer.UserName == "cancel") { return; } } db.Add <Customer>(newCustomer); db.SaveChanges(); Console.WriteLine("Customer successfully added! Hit enter to go back to menu."); Console.ReadLine(); } }