Beispiel #1
0
        public void AdminController_Has_An_Add_Post_Post_Method_Which_Returns_To_Allow_Updates_On_Invalid_Input()
        {
            DatabaseHelpers.Initialize(true);
            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {
                var controller = new AdminController();

                Assert.AreEqual(0, repository.GetPosts().Count);

                var post = DummyLivePost();

                post.Content = string.Empty;

                var result = controller.AddPost(post, null) as ViewResult;

                Assert.AreEqual(post, result.ViewData.Model as Post);
                Assert.AreEqual("AddPost", result.ViewName);
            }
        }
Beispiel #2
0
        public void AdminController_Has_An_Add_Post_Post_Method_Which_Writes_A_Post_To_Db()
        {
            DatabaseHelpers.Initialize(true);
            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {
                var controller = new AdminController();

                Assert.AreEqual(0, repository.GetPosts().Count);

                var post = DummyLivePost();

                controller.AddPost(post, null);

                Assert.AreEqual(1, repository.GetPosts().Count);
            }
        }
Beispiel #3
0
        public void AdminController_Has_An_Add_Post_Post_Method_Which_Redirects_To_Posts_On_Success()
        {
            DatabaseHelpers.Initialize(true);
            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {
                var controller = new AdminController();

                Assert.AreEqual(0, repository.GetPosts().Count);

                var result = controller.AddPost(DummyLivePost(), null) as RedirectToRouteResult;

                Assert.AreEqual("Posts", result.RouteValues["action"]);
            }
        }
Beispiel #4
0
        public void AdminController_Has_An_Add_Post_Post_Method_Which_Accepts_A_Post()
        {
            var controller = new AdminController();

            var result = controller.AddPost(DummyLivePost(), null);

            Assert.IsNotNull(result);
        }
Beispiel #5
0
        public void AdminController_Has_An_Add_Post_Post_Method_Accepting_A_Post_Object_And_Can_Assign_Categories()
        {
            DatabaseHelpers.Initialize(true);

            var post = new Post();

            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {

                post = DummyLivePost();

                repository.Save(post);

                var category1 = new Category() { Name = "Cat1" };
                repository.Save(category1);
                var category2 = new Category() { Name = "Cat2" };
                repository.Save(category2);
                var category3 = new Category() { Name = "Cat3" };
                repository.Save(category3);

                repository.CommitChanges();

                Assert.AreEqual(0, post.Categories.Count);
            }

            var controller = new AdminController();

            var collection = new FormCollection();

            collection.Add("Category-1", "false");
            collection.Add("Category-2", "true false");
            collection.Add("Category-3", "true false");

            var result = controller.AddPost(post, collection) as ViewResult;

            Assert.AreEqual(2, post.Categories.Count);
        }
Beispiel #6
0
        public void AdminController_Has_An_Add_Post_Get_Method_Which_Has_A_Post_Model()
        {
            var controller = new AdminController();

            var result = controller.AddPost() as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Post));
        }
Beispiel #7
0
        public void AdminController_Has_An_Add_Post_Get_Method()
        {
            var controller = new AdminController();

            var result = controller.AddPost();

            Assert.IsNotNull(result);
        }