本文整理汇总了C#中SportsStore.WebUI.Controllers.CartController.AddToCart方法的典型用法代码示例。如果您正苦于以下问题:C# CartController.AddToCart方法的具体用法?C# CartController.AddToCart怎么用?C# CartController.AddToCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SportsStore.WebUI.Controllers.CartController
的用法示例。
在下文中一共展示了CartController.AddToCart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Adding_Product_To_Cart_Goes_To_Cart_Screen
public void Adding_Product_To_Cart_Goes_To_Cart_Screen()
{
// Arrange
// - Create the mock repository
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new Product[] {
new Product { ProductID = 1, Name = "P1", Category = "Apples" }
}.AsQueryable());
// Arrange
// - Create a Cart
Cart cart = new Cart();
// Arrange
// - 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: Adding_product_goes_to_cart_screen
public void Adding_product_goes_to_cart_screen()
{
var cart = new Cart();
var controller = new CartController(CreateRepositoryMock().Object, null);
var result = controller.AddToCart(cart, 2, "my url");
Assert.AreEqual(result.RouteValues["action"], "Index");
Assert.AreEqual(result.RouteValues["returnUrl"], "my url");
}
示例3: Adding_Products_To_Cart_Goes_To_Cart_Screen
public void Adding_Products_To_Cart_Goes_To_Cart_Screen()
{
var productsArray = products.Products.ToArray();
Cart cart = new Cart();
CartController target = new CartController(products, orderProcessor);
RedirectToRouteResult result = target.AddToCart(cart, 1, "testUrl");
Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl");
Assert.AreEqual(result.RouteValues["action"], "Index");
}
示例4: Can_Add_To_Cart
public void Can_Add_To_Cart()
{
var productsArray = products.Products.ToArray();
Cart cart = new Cart();
CartController target = new CartController(products, orderProcessor);
target.AddToCart(cart, 1, "testUrl");
Assert.AreEqual(cart.Lines.Count(), 1);
Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
}
示例5: After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen
public void After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen()
{
var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
new Product { ProductId = 1 }
);
var cartController = new CartController(mockProductsRepository, null);
var result = cartController.AddToCart(new Cart(), 1, "someReturnUrl");
result.ShouldBeRedirectionTo(new {action = "Index", returnUrl = "someReturnUrl"});
}
示例6: Can_add_to_cart
public void Can_add_to_cart()
{
var mockRepository = CreateRepositoryMock();
var controller = new CartController(mockRepository.Object, null);
var cart = new Cart();
controller.AddToCart(cart, 1, null);
Assert.AreEqual(1, cart.Lines.Count());
Assert.AreEqual(cart.Lines.ElementAt(0).Product.ProductID, 1);
}
示例7: Adding_Prod_To_Cart_Goes_To_Cart_Screen
public void Adding_Prod_To_Cart_Goes_To_Cart_Screen()
{
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new Product[]{
new Product{ProductID = 1, Name = "P1",Category = "Apples"},
}.AsQueryable());
Cart cart = new Cart();
CartController target = new CartController(mock.Object, null);
RedirectToRouteResult res = target.AddToCart(cart, 2, "MyUrl");
Assert.AreEqual(res.RouteValues["action"], "Index");
Assert.AreEqual(res.RouteValues["returnUrl"], "MyUrl");
}
示例8: Can_Add_To_Cart
public void Can_Add_To_Cart()
{
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new Product[]{
new Product{ProductID = 1, Name = "P1",Category = "Apples"},
}.AsQueryable());
Cart cart = new Cart();
CartController target = new CartController(mock.Object, null);
target.AddToCart(cart, 1, null);
Assert.AreEqual(cart.Lines.Count(), 1);
Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
}
示例9: AddingProductToCartGoesToCartScreen
public void AddingProductToCartGoesToCartScreen()
{
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new[]
{new Product {ProductID = 1, Name = "P1", Category = "Apples"}}
);
Cart cart = new Cart();
CartController target = new CartController(mock.Object, null);
var result = target.AddToCart(cart, 1, "myUrl");
Assert.AreEqual(result.RouteValues["action"], "Index");
Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
}
示例10: AddingProductToCartScreen
public void AddingProductToCartScreen()
{
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new Product[]
{
new Product(){Id = 1, Name = "P1", Category = "Jabłka"}
}.AsQueryable());
Cart cart = new Cart();
CartController controller = new CartController(mock.Object, null);
RedirectToRouteResult result = controller.AddToCart(cart, 2, "myUrl");
Assert.AreEqual(result.RouteValues["action"], "Index");
Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
}
示例11: Can_Add_Product_To_Cart
public void Can_Add_Product_To_Cart()
{
var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
new Product {ProductId = 123}
, new Product {ProductId = 456}
);
var cartController = new CartController(mockProductsRepository, null);
var cart = new Cart();
cartController.AddToCart(cart, 456, null);
cart.Lines.Count.ShouldEqual(1);
cart.Lines[0].Product.ProductId.ShouldEqual(456);
}
示例12: Adding_Product_To_Cart_Goes_To_Cart_Screen
public void Adding_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.AddToCart(cart, 2, "myUrl");
//Assert
Assert.AreEqual("Index", result.RouteValues["Action"]);
Assert.AreEqual("myUrl", result.RouteValues["returnUrl"]);
}
示例13: After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen
public void After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen()
{
// Arrange: Given a repository with some products...
var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
new Product { ProductID = 1 }
);
var cartController = new CartController(mockProductsRepository, null);
// Act: When a user adds a product to their cart...
var result = cartController.AddToCart(new Cart(), 1, "someReturnUrl");
// Assert: Then the user is redirected to the Cart Index screen
result.ShouldBeRedirectionTo(new {
action = "Index",
returnUrl = "someReturnUrl"
});
}
示例14: CanAddToCart
public void CanAddToCart()
{
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(x => x.Products).Returns(new Product[]
{
new Product { ProductID = 1, Category = "Apples", Name = "P1" }
});
Cart cart = new Cart();
CartController target = new CartController(mock.Object, null);
target.AddToCart(cart, 1, null);
Assert.AreEqual(1, cart.Lines.Count());
Assert.AreEqual(1, cart.Lines.ElementAt(0).Product.ProductID);
}
示例15: CartController_AddToCart_GoesToCartScreen
public void CartController_AddToCart_GoesToCartScreen()
{
// Arrange
Mock<IProductRepository> mock = new Mock<IProductRepository>();
mock.Setup(m => m.Products).Returns(new Product[] {
new Product {ProductID = 1, Name = "P1", Category = "Apples" },
}.AsQueryable());
Cart cart = new Cart();
var target = new CartController(mock.Object, null);
// Act
var result = target.AddToCart(cart, 1, "myUrl");
// Assert
Assert.AreEqual<string>(result.RouteValues["action"].ToString(), "Index");
Assert.AreEqual<string>(result.RouteValues["returnUrl"].ToString(), "myUrl");
}