当前位置: 首页>>代码示例>>C#>>正文


C# Controllers.CartController类代码示例

本文整理汇总了C#中SportsStore.WebUI.Controllers.CartController的典型用法代码示例。如果您正苦于以下问题:C# CartController类的具体用法?C# CartController怎么用?C# CartController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CartController类属于SportsStore.WebUI.Controllers命名空间,在下文中一共展示了CartController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Adding_Product_To_Cart_Goes_To_Cart_Screen

        public void Adding_Product_To_Cart_Goes_To_Cart_Screen()
        {
            // Arrange
            // - Create the mock repository
            Mock<IProductRepository> mock = new Mock<IProductRepository>();
            mock.Setup(m => m.Products).Returns(new Product[] {
                new Product { ProductID = 1, Name = "P1", Category = "Apples" }
            }.AsQueryable());

            // Arrange
            // - Create a Cart
            Cart cart = new Cart();

            // Arrange
            // - Create the controller
            CartController target = new CartController(mock.Object, null);

            // Act
            // - Add a product to the cart
            RedirectToRouteResult result = target.AddToCart(cart, 2, "myUrl");

            // Assert
            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["returnUrl"], "myUrl");
        }
开发者ID:Zanion,项目名称:SportsStore,代码行数:25,代码来源:CartTests.cs

示例2: Cannot_Checkout_Empty_Cart

        public void Cannot_Checkout_Empty_Cart()
        {
            // Arragne - Mock 주문 처리기 생성
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            // Arrange - 빈 Cart 개체 생성
            Cart cart = new Cart();

            // Arragne - 배송 정보 생성
            ShippingDetails shippingDetails = new ShippingDetails();

            // Arrange - 컨트롤러의 인스턴스 생성
            CartController target = new CartController(null, mock.Object);

            // Act
            ViewResult result = target.Checkout(cart, shippingDetails);

            // Assert - 주문이 주문 처리기에 전달되지 않은 것을 확인한다.
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
                Times.Never());
            // Assert - 메서드가 기본 뷰를 반환했는지 확인한다.
            Assert.AreEqual("", result.ViewName);

            // Assert - 유효하지 않은 모델을 뷰에 전달하는지 확인한다
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
开发者ID:EthanK28,项目名称:pro-asp-mvc5,代码行数:25,代码来源:CartTests.cs

示例3: Cannot_Checkout_Empty_Cart

        public void Cannot_Checkout_Empty_Cart()
        {
            // arrange -create a mock order processor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // arrange - create an empty cart
            Cart cart = new Cart();

            // arrange - create shipping details
            ShippingDetails shippingDetails = new ShippingDetails();

            // arrange - create an instance of the controller
            CartController target = new CartController(null, mock.Object);

            // act - get a result back from the CartController.CheckOut() method
            ViewResult result = target.CheckOut(cart, shippingDetails);

            // assert - verify that processorder method is never called
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never);

            // assert - check that the method is returning the default view
            Assert.AreEqual("", result.ViewName);

            // assert - check that i am passing an invalid model to the view
            Assert.AreEqual(false,result.ViewData.ModelState.IsValid);
        }
开发者ID:pixelsyndicate,项目名称:Pro_AspNet_MVC_5_book,代码行数:26,代码来源:CartTests.cs

示例4: Cannot_Checkout_Invalid_ShippingDetails

        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // Arrange - create a mock order processor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // Arrange - create a cart with an item
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

            // Arrange - create an instance of the controller
            CartController target = new CartController(null, mock.Object);

            // Arrange - add an error to the model
            target.ModelState.AddModelError("error", "error");

            // Act - try to checkout
            ViewResult result = target.Checkout(cart, new ShippingDetails());

            // Assert - check that the order hasn't been passed on to the processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
                Times.Never());
            // Assert - check that the method is returning the default view
            Assert.AreEqual("", result.ViewName);
            // Assert - check that I am passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
开发者ID:devscott,项目名称:SportsStore,代码行数:26,代码来源:CartControllerTests.cs

