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 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 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
/// <summary> /// Takes the user input and updates the customers default store in db and cache /// </summary> /// <param name="storeSelection"></param> /// <returns>Updated customer object</returns> public IActionResult SelectDefaultStore(Stores store) { int storeSelection = store.StoreId; //Update the default store in the cache var loggedIn = _cache.Get("loggedInCustomer"); loggedInCustomer = (Customers)loggedIn; loggedInCustomer.DefaultStore = storeSelection; _cache.Set("loggedInCustomer", loggedInCustomer); _logger.LogInformation("Logged in customer updated on cache"); //Update the default store in the database var dbCust = StoreMethods.SetDefaultStore(_db, loggedInCustomer); dbCust.DefaultStore = storeSelection; _db.SaveChanges(); _logger.LogInformation("Logged in customer updated on database"); return(View("_StoreMenu")); }