public void TestValidChoiceGetRightCustomer() { var mockICustomer = new Mock <ICustomer>(); var mockIConsoleHelper = new Mock <IConsoleHelper>(); var selectCustomerController = new SelectCustomerController(mockICustomer.Object, mockIConsoleHelper.Object); var customer1 = new Customer() { CustomerId = 1, CustomerName = "aa ab", CustomerStreetAddress = "1232 fsdf 33" }; var customer2 = new Customer() { CustomerId = 2, CustomerName = "bb bc", CustomerStreetAddress = "1555 yyyf 33" }; var list = new List <Customer>(); list.Add(customer1); list.Add(customer2); mockICustomer.Setup(x => x.GetAllCustomers()).Returns(list); mockIConsoleHelper.Setup(x => x.WriteAndReadFromConsole("> ")).Returns("1"); var selectedCustomer = selectCustomerController.SelectActiveCustomer(); var expected = 1; var actual = selectedCustomer.CustomerId; Assert.AreEqual(expected, actual); }
static void Main(string[] args) { SplashScreen splash = new SplashScreen(); splash.GenerateSplashScreen(); Console.SetWindowSize(57, 35); Customer activeCustomer = null; ConsoleHelper consoleHelper = new ConsoleHelper(); SHOWMENU: { Console.Clear(); consoleHelper.WriteHeaderToConsole("Welcome to Bangazon!"); if (activeCustomer != null) { string custString = $"Logged In As: {activeCustomer.CustomerName}"; string cartString = ""; var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); if (activeCart == null) { cartRepo.AddCart(activeCustomer.CustomerId); activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); } else { var cartDetail = new CartDetailRepository(); cartString = $"Cart({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}"; } string space = new string(' ', (56 - cartString.Length - custString.Length)); if (cartString.Length < 1) { consoleHelper.WriteLine($"{custString}\n"); } else { consoleHelper.WriteLine($"{custString}{space}{cartString}\n"); } } consoleHelper.WriteLine( "1.Create a new customer account" + "\n" + "2.Choose an existing customer" + "\n" + "3.Create a new payment option" + "\n" + "4.Add product(s) to shopping cart" + "\n" + "5.View Items in Cart\n" + "6.Complete an order" + "\n" + "7.View product popularity" + "\n" + "8.Logout Current User" + "\n" + "9.Leave Bangazon!"); Console.ForegroundColor = ConsoleColor.White; var userInput = consoleHelper.WriteAndReadFromConsole("> "); switch (userInput) { case "1": Console.Clear(); var CustomerInfo = new CustomerController(); activeCustomer = CustomerInfo.CreateCustomer(); goto SHOWMENU; case "2": Console.Clear(); var selectCustomerCtrl = new SelectCustomerController(); activeCustomer = selectCustomerCtrl.SelectActiveCustomer(); break; case "3": if (activeCustomer == null) { Console.Clear(); selectCustomerCtrl = new SelectCustomerController(); activeCustomer = selectCustomerCtrl.SelectActiveCustomer(); if (activeCustomer == null) { break; } } Console.Clear(); var PaymentCtrl = new PaymentController(); PaymentCtrl.RequestPayment(activeCustomer); break; case "4": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new CartController()).addProduct(activeCustomer); break; case "5": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new ViewCartController()).getItemsInCart(activeCustomer); break; case "6": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new CartController()).checkout(activeCustomer); break; case "7": Console.Clear(); var productPopularityController = new ProductPopularityController(); productPopularityController.DisplayPopularProducts(); break; case "8": if (activeCustomer != null) { consoleHelper.WriteLine($"\nUser {activeCustomer.CustomerName} is being logged out!"); activeCustomer = null; Thread.Sleep(1500); } else { consoleHelper.WriteLine($"\nNo customer currently logged in!"); Thread.Sleep(1500); } break; case "9": Console.Clear(); consoleHelper.WriteHeaderToConsole("Logging out..."); Thread.Sleep(1500); Environment.Exit(0); break; default: consoleHelper.WriteLine("please select a valid menu item..."); Thread.Sleep(1000); break; } goto SHOWMENU; } }