예제 #1
0
        public void Category_Has_Id()
        {
            var category = new Category();

            category.Id = 1;

            Assert.AreEqual(1, category.Id);
        }
예제 #2
0
        public void Category_Can_Have_Posts_Assigned()
        {
            var category = new Category();

            category.Posts.Add(new Post());

            Assert.AreEqual(1, category.Posts.Count());
        }
예제 #3
0
        public void Category_Has_Name()
        {
            var category = new Category();

            category.Name = "Name";

            Assert.AreEqual("Name", category.Name);
        }
예제 #4
0
        public virtual ActionResult AddCategory(Category category)
        {
            var repository = ObjectFactory.GetInstance<IBlogService>();

            repository.Save(category);

            repository.CommitChanges();

            return RedirectToAction("Categories");
        }
예제 #5
0
        public void Category_Post_Should_Have_Have_Category_Assigned()
        {
            var category = new Category();

            var post = new Post();

            category.AddPost(post);

            Assert.AreEqual(1, category.Posts.Count());

            Assert.AreEqual(1, post.Categories.Count());
        }
예제 #6
0
        public void Category_Post_Can_Be_Removed()
        {
            var category = new Category();

            var post = new Post();

            category.AddPost(post);

            Assert.AreEqual(1, category.Posts.Count());

            Assert.AreEqual(1, post.Categories.Count());

            category.RemovePost(post);

            Assert.AreEqual(0, category.Posts.Count());

            Assert.AreEqual(0, post.Categories.Count());
        }
예제 #7
0
파일: Post.cs 프로젝트: gmstr/GMSBlog
 public virtual void AddCategory(Category category)
 {
     Categories.Add(category);
     category.Posts.Add(this);
 }
예제 #8
0
        public void Home_Controller_Has_An_Action_Named_Category_Which_Accepts_An_Id_And_Returns_Posts_In_The_Category()
        {
            DatabaseHelpers.Initialize(true);
            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {
                var category = new Category() { Name = "Test" };

                for (int i = 0; i < 5; i++)
                {
                    var post = DummyLivePost();

                    post.Categories.Add(category);

                    repository.Save(post);
                }

                repository.Save(category);
            }

            var controller = new HomeController();

            var result = controller.Category(1) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(IList<Post>));
            Assert.AreEqual(5, (result.ViewData.Model as IList<Post>).Count);
        }
예제 #9
0
        public void Can_Return_Published_Posts_By_Category_Paged()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var category = new Category() { Name = "Test" };

                for (int i = 0; i < 5; i++)
                {
                    var post = DummyLivePost();

                    post.Categories.Add(category);

                    repository.Save(post);
                }

                for (int i = 0; i < 5; i++)
                {
                    var post = DummyLivePost();

                    post.IsPublished = false;
                    post.Categories.Add(category);

                    repository.Save(post);
                }
                repository.Save(category);
            }
            using (var repository = new NHibernateBlogService())
            {
                Assert.AreEqual(2, repository.GetPublishedPostsByCategoryPaged(1, 2, 1).Count);
            }
        }
예제 #10
0
        public void Can_Save_Many_Categories()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {

                for (int i = 0; i < 10; i++)
                {
                    var category = new Category() { Name = "Test" };

                    repository.Save(category);
                }

            }
        }
예제 #11
0
        public void Can_Load_Many_Saved_Categories_Paged()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                for (int i = 0; i < 10; i++)
                {
                    var category = new Category() { Name = "Test" };

                    repository.Save(category);
                }
                Assert.AreEqual(4, repository.GetCategoriesPaged(4, 1).Count);
            }
        }
예제 #12
0
        public void Can_Load_Saved_Category()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var category = new Category() { Name = "Test" };

                repository.Save(category);

                Assert.AreEqual(1, repository.GetCategories().Count);
            }
        }
예제 #13
0
        public void Can_Get_Posts_By_Category_Id()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var post = DummyLivePost();

                var category = new Category() { Name = "Test" };

                post.Categories.Add(category);

                repository.Save(post);
                repository.Save(category);

                repository.CommitChanges();

                Assert.AreEqual(post, repository.GetPostsByCategory(category.Id).First());
            }
        }
예제 #14
0
 public CategorySummary(Category category)
 {
     Name = category.Name;
     Id = category.Id;
     NoOfPosts = category.PublishedPosts.Count();
 }
예제 #15
0
파일: Post.cs 프로젝트: gmstr/GMSBlog
 public virtual void RemoveCategory(Category category)
 {
     Categories.Remove(category);
     category.Posts.Remove(this);
 }
예제 #16
0
        public void Category_Should_Have_List_Of_Posts()
        {
            var category = new Category();

            var posts = new List<Post>();

            category.Posts = posts;

            Assert.AreEqual(posts, category.Posts);
        }
예제 #17
0
        public void Category_Class_Exists()
        {
            var category = new Category();

            Assert.IsNotNull(category);
        }
예제 #18
0
        public void Can_Get_Categories_By_Id()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var category = new Category() { Name = "Test" };

                repository.Save(category);

                var retreivedCategory = repository.GetCategoryById(category.Id);

                Assert.AreEqual(category, retreivedCategory);
            }
        }
