コード例 #1
0
        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
0
        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
0
ファイル: Products.cs プロジェクト: Itdotaer/SportsStore
        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
0
ファイル: Products.cs プロジェクト: Itdotaer/SportsStore
        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
0
ファイル: Products.cs プロジェクト: Itdotaer/SportsStore
        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
0
ファイル: Products.cs プロジェクト: Itdotaer/SportsStore
        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
0
ファイル: Products.cs プロジェクト: Itdotaer/SportsStore
        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
0
            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
0
            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("~/");
            }