public void ReturnCorrectOrderIfValidationCorrect() { var date = DateTime.Now; OrderValidators.UserName = "******"; var boughtGood = new Good() { FullName = "TestGoodName", ID = 1, ProducedAt = date }; OrderValidators.AllGoods = new List <Good>() { boughtGood }; var order = OrdersManipulator.CreateAndReturnNewOrder("TestUser", boughtGood, OrderValidators.IsValidOrder); var expectedOrder = new Order() { OrderId = 0, FullGoodName = "TestGoodName", GoodAmount = 1, GoodCategory = null, GoodId = 1, GoodImgSrc = "no information", GoodPrice = 0, OrderStatus = OrderStatus.Registered.ToString(), PaidAt = null, UserName = "******" }; Assert.AreEqual(expectedOrder.ToString(), order.ToString()); }
public async Task <ActionResult> CreateRegisteredOrder(int[] goodId, string[] category, string ids = null, string ctgrs = null) { AppUser currUser = await UserManager.FindByNameAsync(User.Identity.Name); if (!string.IsNullOrEmpty(ids) && !string.IsNullOrEmpty(ctgrs)) { goodId = Array.ConvertAll(ids.Split(','), int.Parse); category = ctgrs.Split(','); } int i = 0; OrderValidators.UserName = User.Identity.Name; while (i < goodId.Length && i < category.Length) { OrderValidators.AllGoods = pcComponentsUnit.GetGoodsDependsOnCategory(category[i]); HttpCookie cookieReq = Request.Cookies["ShoppingBasket"]; string findItem = string.Format($"+{goodId[i]},{category[i]}+"); if (cookieReq != null && cookieReq["ShoppingBasket"].Contains(findItem)) { Order order = OrdersManipulator.CreateAndReturnNewOrder( User.Identity.Name, pcComponentsUnit.GetGoodsDependsOnCategory(category[i]).FirstOrDefault(g => g.ID == goodId[i]), OrderValidators.IsValidOrder); if (order != null) { pcComponentsUnit.Orders.Create(order); pcComponentsUnit.Save(); cookieReq["ShoppingBasket"] = cookieReq["ShoppingBasket"].Replace(findItem, ""); Response.Cookies.Add(cookieReq); OrderInfoEvent($"Order({order.OrderId}) has been created and registered\nOwner name:{order.UserName}\n" + $"GoodId: {order.GoodId} Price: {order.GoodPrice}"); if (currUser != null) { currUser.GoodsInBasket = cookieReq["ShoppingBasket"]; await UserManager.UpdateAsync(currUser); } } } i++; } return(RedirectToActionPermanent("Orders")); }
public void ReturnNullIfValidationIncorrectUserNameDoesNotMatch() { var date = DateTime.Now; OrderValidators.UserName = "******"; var boughtGood = new Good() { FullName = "TestGoodName", ID = 1, ProducedAt = date }; OrderValidators.AllGoods = new List <Good>() { boughtGood }; var order = OrdersManipulator.CreateAndReturnNewOrder("TestUser", boughtGood, OrderValidators.IsValidOrder); Assert.AreEqual(null, order); }