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"]);
        }
 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"]);
 }