public void CreateModelInvalid() { var controller = new ItemCategoriesController(new CategoryBLL(new CategoryServiceStub())); var forventet = new ItemCategory(); controller.ViewData.ModelState.AddModelError("CategoryName", ""); var actionResult = (ViewResult)controller.Create(forventet); Assert.AreEqual(actionResult.ViewName, ""); }
public void CreateModelOK() { var controller = new ItemCategoriesController(new CategoryBLL(new CategoryServiceStub())); var forventet = new ItemCategory { CategoryId = 1, CategoryName = "TestCategory" }; var actionResult = (RedirectToRouteResult)controller.Create(forventet); Assert.AreEqual(actionResult.RouteName, ""); Assert.IsTrue(actionResult.RouteValues.Values.Count == 1); Assert.AreEqual(actionResult.RouteValues.Values.First(), "Index"); }
public void ItemCategoryList() { var controller = new ItemCategoriesController(new CategoryBLL(new CategoryServiceStub())); List<ItemCategory> forventetListe = new List<ItemCategory>(); var ItemCat = new ItemCategory { CategoryId = 1, CategoryName = "TestCategory" }; forventetListe.Add(ItemCat); forventetListe.Add(ItemCat); forventetListe.Add(ItemCat); var actionResultat = (ViewResult)controller.Index(); var resultat = (List<ItemCategory>)actionResultat.Model; Assert.AreEqual(actionResultat.ViewName, ""); for(var i = 0; i < resultat.Count; i++) { Assert.AreEqual(forventetListe[i].CategoryId, resultat[i].CategoryId); Assert.AreEqual(forventetListe[i].CategoryName, resultat[i].CategoryName); } }
public void getCategoryNameList() { var controller = new ItemCategoriesController(new CategoryBLL(new CategoryServiceStub())); List<ItemCategory> forventetListe = new List<ItemCategory>(); var ItemCat = new ItemCategory { CategoryId = 1, CategoryName = "TestCategory" }; forventetListe.Add(ItemCat); forventetListe.Add(ItemCat); forventetListe.Add(ItemCat); var actionResult = controller.getCategoryNameList(); dynamic data = actionResult.Data; for(var i = 0; i < forventetListe.Count; i++) { Assert.AreEqual(forventetListe[i].CategoryId, data[i].CategoryId); Assert.AreEqual(forventetListe[i].CategoryName, data[i].CategoryName); } }