//Gets all products for checkout (set new quantity) in Stores Controller public static List <Products> GetAllProducts(SGDB2Context _db) { var allItemsInventory = (from Products in _db.Products select Products).ToList(); //Gets all the existing products return(allItemsInventory); }
//Gets all orderIDs for checkout in Stores Controller public static List <int> GetAllOrderIds(SGDB2Context _db) { var orderList = (from Orders in _db.Orders select Orders.OrderId).ToList(); return(orderList); }
//Gets all customer IDs for the SignUp action in Customer Controller public static List <int> GetCustomerIDs(SGDB2Context _db) { var custId = (from Customers in _db.Customers select Customers.CustomerId).ToList(); return(custId); }
//Gets all customers for Login action in Customers Controller public static List <Customers> GetCustomers(SGDB2Context _db) { var custLoginInfo = (from Customers in _db.Customers select Customers).ToList(); return(custLoginInfo); }
//Gets list of store for _SelectDefaultStore in Stores Controller public static List <Stores> SelectListOfStores(SGDB2Context _db) { var storeList = (from Stores in _db.Stores select Stores).ToList(); return(storeList); }
//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
//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
//Retrieves the loggedInCustomer's information for SelectDefaultStore in Stores Controller public static Customers SetDefaultStore(SGDB2Context _db, Customers loggedInCustomer) { var dbCust = (from Customers in _db.Customers where loggedInCustomer.CustomerId == Customers.CustomerId select Customers).ToList().FirstOrDefault(); return(dbCust); }
public CustomersController(ILogger <CustomersController> logger, SGDB2Context db, IMemoryCache cache) { _logger = logger; _db = db; _cache = cache; //If the memory cache doesn't have a customers list, create one if (_db.Customers.ToList().Count == 0) { } }
public StoresController(ILogger <StoresController> logger, SGDB2Context db, IMemoryCache cache) { _logger = logger; _db = db; _cache = cache; if (!_cache.TryGetValue("Cart", out Cart)) { _cache.Set("Cart", new List <OrderInformation>()); } }
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 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 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 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
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 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
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 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 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 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
//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
//Gets search results for _ListSearchResults in Customer controller public static List <Customers> GetSearchResults(string name, SGDB2Context _db) { if (name == null || name.Length == 0) { name = "9"; } else { name = name.ToUpper(); } var result = (from Customers in _db.Customers where Customers.LastName.ToUpper() == name || Customers.LastName.ToUpper().Contains(name) orderby Customers.LastName ascending select Customers).ToList(); return(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
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
//Arrange public void StoreSelectionThrowsExceptionOnNull() { 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("0\n")) { Customers custy = new Customers { UserName = "******", Pword = "yup", DefaultStore = 1 }; context.Add(custy); context.SaveChanges(); //Act bool thrown = false; try { Console.SetOut(sw); Console.SetIn(sr); Customers customer = new Customers(); StoreMethods storeMethods = new StoreMethods(); storeMethods.SetSelectedStore(customer, context); } catch (NullReferenceException) { thrown = true; } //Assert Assert.True(thrown); sw.Close(); } } } }//Test 10
public HomeController(SGDB2Context db, IMemoryCache cache) { _db = db; _cache = cache; }