Exemple #1
0
        public void DateUpdated_Should_Be_Equal_To_Date_Created_For_A_New_Post()
        {
            var post = new Post();

            Thread.Sleep(1);

            Assert.AreEqual(post.DateCreated, post.DateUpdated);
        }
Exemple #2
0
        public void DateUpdated_Should_Change_If_Title_Is_Modified_Later()
        {
            var post = new Post();

            Thread.Sleep(1);

            post.Title = "New Title";

            Assert.AreNotEqual(post.DateCreated, post.DateUpdated);
        }
Exemple #3
0
        public void Can_Add_Comments_To_Post()
        {
            var post = new Post();

            var comment = new Comment();

            post.AddComment(comment);

            Assert.AreEqual(comment.Post, post);

            Assert.AreEqual(post.Comments.Count, 1);
        }
Exemple #4
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());
        }
Exemple #5
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());
        }
Exemple #6
0
        public void DateUpdated_Should_Be_Set_On_Construction()
        {
            var post = new Post();

            Assert.IsTrue(post.DateUpdated > DateTime.Now.AddSeconds(-2), String.Format("DateCreated: {0}, Actual (less 2 seconds): {1}", post.DateUpdated, DateTime.Now.AddSeconds(-2)));
        }
Exemple #7
0
        public void Post_Can_Have_Categories_Assigned()
        {
            var post = new Post();

            post.Categories.Add(new Category());

            Assert.AreEqual(1, post.Categories.Count());
        }
Exemple #8
0
        public void Post_Should_Have_List_Of_Categories()
        {
            var post = new Post();

            var categories = new List<Category>();

            post.Categories = categories;

            Assert.AreEqual(categories, post.Categories);
        }
Exemple #9
0
        public void Post_Should_Have_List_Of_Comments()
        {
            var post = new Post();

            var comments = new List<Comment>();

            post.Comments = comments;

            Assert.AreEqual(comments, post.Comments);
        }
Exemple #10
0
        public void Comment_Has_Post_Associated_With_It()
        {
            var comment = new Comment();

            var post = new Post();

            post.AddComment(comment);

            Assert.AreEqual(post, comment.Post);
        }
Exemple #11
0
        public void Post_Contains_Content()
        {
            var post = new Post();

            post.Content = "New Post Detail";

            Assert.AreEqual("New Post Detail", post.Content);
        }
Exemple #12
0
        public void Post_Implements_IValidated()
        {
            var post = new Post();

            IValidated test = post as IValidated;

            Assert.IsNotNull(test);
        }
Exemple #13
0
 public virtual ActionResult AddPost(Post post, FormCollection collection)
 {
     return processPost(post, collection);
 }
Exemple #14
0
        public void Post_Contains_Title()
        {
            var post = new Post();

            post.Title = "Test";

            Assert.AreEqual("Test", post.Title);
        }
Exemple #15
0
        public void Post_Has_Id()
        {
            var post = new Post();

            post.Id = 1;

            Assert.AreEqual(1, post.Id);
        }
Exemple #16
0
        public void Post_Contains_Summary()
        {
            var post = new Post();

            post.Summary = "Summary";

            Assert.AreEqual("Summary", post.Summary);
        }
Exemple #17
0
        public void Post_Contains_Keywords()
        {
            var post = new Post();

            post.Keywords = "Test";

            Assert.AreEqual("Test", post.Keywords);
        }
Exemple #18
0
        public void Post_Contains_DateUpdated()
        {
            var post = new Post();

            Assert.IsNotNull(post.DateUpdated);
        }
Exemple #19
0
        public void DateUpdated_Should_Not_Change_If_Post_Is_Published()
        {
            var post = new Post();

            Thread.Sleep(1);

            post.IsPublished = true;

            Assert.AreEqual(post.DateCreated, post.DateUpdated);
        }
        public void Will_Fail_Saving_An_Invalid_Post()
        {
            Initialize(true);

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

                Assert.IsFalse(post.IsValid);

                repository.Save(post);
            }
        }
Exemple #21
0
        private ActionResult processPost(Post post, FormCollection collection)
        {
            using (var repository = ObjectFactory.GetInstance<IBlogService>())
            {
                try
                {
                    var categories = repository.GetCategories();

                    foreach (var category in categories)
                    {
                        if (collection[String.Format("Category-{0}", category.Id)].Contains("true"))
                        {
                            if (!post.Categories.Select(x => x.Id).Contains(category.Id))
                            {
                                post.Categories.Add(category);
                            }
                        }
                        else
                        {
                            if (post.Categories.Select(x => x.Id).Contains(category.Id))
                            {
                                post.Categories.Remove(category);
                            }
                        }
                    }

                    repository.Save(post);

                    repository.CommitChanges();

                    return RedirectToAction(Actions.Posts());
                }
                catch (InvalidOperationException exception)
                {
                    ModelState.AddRuleViolations(post.RuleViolations);

                    return View("AddPost", post);
                }
            }
        }
Exemple #22
0
 public virtual void AddPost(Post post)
 {
     Posts.Add(post);
     post.Categories.Add(this);
 }
        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);
        }
Exemple #24
0
        public void Post_Class_Exists()
        {
            var post = new Post();

            Assert.IsNotNull(post);
        }
Exemple #25
0
 public virtual void SetPost(Post post)
 {
     if (post != null)
     {
         if (!post.Comments.Contains(this))
         {
             post.Comments.Add(this);
         }
     }
     else { _post.Comments.Remove(this); }
     _post = post;
 }
Exemple #26
0
        public void Post_Comments_Can_Be_Removed()
        {
            var post = new Post();

            var comment = new Comment() { Name = "test", Content = "test" };

            post.AddComment(comment);

            Assert.AreEqual(1, post.Comments.Count);
            Assert.AreEqual(post, comment.Post);

            post.RemoveComment(comment);

            Assert.AreEqual(0, post.Comments.Count);
            Assert.AreEqual(null, comment.Post);
        }
Exemple #27
0
 private ActionResult postView(Post post)
 {
     if (post != null)
     {
         return View("Post", post);
     }
     else
     {
         return RedirectToAction(Actions.Index());
     }
 }
Exemple #28
0
        public void Post_Should_Have_Initialised_List_Of_Categories()
        {
            var post = new Post();

            Assert.IsNotNull(post.Categories);
        }
Exemple #29
0
 public virtual void RemovePost(Post post)
 {
     Posts.Remove(post);
     post.Categories.Remove(this);
 }
Exemple #30
0
        public void Post_Should_Have_Initialised_List_Of_Comments()
        {
            var post = new Post();

            Assert.IsNotNull(post.Comments);
        }