public void ContrololerAddTest() { CodeBaseContext repo = new FakeCodeBaseContext(); CategoriesController controller = new CategoriesController { context = repo }; controller.Create(new Category { Title = "C#" , CategoryId=1, Articles=null}); repo.SaveChanges(); Assert.AreEqual("C#", repo.Categories.First().Title); }
public void ContrololerAddShouRedispayIfCategoryInvalid() { CodeBaseContext repo = new FakeCodeBaseContext(); CategoriesController controller = new CategoriesController { context = repo }; controller.ModelState.AddModelError("eror", "model error"); var c = new Category { CategoryId = 1, Title = "1", Articles = null }; var result = controller.Create(); Assert.IsNotNull(result); Assert.IsTrue((result as ViewResult).ViewData.ModelState.Count > 0, "Expected errors"); }
public void ComtrollerEditCategory() { CodeBaseContext repo = new FakeCodeBaseContext(); repo.Categories.Add(new Category { Title = "C#", CategoryId = 1, Articles = null }); repo.SaveChanges(); var category = repo.Categories.First(); category.Title = "C++"; CategoriesController controller = new CategoriesController { context = repo }; controller.Edit(category); Assert.AreEqual("C++", repo.Categories.First().Title); }