public void TestAdminTypesCreateThrowsException() { type t = new type(); db.Setup(c => c.SaveChanges()).Throws(new Exception()); ViewResult result = adminCon.Create(t) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("Failed to create the type. Please try again.", model.StatusDescription); }
public void TestAdminCreateType() { type type = new type(); type.id = 2; type.name = "TEST_DLJ"; type.measure = "TEST_DLJ"; //type.timestamp = DateTime.Now; db.Setup(c => c.types.Add(type)).Returns(type); RedirectToRouteResult result = adminCon.Create(type) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual("Index", result.RouteValues["action"], "redirect was not to Index"); }
private List<type> getSeedTypes() { type type1 = new type { id = 1, measure = "measure", name = "type1", timestamp = new byte[] {0, 0, 0, 0, 0, 0, 0, 0} }; var types = new List<type> { type1 }; return types; }
public void TestAdminTypesPostEditWithDbUpdateException() { type t = new type() { id = 1, name = "xfs", measure = "measure" }; db.Setup(c => c.SaveChanges()).Throws(new DbUpdateException()); ViewResult result = adminCon.Edit(t) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("Failed to edit type.", model.StatusDescription); }
public void TestAdminTypesPostEditWithConcurrencyException() { type t = new type() { id = 1 }; db.Setup(c => c.SaveChanges()).Throws(new DbUpdateConcurrencyException()); ViewResult result = adminCon.Edit(t) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("Failed to edit type as another admin may have already updated this type", model.StatusDescription); }
public void TestAdminTypesPostEditTypeNotFound() { type t = new type(); ViewResult result = adminCon.Edit(t) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("The type does not exist or has already been deleted", model.StatusDescription); }