本文整理汇总了C#中SportsStore.WebUI.Controllers.CartController.RemoveFromCart方法的典型用法代码示例。如果您正苦于以下问题:C# CartController.RemoveFromCart方法的具体用法?C# CartController.RemoveFromCart怎么用?C# CartController.RemoveFromCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SportsStore.WebUI.Controllers.CartController
的用法示例。
在下文中一共展示了CartController.RemoveFromCart方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_Remove_From_Cart
public void Can_Remove_From_Cart()
{
var productsArray = products.Products.ToArray();
Cart cart = new Cart();
cart.AddItem(productsArray[0], 1);
cart.AddItem(productsArray[1], 1);
cart.AddItem(productsArray[2], 1);
CartController target = new CartController(products, orderProcessor);
RedirectToRouteResult result = (RedirectToRouteResult)target.RemoveFromCart(cart, productsArray[1].ProductID, "testUrl");
Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl");
Assert.AreEqual(result.RouteValues["action"], "Index");
Assert.AreEqual(cart.Lines.ToArray()[0].Product, productsArray[0]);
Assert.AreEqual(cart.Lines.ToArray()[1].Product, productsArray[2]);
}
示例2: Deleting_Product_To_Cart_Goes_To_Cart_Screen
public void Deleting_Product_To_Cart_Goes_To_Cart_Screen()
{
//Arrange
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(products.AsQueryable());
CartController target = new CartController(mock.Object, null); // TODO: Initialize to an appropriate value
Cart cart = new Cart(); // TODO: Initialize to an appropriate value
//Act
RedirectToRouteResult result = target.RemoveFromCart(cart, 2, "myUrl");
//Assert
Assert.AreEqual("Index", result.RouteValues["Action"]);
Assert.AreEqual("myUrl", result.RouteValues["returnUrl"]);
}
示例3: Can_Delete_Product_From_Cart
public void Can_Delete_Product_From_Cart()
{
//Arrange
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(products.AsQueryable());
CartController target = new CartController(mock.Object, null); // TODO: Initialize to an appropriate value
Cart cart = new Cart(); // TODO: Initialize to an appropriate value
target.AddToCart(cart, 1, "myUrl");
//Act
RedirectToRouteResult result = target.RemoveFromCart(cart, 1, "myUrl");
//Assert
Assert.AreSame(cart, cart);
Assert.AreEqual(0, cart.Lines.ToArray().Length);
}
示例4: Can_Remove_From_Cart
public void Can_Remove_From_Cart()
{
Product p1 = new Product { ProductID = 1, Name = "P1", Category = "Apples" };
Product p2 = new Product { ProductID = 2, Name = "P2", Category = "Pear" };
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new Product[] { p1, p2
}.AsQueryable());
Cart cart = new Cart();
cart.AddItem(p1, 1);
cart.AddItem(p2, 3);
cart.AddItem(p1, 2);
CartController target = new CartController(mock.Object, null);
target.RemoveFromCart(cart, 1, null);
Assert.AreEqual(cart.Lines.Count(), 1);
Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 2);
}
示例5: Can_Remove_Product_From_Cart
public void Can_Remove_Product_From_Cart()
{
var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
new Product { ProductId = 123 }
, new Product { ProductId = 456 }
);
var cartController = new CartController(mockProductsRepository, null);
var cart = new Cart();
if (mockProductsRepository.Products != null)
foreach (var product in mockProductsRepository.Products)
cartController.AddToCart(cart, product.ProductId, null);
cartController.RemoveFromCart(cart, 456, null);
cart.Lines.Count.ShouldEqual(1);
cart.Lines[0].Product.ProductId.ShouldEqual(123);
}
示例6: Can_Remove_Product_From_Cart
public void Can_Remove_Product_From_Cart()
{
// Arrange: Given a repository with some products...
var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
new Product { ProductID = 1 }
);
var cartController = new CartController(mockProductsRepository,null);
var cart = new Cart();
// Act: When a user adds a product to their cart...
cartController.AddToCart(cart, 1, null);
var result = cartController.RemoveFromCart(cart, 1, "deleteReturnUrl");
// Assert: Then the user is redirected to the Cart Index screen
result.ShouldBeRedirectionTo(new
{
action = "Index",
returnUrl = "deleteReturnUrl"
});
}