Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
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);

            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 5
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());

            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);
        }
Exemplo n.º 6
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);
        }
        public void Cannot_Checkout_empty_cart()
        {
            var mock = new Mock<IOrderProcessor>();
            var cart = new Cart();
            var shipping = new ShippingDetails();

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

            var result = controller.Checkout(cart, shipping);

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

            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 8
0
        public void Cannot_Checkout_Empty_Cart()
        {
            Mock<IOrderProcessor> mockProc = new Mock<IOrderProcessor>();
            Cart cart = new Cart();
            ShippingDetails shippingDetails = new ShippingDetails();
            CartController target = new CartController(null, mockProc.Object);

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

            //Assert - check that the order hasn't been passed on to the processor, means that ProcessorOrder was never invoked
            mockProc.Verify(mock=> mock.ProcessorOrder(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);
        }
Exemplo n.º 9
0
        public void Cannot_Checkout_And_Submit_Order()
        {
            Mock<IOrderProcessor> mockProc = new Mock<IOrderProcessor>();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

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

            //Assert - check that the order hasn't been passed on to the processor, means that ProcessorOrder was never invoked
            mockProc.Verify(mock=> mock.ProcessorOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Once);
            //Assert - check that the method is returning the default 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);
        }
Exemplo n.º 10
0
        public void Cannot_Chechout_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()); //Verify that order is never sent to the processor
            Assert.AreEqual("", result.ViewName); // Check that method is returning same view
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }
        public void Can_checkout_and_submit_order()
        {
            var mock = new Mock<IOrderProcessor>();
            var cart = new Cart();
            cart.AddItem(new Product(), 1);
            var shipping = new ShippingDetails();

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

            var result = controller.Checkout(cart, shipping);

            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);
        }
Exemplo n.º 12
0
        public void Cannot_Checkout_EmptyCart()
        {
            //arrange - Create a mock order process

            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            Cart cart = new Cart();

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

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

            mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.AtLeastOnce());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
        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 on to the processor
            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            Assert.AreEqual(string.Empty, result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 14
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 an valid model to the view
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 15
0
        public void Cannot_Checkout_Imvalid_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);
            // Arrage - add an erro to the model
            target.ModelState.AddModelError("error", "error");

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

            // Assert - check that the model 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);
        }
Exemplo n.º 16
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // Arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

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

            ShippingDetails shippingDetails = new ShippingDetails();

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

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

            // Assert
            mock.Verify(p => p.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
                        Times.Never());
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 17
0
        public void Can_Checkout_And_Submit_OrdeR()
        {
            // Arrange - Mock 주문 처리기를 생성한다.
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // Arrange - 하나의 상품이 담긴 Cart 개체를 생성한다
            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 - 메서드가 Completed 뷰를 반환하는지 확인한다.
            Assert.AreEqual("Completed", result.ViewName);

            // Assert - 유욯한 모델을 뷰에 전달하는지 확인하다.
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // arrange create mock order processor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // arrange create cart
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

            // arrange create the controller
            CartController controller = new CartController(null, mock.Object);

            // arrange create a model and add an error state to it
            controller.ModelState.AddModelError("error", "error");

            // act try to checkout
            var result = controller.Checkout(cart, new ShippingDetails());

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

            // assert - check that the method is returning the defaultview (so the user can correct mistakes and see the errors on screen)
            Assert.AreEqual("", result.ViewName);

            // assert - check that we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 20
0
        public void Can_Checkout_And_Submit_Order()
        {
            // assert create orderprocessor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);
            CartController controller = new CartController(null, mock.Object);
            ViewResult result = controller.Checkout(cart, new ShippingDetails());

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

            // assert - check that the returned view is called Completed
            Assert.AreEqual("Completed", result.ViewName);

            // check that the model state does not have any errors
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 21
0
        public void Can_Checkout_And_Submit_Order()
        {
            // Arrange - set up a mock order processor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);
            CartController target = new CartController(null, mock.Object);

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

            //Assert - check that the process order method has been called once
            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);
        }
Exemplo n.º 22
0
        public void Cannot_Checkout_Empty_Cart()
        {
            // arrange create a mock orderporcessor
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            
            // arrange create cart
            Cart cart = new Cart();

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

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

            // act
            ViewResult result = controller.Checkout(cart, shipping);

            // Assert check that the order has not been passed on to the order 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);

            // check the model state and make sure it is not valid
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 23
0
        public void Cannot_Checkout_Invalid_ShippingDetails()
        {
            // Arragne - Mock 주문 처리기 생성
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            // Arrange - 빈 Cart 개체 생성
            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());

            // 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);
        }
Exemplo n.º 24
0
        public void Can_Checkout_And_Submit_Order()
        {
            // Arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

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

            ShippingDetails shippingDetails = new ShippingDetails();

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

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

            // Assert
            mock.Verify(p => p.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
                        Times.Once());
            Assert.AreEqual("Completed", result.ViewName);
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }