当前位置: 首页>>代码示例>>C#>>正文


C# Cart.AddProduct方法代码示例

本文整理汇总了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 });
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:11,代码来源:CartController.cs

示例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));
        }
开发者ID:jupaol,项目名称:LearningProjects,代码行数:11,代码来源:CartController.cs

示例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());
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:18,代码来源:Products.cs

示例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);
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:18,代码来源:Products.cs

示例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());
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:23,代码来源:Products.cs

示例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);
        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:25,代码来源:Products.cs

示例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);

        }
开发者ID:Itdotaer,项目名称:SportsStore,代码行数:23,代码来源:Products.cs

示例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());
            }
开发者ID:jupaol,项目名称:LearningProjects,代码行数:15,代码来源:CartControllerTests.cs

示例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("~/");
            }
开发者ID:jupaol,项目名称:LearningProjects,代码行数:12,代码来源:CartControllerTests.cs


注:本文中的SportsStore.Domain.Entities.Cart.AddProduct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。