public ActionResult Create(RawMaterial rawmaterial)
        {
            if (ModelState.IsValid)
            {
                db.RawMaterials.Add(rawmaterial);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(rawmaterial);
        }
        public void RawMaterialsController_Create_isValid()
        {
            RawMaterial testRawMaterials = new RawMaterial();
            testRawMaterials.rawMaterialsName = "testBrand";
            testRawMaterials.rawMaterialsPrice = 1;
            testRawMaterials.rawMaterialsQty = 5;
            RawMaterialsController controller = new RawMaterialsController();

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

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void RawMaterialsController_Create_isNotValid()
        {
            RawMaterial testRawMaterials = new RawMaterial();
            testRawMaterials.rawMaterialsName = "invalidTestBrand";
            RawMaterialsController controller = new RawMaterialsController();
            controller.ModelState.AddModelError("", "error message");

            var result = controller.Create(testRawMaterials) as ViewResult;
            RawMaterial resultRawMaterials = (RawMaterial)result.Model;

            Assert.AreEqual("invalidTestBrand", resultRawMaterials.rawMaterialsName);
        }
 public ActionResult Edit(RawMaterial rawmaterial)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rawmaterial).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(rawmaterial);
 }