//Arrange public void SearchCustomerReturnsCustomerName() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { using (var sw = new StringWriter()) { using (var sr = new StringReader("a")) { Customers custy = new Customers { FirstName = "al", LastName = "ali" }; context.Add(custy); context.SaveChanges(); //Act Console.SetOut(sw); Console.SetIn(sr); Customers customer = new Customers(); StoreMethods storeMethods = new StoreMethods(); storeMethods.SearchForUser(context); //Assert Assert.Contains("al\r\n", sw.ToString()); } } } }//Test 9
/// <summary> /// Edits item quantity /// </summary> /// <param name="cartItem"></param> /// <param name="newNum"></param> public IActionResult EditCartItem(EditCart editCart) { int newAmt = editCart.OrderNum; var itemQuantity = (from Inventory in _db.Inventory where Inventory.StoreInventory == editCart.storeId && Inventory.ItemInInventory == editCart.itemId select Inventory.ProductCurrentQuantity).FirstOrDefault(); if (newAmt > itemQuantity) { ModelState.AddModelError("newAmt", "Input is too large!"); return(View("_Checkcart")); } //TODO Add a check to make sure new quantity isnt more than whats available //TODO Finish the editting functionality var itemCart = _cache.Get("Cart"); List <OrderInformation> cart = new List <OrderInformation>(); cart = (List <OrderInformation>)itemCart; //Select the item from our cart that needs to be edited and edit OrderInformation edit = new OrderInformation(); edit = StoreMethods.ManipulateCartItem(editCart.itemId, cart); //Update the items ordered amount and total unit price edit.OrderedProductAmount = newAmt; edit.UnitPrice = edit.OrderedProductAmount * (edit.UnitPrice * (1 - edit.ProductDiscount)); _cache.Set("Cart", cart); return(RedirectToAction("_CheckCart")); }
public void LogoutEmptiesCacheRegion() { var services = new ServiceCollection(); services.AddMemoryCache(); var serviceProvider = services.BuildServiceProvider(); var _cache = serviceProvider.GetService <IMemoryCache>(); int isEmpty; Customers test = new Customers(); Customers empty = new Customers(); _cache.Set("loggedInCustomer", test); StoreMethods.LogoutCache(_cache); if (!_cache.TryGetValue("loggedInCustomer", out empty)) { isEmpty = 1; } else { isEmpty = 2; } //Check that the loggedInCustomer is empty Assert.Equal(1, isEmpty); }//5
//Arrange public void LoginProperlyReturnsACustomerType() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { using (var sw = new StringWriter()) { using (var sr = new StringReader("abe\nyup")) { context.Add(new Customers { UserName = "******", Pword = "yup" }); context.SaveChanges(); //Act Console.SetOut(sw); Console.SetIn(sr); Customers customer = new Customers(); StoreMethods storeMethods = new StoreMethods(); customer = storeMethods.Login(context); //Assert Assert.IsType <Customers>(customer); } } } }//End Test 1
public IActionResult Login(string UserName, string Pword) { int passFound = 0; int userFound = 0; var custLoginInfo = StoreMethods.GetCustomers(_db); foreach (var customer in custLoginInfo) //Check to make sure valid login info { if (UserName == customer.UserName) //entered user name corresponds to existing username for logged in user { userFound++; if (Pword == customer.Pword) //entered password corresponds to existing pass for logged in user { passFound++; _logger.LogInformation("User logged in"); _cache.Set("loggedInCustomer", customer); //Set the logged in customer to be the customer who just passed the login check return(View("_StoreMenu")); } } } if (userFound == 0) //Print out error messages according to what was entered incorrectly { _logger.LogInformation("Incorrect username"); ModelState.AddModelError("Username", "Incorrect username"); return(View("_Login")); } if (passFound == 0) { _logger.LogInformation("Correct user, incorrect pass"); ModelState.AddModelError("Pword", "Incorrect password"); return(View("_Login")); } return(View("_Login")); }
//Arrange public void GetOrderTotalReturnsCorrectOutput() { //Act StoreMethods newMethod = new StoreMethods(); double dub = 25.75111; var result = newMethod.GetOrderTotal(dub); //Assert Assert.Equal(25.75, result); }//test 5
//Arrange public void GetOrderTotalReturnsDecimal() { //Act StoreMethods newMethod = new StoreMethods(); double dub = 25.75576; var result = newMethod.GetOrderTotal(dub); //Assert Assert.IsType <double>(result); }//test 6
/// <summary> /// Prints out all the stores and lets the user choose which inventory they want to view /// </summary> /// <returns>List of stores</returns> public IActionResult _GetStoreInventory() { if (!_cache.TryGetValue("loggedInCustomer", out loggedInCustomer)) { //If the user isn't logged in, return to login screen return(View("_Login")); } var storeList = StoreMethods.SelectListOfStores(_db); return(View(storeList)); }
public void SelectAllProductsReturnsListOfProducts() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var list = StoreMethods.GetAllProducts(context); Assert.IsType <List <Products> >(list); } }//19
public void GetCustomerIDReturnsCustomerID() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var result = StoreMethods.GetCustomerIDs(context); Assert.IsType <List <int> >(result); } }//6
public void SearchCustomerReturnsListOfCustomers() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var result = StoreMethods.GetSearchResults("a", context); Assert.IsType <List <Customers> >(result); } }//4
public void SelectListOfStoreCreatesListOfStores() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var list = StoreMethods.SelectListOfStores(context); Assert.IsType <List <Stores> >(list); } }//11
public void SearchCustomerReturnsEmptyListOfCustomers() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { List <Customers> result = StoreMethods.GetSearchResults("", context); int isEmpty = result.Count; Assert.True(isEmpty == 0); } }//2
public void GetHighestOrderIDReturnsInt() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var orderId = StoreMethods.GetAllOrderIds(context); var result = StoreMethods.GetNewOrderId(orderId); Assert.IsType <int>(result); } }//16
/// <summary> /// Deletes item from cart /// </summary> /// <param name="cartItem"></param> public IActionResult DeleteCartItem(OrderInformation cartItem) { var itemCart = _cache.Get("Cart"); List <OrderInformation> cart = new List <OrderInformation>(); cart = (List <OrderInformation>)itemCart; //Select item to be deleted var delete = StoreMethods.ManipulateCartItem(cartItem.OrderedProduct, cart); cart.Remove(delete); _cache.Set("Cart", cart); return(RedirectToAction("GetCustomerStoreInventory")); }
public void SecondMenuChoiceReturnsAValidInteger() { using (var sr = new StringReader("4\n")) { Console.SetIn(sr); //Act StoreMethods storeMethod = new StoreMethods(); //Assert int menuChoice = storeMethod.SecondMenu(); Assert.InRange(menuChoice, 1, 6); } }//Test 4
public void FirstMenuChoiceReturnsAValidInteger() { using (var sr = new StringReader("2\n")) { Console.SetIn(sr); //Act StoreMethods storeMethod = new StoreMethods(); //Assert int menuChoice = storeMethod.UserMenuChoice(); Assert.InRange(menuChoice, 1, 3); } }//Test 3
public void GetHighestOrderIDSetsTo1IfListEmpty() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { List <int> empty = new List <int>(); int result = StoreMethods.GetNewOrderId(empty); Assert.True(result == 1); } }//18
//Arrange public void StartMenuHasCorrectOutput() { using (var sw = new StringWriter()) { Console.SetOut(sw); // Act statement ... StoreMethods storeMethod = new StoreMethods(); storeMethod.StartMenu(); // Assert statement ... Assert.Equal("\t\t\tWelcome to Slaughtoria Games!\n\t\t\tOnly true 5head gamers shop here!\r\n", sw.ToString()); sw.Close(); } }//Test 2
public void SelectDefaultStoreReturnsEmptyOnInvalidEntry() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Customers loggedIn = new Customers { FirstName = "kk", LastName = "kk", CustomerId = -1, DefaultStore = 5 }; Customers result = StoreMethods.SetDefaultStore(context, loggedIn); Assert.Null(result); } }//15
public void GetHighestOrderIdIncrements() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var orderId = StoreMethods.GetAllOrderIds(context); var result = StoreMethods.GetNewOrderId(orderId); orderId.Add(result); var result1 = StoreMethods.GetNewOrderId(orderId); Assert.True(result1 != result); } }//17
public void GetHighestIDIncrements() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var custID = StoreMethods.GetCustomerIDs(context); var result = StoreMethods.GetNewCustID(custID); custID.Add(result); var result1 = StoreMethods.GetNewCustID(custID); Assert.True(result1 != result); } }//9
public void SelectListOfStoreCreatesPopulatedList() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Stores store = new Stores(); context.Stores.Add(store); context.SaveChanges(); var list = StoreMethods.SelectListOfStores(context); int isEmpty = list.Count; Assert.True(isEmpty > 0); } }//12
public void SelectDefaultStoreReturnsASingleCustomer() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Customers loggedIn = new Customers { FirstName = "kk", LastName = "kk", CustomerId = 1, DefaultStore = 5 }; var result = StoreMethods.SetDefaultStore(context, loggedIn); Assert.IsNotType <List <Customers> >(result); } }//14
public void SelectAllProductsReturnsPopulatedList() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Products item1 = new Products { }; context.Products.Add(item1); context.SaveChanges(); var list = StoreMethods.GetAllProducts(context); int isEmpty = list.Count; Assert.True(isEmpty > 0); } }//20
/// <summary> /// Returns the results of the user search /// </summary> /// <returns>List of search results ordered by last name</returns> public IActionResult _ListSearchResults(string name) { //TODO Add an alert if the search results are EMPTY (no matches) //Find all the matches, order by last name var result = StoreMethods.GetSearchResults(name, _db); if (result.Count == 0) { _logger.LogInformation("No results were found"); return(View(result)); } else { _logger.LogInformation("Results were found"); return(View(result)); } }
public void GetCustomerIDReturnsPopulatedList() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Customers customer = new Customers { CustomerId = 200 }; context.Customers.Add(customer); context.SaveChanges(); List <int> result = StoreMethods.GetCustomerIDs(context); int isEmpty = result.Count; Assert.True(result.Count > 0); } }//7
public void SelectDefaultStoreReturnsACustomerType() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Customers loggedIn = new Customers { FirstName = "kk", LastName = "kk", CustomerId = 1, DefaultStore = 5 }; context.Customers.Add(loggedIn); context.SaveChanges(); var result = StoreMethods.SetDefaultStore(context, loggedIn); Assert.IsType <Customers>(result); } }//13
//Arrange public void GetItemTotalReturnsCorrectResult() { //Act var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Products thing = new Products(50.50m, .50m); context.Add(thing); StoreMethods storeMethod = new StoreMethods(); var result = storeMethod.GetItemTotal(4, thing, context); //Assert Assert.Equal(101.00m, result); } }//Test 8
public void SearchCustomerReturnsPopulatedListOfCustomers() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { Customers customer = new Customers { FirstName = "aaron", LastName = "aaronson" }; context.Customers.Add(customer); context.SaveChanges(); List <Customers> result = StoreMethods.GetSearchResults("a", context); int isEmpty = result.Count; Assert.False(isEmpty == 0); } }//3