コード例 #1
0
        public void TestDecreaseAmountOnProductLine()
        {
            // Arrange
            var context = new Mock <ControllerContext>();
            var session = new MockHttpSession();

            List <ProductLine> productLineList = new List <ProductLine>();

            ShoppingCartController cartController = new ShoppingCartController();

            cartController.ControllerContext = context.Object;

            Product product = new Product();

            product.ProductId = 1;
            product.Price     = 100;

            ProductLine productLine = new ProductLine();

            productLine.Amount  = 1;
            productLine.Product = product;

            productLineList.Add(productLine);
            session.insertIntoDictionary("shoppingCart", productLineList);

            context.Setup(m => m.HttpContext.Session).Returns(session);

            // Act
            cartController.Add(product);
            cartController.DecreaseAmount(productLine.Product.ProductId);

            // Assert
            Assert.AreEqual(1, productLine.Amount);
        }