示例#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");
        }
示例#3
0
        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);
        }