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);
        }
        public void IndexTest()
        {
            CodeBaseContext repo = new FakeCodeBaseContext();

            // Arrange
            var controller = new HomeController();
            controller.context = repo;

            // Act
            var actionResult = controller.Index() as ViewResult;

            Assert.IsTrue(((IndexViewModel)actionResult.Model).Articles.Count() == 0);
            Assert.AreEqual("Index", actionResult.ViewName);
        }
        public void CreatingNewArticleShouldSetUsernameAndDate()
        {
            var repo = new FakeCodeBaseContext();
            repo.Users.Add(new CodeBase.Models.User { Username = "******" });

            MockRepository mock = new MockRepository(MockBehavior.Default);
            var membershipMock = mock.Create<ICodeBaseMembership>();
            membershipMock.Setup(x=>x.LoggedInUser()).Returns("snuderl");

            ArticlesController controller = new ArticlesController{ context=repo, membership=membershipMock.Object};
            //controller.Create(new Article{ CategoryId=1, Content="blabla", Title="mock"});

            Assert.AreEqual(repo.Users.First().UserId, repo.Articles.First().UserId);
            var d = repo.Articles.First().Date;
            var d1 = DateTime.Now;
            Assert.IsTrue(d.Value.Second == d1.Second || d.Value.Second == d1.Second - 1);
        }