예제 #1
0
        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
            // Not passed to any processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            // Returning default view
            Assert.AreEqual("", result.ViewName);
            // Passing invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #2
0
        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
            // Not passed to any processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            // Returning default view
            Assert.AreEqual("", result.ViewName);
            // Passing invalid model
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #3
0
        public void Can_Checkout_Andu_Submit_Order()
        {
            //准备-创建一个模仿的订单处理器
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            //准备-创建一个空的购物车
            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);
            //准备-创建一个送货地址实例
            ShippingDetails shippingDetails = new ShippingDetails();
            //准备-创建一个控制器实例
            CartController target = new CartController(null, mock.Object);
            ViewResult     result = target.Checkout(cart, shippingDetails);

            //断言-检查,订单已经传递给处理器
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Once);
            //断言-检查,该方法返回的是"Completed"视图
            Assert.AreEqual("Completed", result.ViewName);
            //断言-检查,我们正在把一个有效的模型传递给视图
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
예제 #4
0
        public void Can_Save_Shipping_Changes()
        {
            // Arrange - create mock repository
            Mock <IOrderProcessor>    moc1 = new Mock <IOrderProcessor>();
            Mock <IProductRepository> moc2 = new Mock <IProductRepository>();
            // Arrange - create the controller
            CartController target = new CartController(moc2.Object, moc1.Object);
            // Arrange - create a
            Shipping shipping = new Shipping {
                Name = "Ship"
            };
            Order order = new Order();
            Cart  cart  = new Cart();
            // Act - try to save the product
            ActionResult adresult = target.Checkout(order, shipping, cart);

            // Assert - check that the repository was called
            moc2.Verify(m => m.SaveShipping(It.IsAny <Shipping>()), Times.Never());
            // Assert - check the method result type
            Assert.IsNotInstanceOfType(adresult, typeof(ActionResult));
        }
예제 #5
0
        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 we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #6
0
        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 orther hasn't bneen passed on to processor
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never());
            //Assert - check the 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);
        }
예제 #7
0
        public void WhenCheckoutAlreadyCheckedoutCartThenExceptionIsReturnedInMessage()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            cartEntry.Info.CheckedOut = true;
            inMemoryCollection.Add(cartEntry);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Checkout(cartEntry.Id);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Error, response.Status);
            Assert.NotNull(response.Exception);
            Assert.Null(response.Body);
        }
예제 #8
0
        public void Can_Checkout_And_Submit_Order()
        {
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);

            CartController target = new CartController(null, mock.Object);
            ViewResult     result = target.Checkout(cart, new ShippingDetails());

            //assert

            //метод ProcessorOrder вызывается
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Once);

            //метод возвращает представление ""Сomplited
            Assert.AreEqual("Completed", result.ViewName);

            //представлению передается допустимая модель
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
예제 #9
0
 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);
 }
        public void CheckoutTest_CannotCheckoutInvalidShippingDetails()
        {
            var mock = new Mock <IOrderProcessor>();
            var cart = new Cart();

            cart.AddItem(new Product(), 1);

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

            //准备--把一个错误添加到模型
            target.ModelState.AddModelError("error", "error");
            //动作--试图结算
            ViewResult result = target.Checkout(cart, new ShippingDetails());

            //断言--检查,订单尚未传递给处理器
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never);
            //断言--检查,该方法返回的默认视图
            Assert.AreEqual("", result.ViewName);
            //断言--检查,对视图传递一个非法模型
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #11
0
        public async Task CheckOut_ModelState_Invalid_Returns_View_with_Model()
        {
            var cart_service_mock  = new Mock <ICartService>();
            var order_service_mock = new Mock <IOrderService>();

            var controller = new CartController(cart_service_mock.Object);

            controller.ModelState.AddModelError("error", "InvalidModel");

            const string expected_model_name = "Test order";
            var          order_view_model    = new OrderViewModel {
                Name = expected_model_name
            };

            var result = await controller.Checkout(order_view_model, order_service_mock.Object);

            var view_result = Assert.IsType <ViewResult>(result);
            var model       = Assert.IsAssignableFrom <CartOrderViewModel>(view_result.Model);

            Assert.Equal(expected_model_name, model.Order.Name);
        }
예제 #12
0
        public void Cannot_Checkout_And_Submit_Order()
        {
            // 准备-创建一个模仿的订单处理器
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();

            // 准备-创建新购物车
            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);

            // 准备-创建控制器
            CartController target = new CartController(null, mock.Object);

            // 动作
            ViewResult result = target.Checkout(cart, new ShippingDetails());

            // 断言-检查,订单尚未传递给处理器
            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);
        }
예제 #13
0
        public void Cannot_Checkout_Empty_Cart()
        {
            //Arrange
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            //Arrange create an Empty Cart
            Cart cart = new Cart();
            //Arrange create a ShippingDetailes
            ShippingDetails shippingDetails = new ShippingDetails();
            //Arrange creating Controller
            CartController controller = new CartController(null, mock.Object);
            //Act
            ViewResult result = controller.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 we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #14
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            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");

            ViewResult result = target.Checkout(cart, new ShippingDetails());

            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()),
                        Times.Never());

            Assert.AreEqual("", result.ViewName);

            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #15
