Пример #1
0
        public void AddCommentSavesCommentToPostRepositoryAndRedirects()
        {
            var postUrl = new PostUrlViewModel { Year = 2013, Month = 4, UrlTitle = "a-test" };
            var returnedPost = new Post();

            Mock.Get(repository).Setup(r => r.SinglePost(postUrl.Url)).Returns(returnedPost);

            var model = new PostViewModel
            {
                CommenterName = "George",
                CommenterEmail = "*****@*****.**",
                CommenterWebsite = "vandelay.com",
                Comment = "A comment"
            };

            var result = controller.AddComment(postUrl, model) as RedirectToRouteResult;

            Assert.That(returnedPost.Comments,
                Has.Exactly(1).Matches<Comment>(c => c.Text == model.Comment
                                                     && c.Name == model.CommenterName
                                                     && c.Email == model.CommenterEmail
                                                     && c.Website == model.CommenterWebsite));
            Assert.NotNull(result);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Single"));
            Mock.Get(repository).Verify(r => r.Save(returnedPost));
        }
Пример #2
0
        public void CreateSavesValidPostToRepository()
        {
            var model = new CreatePostViewModel();
            var entity = new Post();

            Mock.Get(mapper).Setup(m => m.Map<Post>(It.IsAny<CreatePostViewModel>())).Returns(entity);

            var response = (RedirectToRouteResult)controller.Create(model);

            Mock.Get(mapper).Verify(m => m.Map<Post>(model));
            Mock.Get(repository).Verify(r => r.Save(entity));
            Assert.That(response.RouteValues["action"], Is.EqualTo("Create"));
        }
Пример #3
0
        public void RecentReturnsAllPostsOrderedByDateDescending()
        {
            var newestPost = new Post { Date = new DateTime(2012, 06, 01) };
            var secondNewestPost = new Post { Date = new DateTime(2012, 03, 01) };
            var thirdNewestPost = new Post { Date = new DateTime(2011, 06, 01) };

            var repository = new PostRepository(WithSessionContainingPosts(secondNewestPost, thirdNewestPost, newestPost));

            var recentPosts = repository.Recent();

            Assert.That(recentPosts.Count, Is.EqualTo(3));
            Assert.That(recentPosts[0], Is.EqualTo(newestPost));
            Assert.That(recentPosts[1], Is.EqualTo(secondNewestPost));
            Assert.That(recentPosts[2], Is.EqualTo(thirdNewestPost));
        }
Пример #4
0
        public void ReturnsCorrectSinglePostFromRavenDb()
        {
            const string url = "a-post-url";
            var expectedPost = new Post
                {
                    Url = url,
                };

            var session = WithSessionContainingPosts(new Post { Url = "not-the-correct-post" },
                                                     expectedPost,
                                                     new Post { Url = "also-not-the-correct-post" });

            var repository = new PostRepository(session);

            var post = repository.SinglePost(url);

            Assert.That(post, Is.EqualTo(expectedPost));
        }
Пример #5
0
 public void UrlTitleIsLastSectionOfUrl()
 {
     var post = new Post { Url = "2012/03/expected-title" };
     Assert.That(post.UrlTitle, Is.EqualTo("expected-title"));
 }
Пример #6
0
 public void EmptyUrlReturnsEmptyUrlTitle()
 {
     var post = new Post { Url = string.Empty };
     Assert.That(post.UrlTitle, Is.Empty);
 }
Пример #7
0
        public void SavePersistsPost()
        {
            const string expectedUrl = "1984/07/some-post";
            var post = new Post { Url = expectedUrl };

            var session = WithEmptySession();
            var repository = new PostRepository(session);

            repository.Save(post);

            Assert.That(session.Query<Post>().Count(p => p.Url == expectedUrl), Is.EqualTo(1));
        }
Пример #8
0
        public void GetReturnsCorrectPostFromRepository()
        {
            var postUrl = new PostUrlViewModel { Year = 2013, Month = 4, UrlTitle = "a-test" };
            var post = new Post();
            var expectedModel = new PostViewModel();

            Mock.Get(repository)
                .Setup(r => r.SinglePost(It.IsAny<string>()))
                .Returns(post);

            Mock.Get(mapper)
                .Setup(m => m.Map<PostViewModel>(post))
                .Returns(expectedModel);

            var result = (ViewResult)controller.Single(postUrl);
            var model = (PostViewModel)result.Model;

            Mock.Get(repository).Verify(r => r.SinglePost(postUrl.Url));
            Assert.That(model, Is.EqualTo(expectedModel));
        }
Пример #9
0
 public void Save(Post post)
 {
     session.Store(post);
     session.SaveChanges();
 }