public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here Student temp = new Student(); temp.Name = collection["Name"]; temp.StudentID = collection["StudentID"]; StudentHandler handler = new StudentHandler(); if (handler.Insert(temp) == true) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index")); } } catch { return(View()); } }
public void Insert_MissingData_Throws() { var handler = new StudentHandler(); var student = new API.Student() { FirstNames = "testi oppilas", }; var ex = Assert.Throws(typeof(DbUpdateException), () => handler.Insert(student)); Assert.IsNotNull(ex.InnerException); Assert.AreEqual("SQLite Error 19: 'NOT NULL constraint failed: Students.LastName'.", ex.InnerException.Message); }