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);
        }
        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);
        }
        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();
        }
Exemple #4
0
        public void Cannot_Check_Out_If_Shipping_Details_Are_Invalid()
        {
            // Arrange: Given a user has a non-empty cart
            var cart = new Cart();
            cart.AddItem(new Product(), 1);

            // Arrange: ... but the shipping details are invalid
            var cartController = new CartController(null, null);
            cartController.ModelState.AddModelError("any key", "any error");

            // Act: When the user tries to check out
            var result = cartController.CheckOut(cart, new ShippingDetails());

            // Assert:
            result.ShouldBeDefaultView();
        }
Exemple #5
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 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);
        }
Exemple #6
0
        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);
        }
        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);
        }
        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);
        }
        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");
        }
Exemple #10
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
            mock.Verify(m=>m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()), Times.Never());
            Assert.AreEqual(result.ViewName, "");
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        public void Can_Check_Out_And_Submit_Order()
        {
            var mockOrderSubmitter = new Mock<IOrderSubmitter>();

            // Arrange: Given a user has a non-empty cart & no validation errors
            var cart = new Cart();
            cart.AddItem(new Product(), 1);
            var shippingDetails = new ShippingDetails();

            // Act: When the user tries to check out
            var cartController = new CartController(null, mockOrderSubmitter.Object);
            var result = cartController.CheckOut(cart, shippingDetails);

            // Assert: Order goes to the order submitter & user sees "Completed" view
            mockOrderSubmitter.Verify(x => x.SubmitOrder(cart, shippingDetails));
            result.ShouldBeView("Completed");
        }