public HttpStatusCodeResult ChangeGameQuantity(ChangeGameQuantityViewModel model) { var basket = Session[Basket] as List <Purchase>; if (basket == null) { basket = new List <Purchase>(); GameDto game = _gameService.Get(model.Id); basket.Add(new Purchase(game.Id, game.LanguagesNames["ru"], game.Price, model.Quantity)); Session[Basket] = basket; } else { Purchase purchase = basket.Single(p => p.GameId == model.Id); if (model.Quantity == 0) { basket.Remove(purchase); } else { purchase.Quantity = model.Quantity; } } CreateOrUpdateCurrentOrder(basket); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public void ShouldChangeGameQuantityAtBasket() { var model = new ChangeGameQuantityViewModel { Id = 1, Quantity = 3 }; var sessionItems = new SessionStateItemCollection { [Basket] = new List <Purchase> { new Purchase(model.Id, It.IsAny <string>(), It.IsAny <decimal>(), quantity: 1) } }; _basketController.ControllerContext = new FakeControllerContext(_basketController, sessionItems); _orderService .Setup(m => m.GetCurrentOrderForCustomer(It.IsAny <string>())) .Returns(new OrderDto { Id = 1 }); _orderService .Setup(m => m.Update(It.IsAny <int>(), It.IsAny <Dictionary <int, short> >(), It.IsAny <string>())); _basketController.ChangeGameQuantity(model); var purchases = _basketController.Session[Basket] as List <Purchase>; Assert.IsNotNull(purchases); Assert.AreEqual(model.Quantity, purchases.First().Quantity); }