public ActionResult Create(PurchaseOrder purchaseorder)
        {
            if (ModelState.IsValid)
            {
                db.PurchaseOrders.Add(purchaseorder);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.supplierID = new SelectList(db.Suppliers, "supplierID", "supplierName", purchaseorder.supplierID);
            return View(purchaseorder);
        }
        public void PurchaseOrdersController_Create_isNotValid()
        {
            PurchaseOrder testPurchaseOrder = new PurchaseOrder();
            testPurchaseOrder.purchaseOrderNo = "invalid";
            PurchaseOrdersController controller = new PurchaseOrdersController();
            controller.ModelState.AddModelError("", "error message");

            var result = controller.Create(testPurchaseOrder) as ViewResult;
            PurchaseOrder resultPurchaseOrders = (PurchaseOrder)result.Model;

            Assert.AreEqual("invalid", resultPurchaseOrders.purchaseOrderNo);
        }
        public void PurchaseOrdersController_Create_isValid()
        {
            PurchaseOrder testPurchaseOrder = new PurchaseOrder();
            testPurchaseOrder.purchaseOrderNo = "9999999";
            testPurchaseOrder.purchaseOrderDate = DateTime.Now;
            testPurchaseOrder.deliveryAddress = "123 test street";

            PurchaseOrdersController controller = new PurchaseOrdersController();

            var result = (RedirectToRouteResult)controller.Create(testPurchaseOrder);

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
 public ActionResult Edit(PurchaseOrder purchaseorder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(purchaseorder).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.supplierID = new SelectList(db.Suppliers, "supplierID", "supplierName", purchaseorder.supplierID);
     return View(purchaseorder);
 }