public void Should_Generate_Name() { var possibleValues = Resources.Beer.Name.Split(';'); var actualValue = new[] { Beer.Name() }; Assert.That(actualValue, Is.SubsetOf(possibleValues)); }
public ActionResult AddToCart(int qty, int beerID) { //shell for local shopping cart Dictionary <int, ShoppingCartViewModel> shoppingCart = null; //Check the global shopping cart if (Session["cart"] != null) { //if items in global cart, reassign to local cart shoppingCart = (Dictionary <int, ShoppingCartViewModel>)Session["cart"]; } //if Session cart empty else { //create a local version shoppingCart = new Dictionary <int, ShoppingCartViewModel>(); } //get the product from the view Beer product = db.Beers.Where(x => x.BeerID == beerID).FirstOrDefault(); if (product == null) { return(RedirectToAction("Index")); } else { //beer is valid ShoppingCartViewModel item = new ShoppingCartViewModel(qty, product); //if the item is alread in the cart, just increase the qty if (shoppingCart.ContainsKey(product.BeerID)) { shoppingCart[product.BeerID].Qty += qty; } else//add item to the cart { shoppingCart.Add(product.BeerID, item); } //update global cart from the local cart Session["cart"] = shoppingCart; Session["confirm"] = string.Format($"{qty} {product.Name}{(qty == 1 ? "" : "s")} " + $"{(qty == 1 ? "was" : "were")} added to your cart"); } return(RedirectToAction("Index", "ShoppingCart")); }