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); }
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); }
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); }
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()); }
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()); }
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))); }
public void Post_Can_Have_Categories_Assigned() { var post = new Post(); post.Categories.Add(new Category()); Assert.AreEqual(1, post.Categories.Count()); }
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); }
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); }
public void Comment_Has_Post_Associated_With_It() { var comment = new Comment(); var post = new Post(); post.AddComment(comment); Assert.AreEqual(post, comment.Post); }
public void Post_Contains_Content() { var post = new Post(); post.Content = "New Post Detail"; Assert.AreEqual("New Post Detail", post.Content); }
public void Post_Implements_IValidated() { var post = new Post(); IValidated test = post as IValidated; Assert.IsNotNull(test); }
public virtual ActionResult AddPost(Post post, FormCollection collection) { return processPost(post, collection); }
public void Post_Contains_Title() { var post = new Post(); post.Title = "Test"; Assert.AreEqual("Test", post.Title); }
public void Post_Has_Id() { var post = new Post(); post.Id = 1; Assert.AreEqual(1, post.Id); }
public void Post_Contains_Summary() { var post = new Post(); post.Summary = "Summary"; Assert.AreEqual("Summary", post.Summary); }
public void Post_Contains_Keywords() { var post = new Post(); post.Keywords = "Test"; Assert.AreEqual("Test", post.Keywords); }
public void Post_Contains_DateUpdated() { var post = new Post(); Assert.IsNotNull(post.DateUpdated); }
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); } }
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); } } }
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); }
public void Post_Class_Exists() { var post = new Post(); Assert.IsNotNull(post); }
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; }
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); }
private ActionResult postView(Post post) { if (post != null) { return View("Post", post); } else { return RedirectToAction(Actions.Index()); } }
public void Post_Should_Have_Initialised_List_Of_Categories() { var post = new Post(); Assert.IsNotNull(post.Categories); }
public virtual void RemovePost(Post post) { Posts.Remove(post); post.Categories.Remove(this); }
public void Post_Should_Have_Initialised_List_Of_Comments() { var post = new Post(); Assert.IsNotNull(post.Comments); }