예제 #19
0
        public void Category_Should_Have_Initialised_List_Of_Posts()
        {
            var category = new Category();

            Assert.IsNotNull(category.Posts);
        }
예제 #20
0
        public void Can_Get_Posts_By_Category_Id_Paged_And_It_Works_Correctly()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var category = new Category() { Name = "Test" };

                for (int i = 0; i < 17; i++)
                {
                    var post = DummyLivePost();

                    post.Categories.Add(category);

                    repository.Save(post);
                }

                repository.Save(category);

                repository.CommitChanges();

                Assert.AreEqual(5, repository.GetPostsByCategoryPaged(category.Id, 5, 1).Count);
                Assert.AreEqual(5, repository.GetPostsByCategoryPaged(category.Id, 5, 2).Count);
                Assert.AreEqual(5, repository.GetPostsByCategoryPaged(category.Id, 5, 3).Count);
                Assert.AreEqual(2, repository.GetPostsByCategoryPaged(category.Id, 5, 4).Count);
            }
        }
예제 #21
0
 public void Save(Category category)
 {
     save(category);
 }
예제 #22
0
        public void Can_Load_Many_Saved_Categories_Paged_Results_Correctly()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                for (int i = 0; i < 9; i++)
                {
                    var category = new Category() { Name = String.Format("Test{0}", i) };

                    repository.Save(category);
                }
                Assert.AreEqual(4, repository.GetCategoriesPaged(4, 1).Count);
                Assert.AreEqual(4, repository.GetCategoriesPaged(4, 2).Count);
                Assert.AreEqual(1, repository.GetCategoriesPaged(4, 3).Count);
            }
        }
예제 #23
0
 public void Delete(Category category)
 {
     _session.Delete(category);
 }
예제 #24
0
        public void Can_Persist_Joins()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var post = DummyLivePost();

                var category = new Category() { Name = "Test" };

                post.Categories.Add(category);

                repository.Save(post);
                repository.Save(category);

                Assert.AreEqual(1, repository.GetPosts().Count);
            }

            using (var repository = new NHibernateBlogService())
            {
                Assert.AreEqual(1, repository.GetPosts().Count);
                Assert.AreEqual(1, repository.GetCategories().Count);

                var post = repository.GetPosts().First();
                Assert.AreEqual(1, post.Categories.Count);
            }
        }
예제 #25
0
        public void Categories_ViewData_Retreives_Live_Categories_In_Order_Of_No_Of_Posts_Descending()
        {
            //Arrange
            DatabaseHelpers.Initialize(true);

            ObjectFactory.Initialize(x =>
            {
                x.UseDefaultStructureMapConfigFile = false;
                x.AddRegistry(new GMSBlogRegistry());
            });

            //Act
            using (var repository = new NHibernateBlogService())
            {

                for (int i = 1; i <= 10; i++)
                {
                    var category = new Category() { Name = String.Format("Test {0}", i) };

                    for (int j = 0; j < i; j++)
                    {
                        var post = new Post()
                        {
                            Content = "Test",
                            IsPublished = true,
                            Keywords = "",
                            Title = "Test",
                            Summary = "Test"
                        };

                        post.Categories.Add(category);

                        repository.Save(post);
                    }

                    repository.Save(category);
                }
            }

            BaseBlogController controller = new HomeController() as BaseBlogController;

            //Assert
            Assert.AreEqual(10, (controller.ViewData["Categories"] as IList<CategorySummary>).First().NoOfPosts);
            Assert.AreEqual(1, (controller.ViewData["Categories"] as IList<CategorySummary>).Last().NoOfPosts);
        }
예제 #26
0
        public void Can_Save_Category()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var category = new Category() { Name = "Test" };

                repository.Save(category);
            }
        }
예제 #27
0
        public void HomeController_Has_A_Post_Method_Which_Accepts_An_Id_And_Returns_The_Post_With_That_Id_And_Can_Get_Comments()
        {
            // Arrange
            DatabaseHelpers.Initialize(true);
            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {
                var category = new Category() { Name = "Test Category" };

                for (int i = 0; i < 15; i++)
                {
                    var post = DummyLivePost();

                    post.Categories.Add(category);

                    for (int j = 0; j < 5; j++)
                    {
                        var comment = DummyLiveComment();

                        post.Comments.Add(comment);

                        repository.Save(comment);
                    }

                    repository.Save(post);
                }
                repository.Save(category);
            }
            var controller = new HomeController();

            // Act
            var result = controller.Post(8) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Post));
            var modelPost = (result.ViewData.Model as Post);

            Assert.AreEqual(8, modelPost.Id);
            Assert.AreEqual(5, modelPost.Comments.Count);
        }
예제 #28
0
        public void Can_Save_Post_With_Category_Attached()
        {
            Initialize(true);

            using (var repository = new NHibernateBlogService())
            {
                var category = new Category() { Name = "Test" };

                var post = DummyLivePost();

                post.Categories.Add(category);

                repository.Save(post);
                repository.Save(category);

                Assert.AreEqual(1, repository.GetPosts().Count);
                Assert.AreEqual(1, repository.GetCategories().Count);
            }
        }
예제 #29
0
        public void AdminController_Has_An_Edit_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.EditPost(post, collection) as ViewResult;

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