public override void CommentsAreStillInOrderWhenOneIsAddedLater() { const string FirstCommentName = "Commenter 1"; const string ThirdCommentName = "Commenter 3"; var post = new Post() { Author = "Jason", Title = "Wow", Content = "Yep", Tags = new[] { "Hot" } }; _repository.AddPost(post); WaitForIndexesToBeCurrent(); post.Comments.Add(new Comment { Name = FirstCommentName, Email = "*****@*****.**", Content = "Halla!" }); post.Comments.Add(new Comment { Name = "Commenter 2", Email = "*****@*****.**", Content = "Halla!" }); _repository.UpdatePost(post); WaitForIndexesToBeCurrent(); post = _repository.GetById(post.Id); post.Comments.Add(new Comment { Name = ThirdCommentName, Email = "*****@*****.**", Content = "Halla!" }); _repository.UpdatePost(post); WaitForIndexesToBeCurrent(); var result = _repository.GetById(post.Id); Assert.That(result, Is.Not.Null); Assert.That(result.Comments.Count, Is.EqualTo(3)); Assert.That(result.Comments.First().Name, Is.EqualTo(FirstCommentName)); Assert.That(result.Comments.Last().Name, Is.EqualTo(ThirdCommentName)); }
public void DeletePost(Post post) { var success = RecentPosts.Remove(post); _client.DeleteById(post.Id); if (!success) throw new ArgumentException("Post not found."); }
public void UpdatePost(Post post) { using (var session = _store.OpenSession()) { session.Store(post); session.SaveChanges(); } }
private PostViewModel CreatePostViewModel(Post post) { return new PostViewModel { Post = post, IsTextSelectionEnabled = true, ShowPostPosition = false, ShowReplies = false }; }
public void DeletePost(Post post) { using (var session = _store.OpenSession()) { session.Delete(session.Load<Post>(post.Id)); session.SaveChanges(); } }
public override void CanAddACommentToAnExistingPost() { const string Commenter = "Commenter"; var post = new Post() { Author = "Jason", Title = "Wow", Content = "Yep", Tags = new[] { "Hot" } }; _repository.AddPost(post); post.Comments.Add(new Comment { Name = Commenter, Email = "*****@*****.**", Content = "Halla!" }); _repository.UpdatePost(post); var result = _repository.GetById(post.Id); Assert.That(result, Is.Not.Null); Assert.That(result.Comments.Count, Is.EqualTo(1)); Assert.That(result.Comments.Single().Name, Is.EqualTo(Commenter)); }
public void UpdatePost(Post post) { var retrievedPost = _client.GetById(post.Id); retrievedPost.Comments = post.Comments; retrievedPost.Content = post.Content; retrievedPost.CreatedAt = post.CreatedAt; retrievedPost.Slug = post.Slug; retrievedPost.Tags = post.Tags; retrievedPost.Title = post.Title; _client.Store(retrievedPost); }
public override void CommentsOnAPostAreReturnedInChronologicalOrder() { var post = new Post() { Author = "Jason", Title = "Wow", Content = "Yep", Tags = new[] { "Hot" } }; _repository.AddPost(post); const string FirstCommentName = "Commenter 1"; post.Comments.Add(new Comment { Name = FirstCommentName, Email = "*****@*****.**", Content = "Halla!" }); post.Comments.Add(new Comment { Name = "Commenter 2", Email = "*****@*****.**", Content = "Halla!" }); _repository.UpdatePost(post); var result = _repository.GetById(post.Id); Assert.That(result, Is.Not.Null); Assert.That(result.Comments.Count, Is.EqualTo(2)); Assert.That(result.Comments.First().Name, Is.EqualTo(FirstCommentName)); }
public override void PostHasIdAfterSaving() { var post = new Post() { Author = "Jason", Title = "Wow", Content = "Yep", Tags = new[] { "Hot" } }; _repository.AddPost(post); Assert.That(post.Id, Is.GreaterThan(0)); }
private PostViewModel CreateViewModelForPost(Post post) { var viewModel = new PostViewModel { Post = post, ShowReplies = false, ShowPostPosition = false, IsTextSelectionEnabled = true, ShowActions = true }; SetupEventsForPost(viewModel); return viewModel; }
public void AddPost(Post post) { post.Id = this.GetNextPostId(); _client.Store(post); RecentPosts.Add(post); }
public override void GetRecentPostsReturnsSpecifiedNumberOfPosts() { var oldPost = new Post {CreatedAt = DateTime.Now.AddMinutes(-5)}; var newPost = new Post {CreatedAt = DateTime.Now}; _repository.AddPost(oldPost); _repository.AddPost(newPost); var result = _repository.GetRecentPosts(1).ToArray(); Assert.That(result.Length, Is.EqualTo(1)); }
public override void RecentPostsReturnInCorrectOrder() { var newTitle = "New Post " + Guid.NewGuid().ToString(); var oldTitle = "Old Post " + Guid.NewGuid().ToString(); var oldPost = new Post { CreatedAt = DateTime.Now.AddMinutes(-5), Title = oldTitle }; var newPost = new Post { Title = newTitle }; this._repository.AddPost(oldPost); this._repository.AddPost(newPost); const int PostCount = 2; var result = this._repository.GetRecentPosts(PostCount).ToArray(); Assert.That(result.Length, Is.EqualTo(PostCount)); Assert.That(result.First().Title, Is.EqualTo(newTitle)); Assert.That(result.Last().Title, Is.EqualTo(oldTitle)); }
public override void RecentPostsReturnInCorrectOrder() { const string expected = "New Post"; var oldPost = new Post { CreatedAt = DateTime.Now.AddMinutes(-5), Title = "Old" }; var newPost = new Post { Title = expected }; _repository.AddPost(oldPost); _repository.AddPost(newPost); WaitForIndexesToBeCurrent(); var result = _repository.GetRecentPosts(2).ToArray(); Assert.That(result.First().Title, Is.EqualTo(expected)); }
public ActionResult Create(Post post) { _postRepository.AddPost(post); AddMessage("Post Added!"); return RedirectToAction("View", new {id = post.Id}); }
public override void PostCanBeDeleted() { var post = new Post() { Author = "Jason", Title = "Wow", Content = "Yep", Tags = new[] { "Hot" } }; _repository.AddPost(post); WaitForIndexesToBeCurrent(); _repository.DeletePost(post); WaitForIndexesToBeCurrent(); var result = _repository.GetById(post.Id); Assert.That(result, Is.Null); }
public override void PostCanBeAdded() { var post = new Post() { Author = "Jason", Title = "Wow", Content = "Yep", Tags = new[] { "Hot" } }; this._repository.AddPost(post); }