public void CreateTestInvalidStateModel() { // Arrange db = new touch_for_foodEntities(); SideController target = new SideController(); target.ModelState.AddModelError("error", "ModelState is invalid"); SelectList expectedSideList = new SelectList(db.menu_category, "id", "id", side2.menu_category_id); ViewResult actual; // Act actual = (ViewResult)target.Create(side2); // Assert SelectList actualSideList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedSideList.GetType(), actualSideList.GetType()); Assert.AreEqual(expectedSideList.Count(), actualSideList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); SideController target = new SideController(); SelectList expectedMenuCategoryList = new SelectList(db.menu_category, "id", "id"); ViewResult actual; //Act actual = (ViewResult)target.Create(); //Assert SelectList actualSideList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedMenuCategoryList.GetType(), actualSideList.GetType()); Assert.AreEqual(expectedMenuCategoryList.Count(), actualSideList.Count()); }
public void CreateTest() { // Arrange db = new touch_for_foodEntities(); SideController target = new SideController(); int expectedSides = db.sides.ToList<side>().Count() + 1; // Act var actualResult = target.Create(side2) as RedirectToRouteResult; db = new touch_for_foodEntities(); var actualResultURI = actualResult.RouteValues["action"]; int actualSides = db.sides.ToList<side>().Count(); Assert.AreEqual(expectedSides, actualSides); Assert.AreEqual("Index", actualResultURI); }