本文整理汇总了C#中SportsStore.Domain.Entities.Cart.AddProduct方法的典型用法代码示例。如果您正苦于以下问题:C# Cart.AddProduct方法的具体用法?C# Cart.AddProduct怎么用?C# Cart.AddProduct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SportsStore.Domain.Entities.Cart
的用法示例。
在下文中一共展示了Cart.AddProduct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToCart
public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
{
var product = _repository.Products.FirstOrDefault(p => p.ProductID == productId);
if (product != null)
{
cart.AddProduct(product, 1);
}
return RedirectToAction("Index", new { returnUrl });
}
示例2: AddToCart
public virtual RedirectToRouteResult AddToCart(Cart cart, int productID, string returnUrl)
{
var product = this.repository.GetProducts().FirstOrDefault(x => x.ProductID == productID);
if (product != null)
{
cart.AddProduct(product, 1);
}
return RedirectToAction(MVC.Cart.Index(cart, returnUrl));
}
示例3: CanClearContents
public void CanClearContents()
{
//array
var prod1 = new Product { ProductID = 1, Name = "p1", Price = 100M };
var prod2 = new Product { ProductID = 2, Name = "p2", Price = 50M };
//arrange
var target = new Cart();
target.AddProduct(prod1, 2);
target.AddProduct(prod1, 8);
target.AddProduct(prod2, 1);
//act
target.Clear();
//assert
Assert.AreEqual(0, target.Lines.Count());
}
示例4: CalculateCartTotal
public void CalculateCartTotal()
{
//arrange
var prod1 = new Product { ProductID = 1, Name = "p1", Price = 100M};
var prod2 = new Product { ProductID = 2, Name = "p2", Price = 50M};
//arrange
var target = new Cart();
//act
target.AddProduct(prod1, 2);
target.AddProduct(prod1, 8);
target.AddProduct(prod2, 1);
var result = target.CoputeTotalValue();
//assert
Assert.AreEqual(1050M, result);
}
示例5: CanRemoveLine
public void CanRemoveLine()
{
//arrange
var prod1 = new Product { ProductID = 1, Name = "p1" };
var prod2 = new Product { ProductID = 2, Name = "p2" };
var prod3 = new Product { ProductID = 3, Name = "p3" };
//array
var target = new Cart();
//arrange
target.AddProduct(prod1, 1);
target.AddProduct(prod2, 3);
target.AddProduct(prod3, 5);
target.AddProduct(prod2, 1);
//act
target.RemoveLine(prod2);
//assert
Assert.AreEqual(0, target.Lines.Count(l => l.Product.ProductID == prod2.ProductID));
Assert.AreEqual(2, target.Lines.Count());
}
示例6: CanAddQuantityForExistingLines
public void CanAddQuantityForExistingLines()
{
//arrange
var prod1 = new Product {ProductID = 1, Name = "p1"};
var prod2 = new Product { ProductID = 2, Name = "p2" };
var prod3 = new Product { ProductID = 3, Name = "p3" };
//arrange
var target = new Cart();
//act
target.AddProduct(prod1, 10);
target.AddProduct(prod1, 1);
target.AddProduct(prod2, 1);
target.AddProduct(prod3, 2);
var results = target.Lines.OrderBy(l => l.Product.ProductID);
//assert
var linesArray = results.ToArray();
Assert.AreEqual(linesArray.Length, 3);
Assert.AreEqual(linesArray[0].Product.ProductID, 1);
Assert.AreEqual(linesArray[0].Quantity, 11);
Assert.AreEqual(linesArray[1].Quantity, 1);
Assert.AreEqual(linesArray[2].Quantity, 2);
}
示例7: CanAddNewLies
public void CanAddNewLies()
{
//arrange
var prod1 = new Product { ProductID = 1, Name = "p1" };
var prod2 = new Product { ProductID = 2, Name = "p2" };
//arrange
var target = new Cart();
//act
target.AddProduct(prod1, 1);
target.AddProduct(prod2, 2);
var results = target.Lines.OrderBy(l => l.Product.ProductID);
//assert
var linesArray = results.ToArray();
Assert.AreEqual(2, linesArray.Length);
Assert.AreEqual(1, linesArray[0].Product.ProductID);
Assert.AreEqual(2, linesArray[1].Product.ProductID);
Assert.AreEqual(1, linesArray[0].Quantity);
Assert.AreEqual(2, linesArray[1].Quantity);
}
示例8: whene_there_are_no_errors_it_should_redirect_to_a_completed_action
public void whene_there_are_no_errors_it_should_redirect_to_a_completed_action()
{
var sut = CartControllerTests.GetCartController();
var cart = new Cart();
var shippingDetails = new ShippingDetails();
cart.AddProduct(Builder<Product>.CreateNew().Build(), 3);
var res = sut.Checkout("~/", cart, shippingDetails) as RedirectToRouteResult;
res.RouteValues["action"].ToString().Should().Be("OrderCompleted");
res.RouteValues["returnUrl"].ToString().Should().Be("~/");
sut.ModelState.IsValid.Should().BeTrue();
CartControllerTests.OrderProcessorMock.Verify(x => x.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once());
}
示例9: it_should_render_the_default_view_passing_the_returnUrl_parameter
public void it_should_render_the_default_view_passing_the_returnUrl_parameter()
{
var sut = CartControllerTests.GetCartController();
var cart = new Cart();
cart.AddProduct(new Product(), 2);
var res = sut.Checkout("~/", cart);
res.ViewName.Should().BeEmpty(); // default view rendered
res.ViewData["ReturnUrl"].ToString().Should().Be("~/");
}