コード例 #1
0
        public void Can_Remove_Product_From_Cart()
        {
            // Подготовка
            var mockProductsRepository = new Moq.Mock<IProductsRepository>();
            var products = new List<Product>()
            {
                new Product {ProductID=14, Name="Much Ado About Nothing" },
                new Product {ProductID=27, Name="The Comedy of Errors" }
            };
            mockProductsRepository.Setup(x => x.Products)
                                  .Returns(products.AsQueryable());
            var cart = new Cart();
            var controller = new CartController(mockProductsRepository.Object, null);
            controller.AddToCart(cart, 14, "someReturnUrl");
            controller.AddToCart(cart, 27, "someReturnUrl");
            Assert.AreEqual(2, cart.Lines.Count);
            // Действие
            RedirectToRouteResult result =
                controller.RemoveFromCart(cart, 14, "someReturnUrl");
            // Утверждение
            Assert.AreEqual(1, cart.Lines.Count);
            Assert.AreEqual(27, cart.Lines[0].Product.ProductID);

            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
        }
コード例 #2
0
 public void Index_Action_Renders_Default_View_With_Cart_And_ReturnUrl()
 {
     // Подготовка
     Cart cart = new Cart();
     CartController controller = new CartController(null,null);
     // Действие
     ViewResult result = controller.Index(cart, "myReturnUrl");
     // Утверждение
     Assert.IsEmpty(result.ViewName);
     Assert.AreSame(cart, result.ViewData.Model);
     Assert.AreEqual("myReturnUrl", result.ViewData["returnUrl"]);
     Assert.AreEqual("Cart", result.ViewData["CurrentCategory"]);
 }
コード例 #3
0
 public void Cad_Add_Product_To_Cart()
 {
     // Подгтовка
     var mockProductsRepository = new Moq.Mock<IProductsRepository>();
     var products = new List<Product>()
     {
         new Product {ProductID=14, Name="Much Ado About Nothing" },
         new Product {ProductID=27, Name="The Comedy of Errors" }
     };
     mockProductsRepository.Setup(x => x.Products)
                           .Returns(products.AsQueryable());
     var cart = new Cart();
     var controller = new CartController(mockProductsRepository.Object, null);
     // Действие
     RedirectToRouteResult result =
         controller.AddToCart(cart, 27, "someReturnUrl");
     // Утверждение
     Assert.AreEqual(1, cart.Lines.Count);
     Assert.AreEqual("The Comedy of Errors", cart.Lines[0].Product.Name);
     Assert.AreEqual(1, cart.Lines[0].Quantity);
     // Проверка перенаправления на экран отображения корзины
     Assert.AreEqual("Index", result.RouteValues["action"]);
     Assert.AreEqual("someReturnUrl", result.RouteValues["returnUrl"]);
 }
コード例 #4
0
        public void Summary_Action_Renders_View_With_Total()
        {
            CartController controller = new CartController(null, null);
            Cart cart = new Cart();
            Product p1 = new Product() { ProductID = 1, Price = 12 };
            Product p2 = new Product() { ProductID = 2, Price = 50 };
            cart.AddItem(p1, 12);
            cart.AddItem(p2, 5);

            ViewResult result = controller.Summary(cart);

            Assert.AreEqual(cart, ((Cart)result.ViewData.Model));
            Assert.AreEqual(cart.Lines.Count, ((Cart)result.ViewData.Model).Lines.Count);
            Assert.AreEqual(cart.ComputeTotalValue(), ((Cart)result.ViewData.Model).ComputeTotalValue());
        }
コード例 #5
0
        public void Valie_Order_Goes_To_Submitter_And_Displays_Completed_View()
        {
            var mockSubmitter = new Moq.Mock<IOrderSubmitter>();
            CartController controller = new CartController(null, mockSubmitter.Object);
            controller.ControllerContext = new ControllerContext();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);
            var formData = new FormCollection
            {
                {"Name","Steve" }, {"Line1","123 My Street" },
                {"Line2", "MyArea" }, {"Line3","" },
                {"City","MyCity" }, {"State","Some State" },
                {"Zip","123ABCDEF" }, {"Country","Far far away" },
                {"GiftWrap",bool.TrueString }
            };

            var result = controller.CheckOut(cart, formData);

            Assert.AreEqual("Completed", result.ViewName);
            mockSubmitter.Verify(x => x.SubmitOrder(cart));
            Assert.AreEqual(0, cart.Lines.Count);
        }
コード例 #6
0
        public void Submitting_Empty_Shipping_Details_Displays_Default_View_With_Error()
        {
            CartController controller = new CartController(null,null);
            controller.ControllerContext = new ControllerContext();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

            var result = controller.CheckOut(cart, new FormCollection {
                {"Name", "" }
            });
            Assert.IsEmpty(result.ViewName);
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }
コード例 #7
0
        public void Submitting_Order_With_No_Lines_Displays_View_With_Error()
        {
            CartController controller = new CartController(null,null);
            Cart cart = new Cart();

            var result = controller.CheckOut(cart, new FormCollection());

            Assert.IsEmpty(result.ViewName);
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }