public void TestAdminCategoriesCreateThrowsException() { category t = new category(); 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 category.", model.StatusDescription); }
public void TestAdminCategoriesPostEditWithDbUpdateException() { category t = new category() { id = 1, name = "someCat", description = "Some desc", timestamp = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0} }; 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 category.", model.StatusDescription); }
public void TestAdminCategoriesPostEditWithConcurrencyException() { category t = new category() { 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 category as another admin may have already updated this category", model.StatusDescription); }
public void TestAdminCategoriesPostEditCategoriesNotFound() { category t = new category(); 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 category does not exist or has already been deleted", model.StatusDescription); }
public void TestAdminCategoriesPostDeleteWithDbUpdateException() { category t = new category() { id = 1 }; db.Setup(c => c.categories.Find(t.id)).Returns(t); db.Setup(c => c.categories.Remove(t)).Returns(t); db.Setup(c => c.SaveChanges()).Throws(new DbUpdateException()); ViewResult result = adminCon.DeleteConfirmed(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 delete the category as it may be referenced in the database.", model.StatusDescription); }
/// <summary> /// Gets the fake categories /// </summary> /// <returns>A queryable list of fake categories</returns> private List<category> getSeedCategories() { category category1 = new category { id = 1, name = "endurance", description = "Endurance workouts help" }; category category2 = new category { id = 2, name = "strength", description = "Strength workouts build" }; category category3 = new category { id = 3, name = "flexibility", description = "Flexibility workouts stretch" }; var categories = new List<category> { category1, category2, category3 }; return categories; }