當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。