Exemple #1
0
        public void Index4Test()
        {
            //创建模仿对象
            Mock <IDiscountHelper> mock = new Mock <IDiscountHelper>();

            //选择方法,并传递参数,Return方法返回结果
            mock.Setup(m => m.ApplyDiscount(It.IsAny <decimal>())).Returns <decimal>(total => total);
            //读取Mock对象的Object属性
            var target = new LinqValueCalc(mock.Object);
        }
Exemple #2
0
        //[Route("Index2")]
        public ActionResult Index2()
        {
            var dis = new DefDiscountHelp();

            dis.DiscountSize = 10;
            IValueCalc   value = new LinqValueCalc(dis);
            ShoppingCart shop  = new ShoppingCart(value)
            {
                product = new List <Product>()
                {
                    new Product()
                    {
                        UnitPrice = 100,
                    },
                    new Product()
                    {
                        UnitPrice = 200,
                    },
                }
            };
            var total = shop.CalcProductTotal();

            return(View(total));
        }