Пример #1
0
        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);
        }
Пример #2
0
        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");
        }