0
        public void Cannot_Checkout_Empty_Cart()
        {
            // Chuẩn bị – tạo một đơn hàng giả
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            // Chuẩn bị – tạo một giỏ hàng trống
            Cart cart = new Cart();
            // Chuẩn bị – tạo các chi tiết vận chuyển
            ShippingDetails shippingDetails = new ShippingDetails();
            // Chuẩn bị – tạo một controller
            CartController target = new CartController(null, mock.Object);
            // Thực hiện
            ViewResult result = target.Checkout(cart, shippingDetails);

            // Xác nhận – kiểm tra đơn hàng không được thông qua vào bộ xử lý
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(),
                                            It.IsAny <ShippingDetails>()), Times.Never());
            // Xác nhận – kiểm tra xem phương thức nào là trở về trang mặc định
            Assert.AreEqual("", result.ViewName);
            // Xác nhận - kiểm tra rằng tôi chuyển một mô hình hợp lệ sang giao  diện hiển thị
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #16
0
파일: CartTests.cs 프로젝트: xuzhg/Moutain
        public void Can_Checkout_And_Submit_Order()
        {
            // Arrange
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();

            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);


            // Arrange
            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);
        }
예제 #17
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            //arrange
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            Cart cart = new Cart();

            cart.AddItem(new Game(), 1);
            CartController controller = new CartController(null, mock.Object);

            controller.ModelState.AddModelError("error", "error");
            //action
            ViewResult result = controller.Checkout(cart, new ShippingDetails());

            //assert - проверка, что заказ не передается обработчику
            mock.Verify(m => m.ProcessorOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()),
                        Times.Never());
            //assert - проверка, что метод вернул стандартное представление
            Assert.AreEqual("", result.ViewName);
            //assert - проверка, чот представлению передана неверная информация Shipping details
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #18
0
        public void Checkout_ModelInvalid_Validationerrors()
        {
            // Arange
            var orderProcessorMock = new Mock <IOrderProcessor>();

            var cartController = new CartController(null, orderProcessorMock.Object);

            cartController.ModelState.AddModelError("error", "error");

            var cart = new Cart();

            cart.AddToCart(new Product(), 1);

            //Act
            var viewResult = cartController.Checkout(cart, null);

            // Assert
            orderProcessorMock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()),
                                      Times.Never);
            Assert.IsFalse(viewResult.ViewData.ModelState.IsValid);
        }
예제 #19
0
        public void WhenCheckoutCartThenCartMarkedInCollectionAndNotRemoved()
        {
            var testContext = new TestContext();

            var inMemoryCollection = new CartsCollection();
            var cartEntry          = new CartsCollection.CartsCollectionEntry(
                new CartInfo(), testContext.CartFactory.Create());

            cartEntry.Cart.Add(testContext.CreateNewSku("A", 100));
            inMemoryCollection.Add(cartEntry);

            var controller = new CartController(null, inMemoryCollection,
                                                testContext.CartFactory, testContext.PriceList, new NeutralPipeline());

            var response = controller.Checkout(cartEntry.Id);

            Assert.NotNull(response);
            Assert.Equal(CartOperationStatus.Successful, response.Status);
            Assert.NotNull(response.Body);
            Assert.True(cartEntry.Info.CheckedOut);
        }
예제 #20
0
        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 checkout
            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 we are passing a valid model to the view
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
예제 #21
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            _cart.AddItem(new Product(), 1);

            //Arrange - create the controller
            CartController target = new CartController(null, _mockOrderProcessor.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 - it does not matter the actual value of Cart or ShippingDetails passed
            _mockOrderProcessor.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 we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #22
0
        public void Cannot_Checkout_Empty()
        {
            // 准备-创建一个模仿的订单处理器
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();

            // 准备-创建新购物车
            Cart cart = new Cart();

            // 准备-创建一个控制器实例
            ShippingDetails shippingDetails = new ShippingDetails();

            // 准备-创建控制器
            CartController target = new CartController(null, mock.Object);

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

            // 断言-检查,订单尚未传递给处理器
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #23
0
        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
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()),
                        Times.Never());

            Assert.AreEqual("", result.ViewName);

            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #24
0
        public void Cannot_Checkout_Empty_Cart()
        {
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();

            Cart cart = new Cart();

            ShippingDetails shippingDetails = new ShippingDetails();

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

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

            //sprawdzenie czy zamowienie zostalo przekazane do procesora
            //czy metoda nie jest nigdy wywołana
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never);

            //ponowne wyświetlenie widoku
            Assert.AreEqual("", result.ViewName);

            //stan modelu jest nieprawidłowy
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #25
0
        public void TestCheckoutWithInvalidShippingDetailsFailure()
        {
            // Arrange
            Mock <IOrderProcessor> mockBuilder = new Mock <IOrderProcessor>();

            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);

            CartController cartController = new CartController(null, mockBuilder.Object);

            cartController.ModelState.AddModelError("error", "error");

            // Act
            ViewResult viewResult = cartController.Checkout(cart, new ShippingDetails());

            mockBuilder.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never);

            // Assert
            Assert.AreEqual("", viewResult.ViewName);
            Assert.AreEqual(false, viewResult.ViewData.ModelState.IsValid);
        }