示例5: Cannot_Checkout_Empty_Cart

        public void Cannot_Checkout_Empty_Cart()
        {
            // Arrange create a mock order processor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // Arrange create an empty cart
            Cart cart = new Cart();

            // Arrange create shipping details
            ShippingDetails shippingDetails = new ShippingDetails();

            // Arrange create an instance of the controller
            CartController target = new CartController(null, mock.Object);

            // Act
            ViewResult result = target.Checkout(cart, shippingDetails);

            // Assert check that the order hasn't been passed on to the processor
            mock.Verify(m => m.ProcessOrder(
                It.IsAny<Cart>(),
                It.IsAny<ShippingDetails>()),
                Times.Never()
            );

            // Assert check that the method is returning the default view
            Assert.AreEqual("", result.ViewName);

            // Assert check that I am passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
开发者ID:xpk-rodaire,项目名称:SportsStore,代码行数:30,代码来源:CartTests.cs

示例6: Cannot_Check_Out_If_Cart_Is_Empty

        public void Cannot_Check_Out_If_Cart_Is_Empty()
        {
            var emptyCart = new Cart();
            var shippingDetails = new ShippingDetails();

            var result = new CartController(null, null).CheckOut(emptyCart, shippingDetails);

            result.ShouldBeDefaultView();
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:9,代码来源:ShoppingCart.cs

示例7: Adding_Products_To_Cart_Goes_To_Cart_Screen

        public void Adding_Products_To_Cart_Goes_To_Cart_Screen()
        {
            var productsArray = products.Products.ToArray();
            Cart cart = new Cart();
            CartController target = new CartController(products, orderProcessor);

            RedirectToRouteResult result = target.AddToCart(cart, 1, "testUrl");
            Assert.AreEqual(result.RouteValues["returnUrl"], "testUrl");
            Assert.AreEqual(result.RouteValues["action"], "Index");
        }
开发者ID:Shiloff,项目名称:SportsStore,代码行数:10,代码来源:CartTests.cs

示例8: Cant_CheckOut_if_a_Cart_is_Empty

        public void Cant_CheckOut_if_a_Cart_is_Empty()
        {
            Cart cart = new Cart();

            CartController controller = new CartController(null);

            var IsValid = controller.CheckOut(cart, null).ViewData.ModelState.IsValid;

            Assert.IsFalse(IsValid);
        }
开发者ID:CacoDurban,项目名称:SportsStore,代码行数:10,代码来源:CartControllerTest.cs

示例9: Can_view_cart_contents

        public void Can_view_cart_contents()
        {
            var cart = new Cart();
            var controller = new CartController(null, null);

            var result = (CartIndexViewModel)controller.Index(cart, "myurl").ViewData.Model;

            Assert.AreSame(cart, result.Cart);
            Assert.AreEqual("myurl", result.ReturnUrl);
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:10,代码来源:CartControllerTests.cs

示例10: Adding_product_goes_to_cart_screen

        public void Adding_product_goes_to_cart_screen()
        {
            var cart = new Cart();
            var controller = new CartController(CreateRepositoryMock().Object, null);

            var result = controller.AddToCart(cart, 2, "my url");

            Assert.AreEqual(result.RouteValues["action"], "Index");
            Assert.AreEqual(result.RouteValues["returnUrl"], "my url");
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:10,代码来源:CartControllerTests.cs

示例11: Can_View_Cart_Content

        public void Can_View_Cart_Content()
        {
            Cart cart = new Cart();
            CartController target = new CartController(null, null);

            CartIndexViewModel res = (CartIndexViewModel)target.Index(cart, "MyUrl").ViewData.Model;

            Assert.AreSame(res.Cart, cart);
            Assert.AreEqual(res.ReturnUrl, "MyUrl");
        }
开发者ID:Karoliner,项目名称:sports_store,代码行数:10,代码来源:UnitTest2.cs

示例12: Can_Add_To_Cart

        public void Can_Add_To_Cart()
        {
            var productsArray = products.Products.ToArray();
            Cart cart = new Cart();
            CartController target = new CartController(products, orderProcessor);

            target.AddToCart(cart, 1, "testUrl");

            Assert.AreEqual(cart.Lines.Count(), 1);
            Assert.AreEqual(cart.Lines.ToArray()[0].Product.ProductID, 1);
        }
开发者ID:Shiloff,项目名称:SportsStore,代码行数:11,代码来源:CartTests.cs

示例13: Can_add_to_cart

        public void Can_add_to_cart()
        {
            var mockRepository = CreateRepositoryMock();

            var controller = new CartController(mockRepository.Object, null);
            var cart = new Cart();

            controller.AddToCart(cart, 1, null);

            Assert.AreEqual(1, cart.Lines.Count());
            Assert.AreEqual(cart.Lines.ElementAt(0).Product.ProductID, 1);
        }
开发者ID:vcaraulean,项目名称:Pro-ASP-NET-MVC-SportsStore,代码行数:12,代码来源:CartControllerTests.cs

示例14: After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen

        public void After_Adding_Product_To_Cart_User_Goes_To_Your_Cart_Screen()
        {
            var mockProductsRepository = UnitTestHelpers.MockProductsRepository(
                new Product { ProductId = 1 }

                );

            var cartController = new CartController(mockProductsRepository, null);
            var result = cartController.AddToCart(new Cart(), 1, "someReturnUrl");

            result.ShouldBeRedirectionTo(new {action = "Index", returnUrl = "someReturnUrl"});
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:12,代码来源:ShoppingCart.cs

示例15: Cannot_Check_Out_If_Shipping_Details_Are_Invalid

        public void Cannot_Check_Out_If_Shipping_Details_Are_Invalid()
        {
            var cart = new Cart();
            cart.AddItem(new Product(), 1);

            var cartController = new CartController(null, null);
            cartController.ModelState.AddModelError("any key", "any error");

            var result = cartController.CheckOut(cart, new ShippingDetails());

            result.ShouldBeDefaultView();
        }
开发者ID:hcabnettek,项目名称:SportsStore,代码行数:12,代码来源:ShoppingCart.cs


注:本文中的SportsStore.WebUI.Controllers.CartController类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。