本文整理匯總了C#中SportsStore.WebUI.Controllers.CartController.AddtoCart方法的典型用法代碼示例。如果您正苦於以下問題:C# CartController.AddtoCart方法的具體用法?C# CartController.AddtoCart怎麽用?C# CartController.AddtoCart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SportsStore.WebUI.Controllers.CartController
的用法示例。
在下文中一共展示了CartController.AddtoCart方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Adding_Product_To_Cart_Goes_To_Cart_Screen
public void Adding_Product_To_Cart_Goes_To_Cart_Screen()
{
//Arrange - create the mosk repo
Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
mock.Setup(m => m.Products).Returns(new Product[]
{
new Product {ProductID =1, Name = "P1", Category = "Apples" },
}.AsQueryable());
//Arrage - create a Cart
Cart cart = new Cart();
//Arrage - create the controller
CartController target = new CartController(mock.Object, null);
//Act - add a product to the cart
RedirectToRouteResult result = target.AddtoCart(cart, 2, "myUrl");
//Assert
Assert.AreEqual(result.RouteValues["action"], "Index");
Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
}
示例2: Can_Add_To_Cart
public void Can_Add_To_Cart()
{
//Arrange - create the mosk repo
Mock<IProductsRepository> mock = new Mock<IProductsRepository>();
mock.Setup(m => m.Products).Returns(new Product[]
{
new Product {ProductID =1, Name = "P1", Category = "Apples" },
}.AsQueryable());
//Arrage - create a Cart
Cart cart = new Cart();
//Arrage - create the controller
CartController target = new CartController(mock.Object, null);
//Act - add a product to the cart
target.AddtoCart(cart, 1, null);
//Assert
Assert.AreEqual(cart.Lines.Count(), 1);
Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
}