當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。