public void Order_Fails_When_Price_Too_High()
        {
            // Arrange
            ICreditCardService service = new TestCreditCardService();
            OrderController controller = new OrderController(service);

            // Act
            Order order = new Order { CreditCard = "00000000000000000000", Price = 5000 };
            ActionResult result = controller.Create(order) as ViewResult;

            // Assert
            ViewResult viewResult = (ViewResult)result;
            Assert.AreEqual(order, viewResult.ViewData.Model);
        }
        public void Can_Order_With_Valid_Credit_Info()
        {
            // Arrange
            ICreditCardService service = new TestCreditCardService();
            OrderController controller = new OrderController(service);

            // Act
            Order order = new Order { CreditCard = "4111111111111111", Price = 50 };
            ActionResult result = controller.Create(order) as ActionResult;

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectResult = (RedirectToRouteResult)result;
            Assert.AreEqual("OrderComplete", redirectResult.RouteValues["action"]);
        }
        public ActionResult Create(Order order)
        {
            try
            {
                bool result = service.ChargeCreditCart(order.CreditCard, order.Price);

                if (result == false)
                {
                    ModelState.AddModelError("CreditCard", "Invalid Credit Card");
                    return View(order);
                }

                return RedirectToAction("OrderComplete");
            }
            catch
            {
                return View(order);
            }
        }
 //
 // GET: /Order/Create
 public ActionResult Create()
 {
     var order = new Order { ProductName = "Darth Vader mask", Price = 20.00m };
     return View(order);
 }