當前位置: 首頁>>代碼示例>>C#>>正文


C# CartController.CheckOut方法代碼示例

本文整理匯總了C#中SportsStore.WebUI.Controllers.CartController.CheckOut方法的典型用法代碼示例。如果您正苦於以下問題:C# CartController.CheckOut方法的具體用法?C# CartController.CheckOut怎麽用?C# CartController.CheckOut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SportsStore.WebUI.Controllers.CartController的用法示例。


在下文中一共展示了CartController.CheckOut方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: Cannot_Checkout_Empty_Cart

        public void Cannot_Checkout_Empty_Cart()
        {
            //arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            Cart cart = new Cart();

            ShippingDetails shippingDetails = new ShippingDetails();
            CartController target = new CartController(null, mock.Object);

            // act
            ViewResult result = target.CheckOut(cart, shippingDetails);

            // assert check that the order hasn't been passed to the processor
            mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
開發者ID:joshhoffman,項目名稱:SportsStore,代碼行數:17,代碼來源:CartTests.cs

示例5: Cannot_Checkout_Empty_Cart

        public void Cannot_Checkout_Empty_Cart()
        {
            // przygotowanie - tworzenie imitacji procesora zamówień
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            // przygotowanie - tworzenie pustego koszyka
            CartRepository cart = new CartRepository();
            // przygotowanie - tworzenie danych do wysyłki
            ShippingDetails shippingDetails = new ShippingDetails();
            // przygotowanie - tworzenie egzemplarza kontrolera
            CartController target = new CartController(null, mock.Object);

            // działanie
            ViewResult result = target.CheckOut(cart, shippingDetails);

            // asercje - sprawdzenie, czy zamówienie zostało przekazane do procesora
            mock.Verify(m => m.ProcessOrder(It.IsAny<CartRepository>(), It.IsAny<ShippingDetails>()),
                Times.Never());
            // asercje - sprawdzenie, czy metoda zwraca domyślny widok
            Assert.AreEqual("", result.ViewName);
            // asercje - sprawdzenie, czy przekazujemy prawidłowy model do widoku
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
開發者ID:PawelHaracz,項目名稱:SportsStore,代碼行數:22,代碼來源:CartTests.cs

示例6: Cannot_Checkout_Invalid_Shipping_Data

        public void Cannot_Checkout_Invalid_Shipping_Data()
        {
            // 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 a error to the model
            target.ModelState.AddModelError("error","error");

            // act - try to check out
            ViewResult result = target.CheckOut(cart, new 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

示例7: Can_Checkout_And_Submit_Order

        public void Can_Checkout_And_Submit_Order()
        {
            // 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);

            // act - try to check out
            ViewResult result = target.CheckOut(cart, new ShippingDetails());

            // assert - check that the order has been passed on to the processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once);

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

            // assert - check that i am passing an invalid model to the view
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
開發者ID:pixelsyndicate,項目名稱:Pro_AspNet_MVC_5_book,代碼行數:24,代碼來源:CartTests.cs

示例8: Can_Check_Out_And_Submit_Order

        public void Can_Check_Out_And_Submit_Order()
        {
            var mockOrderSubmitter = new Mock<IOrderSubmitter>();

            var cart = new Cart();
            cart.AddItem(new Product(), 1);
            var shippingDetails = new ShippingDetails();

            var cartController = new CartController(null, mockOrderSubmitter.Object);
            var result = cartController.CheckOut(cart, shippingDetails);

            mockOrderSubmitter.Verify(x => x.SubmitOrder(cart, shippingDetails));

            result.ShouldBeView("Completed");
        }
開發者ID:hcabnettek,項目名稱:SportsStore,代碼行數:15,代碼來源:ShoppingCart.cs

示例9: Cannot_Checkout_Invalid_Shipping_Details

        public void Cannot_Checkout_Invalid_Shipping_Details()
        {
            // arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

            CartController target = new CartController(null, mock.Object);
            target.ModelState.AddModelError("error", "error");

            // act
            ViewResult result = target.CheckOut(cart, new ShippingDetails());

            // assert
            mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            Assert.AreEqual(result.ViewName, "");
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
開發者ID:joshhoffman,項目名稱:SportsStore,代碼行數:18,代碼來源:CartTests.cs

示例10: Can_Checkout_And_Submit_Order

        public void Can_Checkout_And_Submit_Order()
        {
            // arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

            CartController target = new CartController(null, mock.Object);

            // act
            ViewResult result = target.CheckOut(cart, new ShippingDetails());

            //assert
            mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once());
            Assert.AreEqual("Completed", result.ViewName);
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
開發者ID:joshhoffman,項目名稱:SportsStore,代碼行數:17,代碼來源:CartTests.cs

示例11: Cannot_Checkout_Invalid_ShippingDetails

        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // przygotowanie - tworzenie imitacji procesora zamówień
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            // przygotowanie - tworzenie koszyka z produktem
            CartRepository cart = new CartRepository();
            cart.AddItem(new Product(), 1);

            // przygotowanie - tworzenie egzemplarza kontrolera
            CartController target = new CartController(null, mock.Object);
            // przygotowanie - dodanie błędu do modelu
            target.ModelState.AddModelError("error", "error");

            // działanie - próba zakończenia zamówienia
            ViewResult result = target.CheckOut(cart, new ShippingDetails());

            // asercje - sprawdzenie, czy zamówienie zostało przekazane do procesora
            mock.Verify(m => m.ProcessOrder(It.IsAny<CartRepository>(), It.IsAny<ShippingDetails>()),
                Times.Never());
            // asercje - sprawdzenie, czy metoda zwraca domyślny widok
            Assert.AreEqual("", result.ViewName);
            // asercje - sprawdzenie, czy przekazujemy prawidłowy model do widoku
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
開發者ID:PawelHaracz,項目名稱:SportsStore,代碼行數:24,代碼來源:CartTests.cs


注:本文中的SportsStore.WebUI.Controllers.CartController.CheckOut方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。