public JsonResult DeleteWishList(long goodId) { var resultCode = 0; var customer = new CustomerAction(Session.GetUserId()); try { customer.DeleteWishList(goodId); } catch (Exception) { resultCode = -1; } try { Session.UpdateWishList(); var wishList = Session.GetUser().wishList; var result = new { result = resultCode, wishCount = (customer.GetWishList()?.Count() ?? 0) }; return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception) { resultCode = -2; var result = new { result = resultCode, wishCount = 0 }; return(Json(result, JsonRequestBehavior.AllowGet)); } }
public void TestWishList() { var customer = new CustomerAction(8); var store = new StoreAction(); customer.AddToWishList(3); customer.AddToWishList(4); customer.AddToWishList(5); var withList = customer.GetWishList(); Assert.IsTrue(withList.Count() > 2); customer.DeleteWishList(3); Assert.IsNull(customer.GetWishList().FirstOrDefault(s => s.id == 3)); customer.ClearWishList(); Assert.IsTrue(customer.GetWishList().Count() == 0); }