Пример #1
0
        public void Cannot_Checkout_Invalid_ShippingDetails() {

            // Arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();
            // Arrange
            Cart cart = new Cart();
            cart.AddItem(new Product(), 1);

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

            // Arrange
            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
            Assert.AreEqual("", result.ViewName);

            // Assert
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        }
Пример #2
0
        public void Can_Checkout_And_Submit_Order() {

            // Arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // Arrange
            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
            Assert.AreEqual("Completed", result.ViewName);

            // Assert
            Assert.AreEqual(true, result.ViewData.ModelState.IsValid);
        }
Пример #3
0
        public void Cannot_Checkout_Empty_Cart() {
            
            // Arrange
            Mock<IOrderProcessor> mock = new Mock<IOrderProcessor>();

            // Arrange
            Cart cart = new Cart();

            // Arrange
            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);
        }