예제 #1
0
        public async Task WhenCartIsNotClear_ExpectedOKModel()
        {
            //Arrange
            IEnumerable <IProduct> products = new[] { new Good()
                                                      {
                                                          Price = 1
                                                      }, new Good()
                                                      {
                                                          Price = 2
                                                      } };
            decimal exepectedPrice = 3m;

            var cartServ = new Mock <ICart>();

            cartServ.SetupAllProperties();
            cartServ.Setup((c) => c.All())
            .Returns(products);

            var cart = new preparation.Controllers.CartController(cartServ.Object);
            //Actual
            var res = cart.Index();
            //Assert
            var actionResult = Assert.IsType <ViewResult>(res);
            var model        = Assert.IsAssignableFrom <CartViewModel>(actionResult.ViewData.Model);

            NUnitAssert.AreEqual(products, model.Products);
            NUnitAssert.Null(model.PromoCode);
            NUnitAssert.AreEqual(exepectedPrice, model.TotalPrice);
        }
예제 #2
0
        public async Task WhenCartIsClear_ExpectedNotNullModel()
        {
            //Arrange
            var cartServ = new Mock <ICart>();

            cartServ.SetupAllProperties();
            var cart = new preparation.Controllers.CartController(cartServ.Object);
            //Actual
            var res = cart.Index();
            //Assert
            var actionResult = Assert.IsType <ViewResult>(res);
            var model        = Assert.IsAssignableFrom <CartViewModel>(actionResult.ViewData.Model);

            NUnitAssert.Null(model.Products);
            NUnitAssert.Null(model.PromoCode);
            NUnitAssert.AreEqual(0, model.TotalPrice);
        }