예제 #26
0
        public void Cannot_Ship_With_Invalid_Details()
        {
            // Arrange
            CartController target = new CartController(mockRepo.Object, mockProc.Object);

            target.ModelState.AddModelError("invalidShippingDetails", "Invalid Shipping Details.");
            Cart    cart = new Cart();
            Product p1   = mockRepo.Object.Products.Where(p => p.ProductId == 1).FirstOrDefault();

            cart.AddToCart(p1);
            ShippingDetails shippingDetails = new ShippingDetails();

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

            // Assert - Order processor has NOT been called
            mockProc.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never);
            // Assert - Model is invalid.
            Assert.IsTrue(result.ViewData.ModelState.IsValid == false);
            // Assert - Default view is returned.
            Assert.IsTrue(result.ViewName == String.Empty);
        }
예제 #27
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();

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

            cart.AddItem(new Product(), 1);

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

            target.ModelState.AddModelError("error", "error");

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

            //Assert - check that the order hasn't bene passed on 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);
        }
예제 #28
0
        public void CheckCannotCheckoutInvalidShippingDetails()
        {
            // arrange
            var mockOrderProcessor = new Mock <IOrderProcessor>();
            var cart = new Cart();

            cart.AddItem(new Product(), 1);
            var shippingDetails = new ShippingDetails();
            var cartController  = new CartController()
            {
                OrderProcessor = mockOrderProcessor.Object
            };

            // act
            cartController.ModelState.AddModelError("error", "error");
            var result = cartController.Checkout(cart, shippingDetails);

            // assert
            mockOrderProcessor.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #29
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            //przygotowanie
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);

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

            //dodanie bledu do modelu
            target.ModelState.AddModelError("error", "error");
            //dzialanie
            ViewResult result = target.Checkout(cart, new ShippingDetails());

            //assercje
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()), Times.Never);
            // spr czy metoda zwraca domyslny widok
            Assert.AreEqual("", result.ViewName);
            // spr czy przekazujemy nieprawidlowy model do widoku
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
        public void CannotCheckoutInvalidOrderTest()
        {
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            Cart cart = new Cart();

            cart.AddItem(new Toy(), 1);

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

            controller.ModelState.AddModelError("error", "error");

            ViewResult result = controller.Checkout(cart, new Order());

            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <Order>()),
                        Times.Never());

            //sprawdzam czy zwraca domyślny widok
            Assert.AreEqual("", result.ViewName);

            //sprawdzam czy przekazujemy prawidłowy model od widoku
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
예제 #31
0
        public void Can_Checkout_And_Submit_Order()
        {
            // przygotowanie - tworzenie imitacji procesora zamówień
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            // przygotowanie - tworzenie koszyka z produktem
            Cart cart = new Cart();

            cart.AddItem(new Product(), 1);
            // przygotowanie - tworzenie egzemplarza kontrolera
            CartController target = new CartController(null, mock.Object);

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

            // asercje - sprawdzenie, czy zamówienie nie zostało przekazane do procesora
            mock.Verify(m => m.ProcessOrder(It.IsAny <Cart>(), It.IsAny <ShippingDetails>()),
                        Times.Once());
            // asercje - sprawdzenie, czy metoda zwraca widok Completed
            Assert.AreEqual("Completed", result.ViewName);
            // asercje - sprawdzenie, czy przekazujemy prawidłowy model do widoku
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
예제 #32
0
        public void Cannot_Checkout_Empty_Cart()
        {
            // przygotowanie - tworzenie imitacji procesora zamówień
            Mock <IOrderProcessor> mock = new Mock <IOrderProcessor>();
            // przygotowanie - tworzenie pustego koszyka
            Cart cart = new Cart();
            // 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 <Cart>(), 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);
        }
예제 #33
0
        public void Can_Checkout_And_Submit_Order()
        {
            // Arrange
            var mock = new Mock <IProductCore>();
            var cart = new Cart();

            cart.AddItem(new Product(), 1);

            CartController target = new CartController(mock.Object);

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

            // Assert
            mock.Verify(m => m.ProcessOrder(cart, It.IsAny <ShippingDetails>()), Times.Once());

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

            // check that we are passing a valid model to the view
            Assert.IsTrue(result.ViewData.ModelState.IsValid);
        }
예제 #34
0
        public void Can_Checkout_And_Submit()
        {
            // 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
            // Passed onto the processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once());
            // Returning completed view
            Assert.AreEqual("Completed", result.ViewName);
            // Passing valid model
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
예제 #35
0
 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);
 }