コード例 #1
0
ファイル: PostController.cs プロジェクト: robbell/scribble
        public ViewResult ByTag(Tag tag)
        {
            var posts = repository.ByTag(tag);

            // ToDo: Update this hacky way to load tag full name
            var tagName = posts.First().Tags.First(t => t.UrlName == tag.UrlName).Name;

            return View(MapEntitiesToSummaries(posts, string.Format("Posts tagged with \"{0}\"", tagName)));
        }
コード例 #2
0
        public void ByTagReturnsAllPostsContainingTag()
        {
            const string expectedTitle = "Expected";
            var expectedTag = new Tag { UrlName = "Expected Tag" };
            var otherTag = new Tag { UrlName = "Other Tag" };

            var session = WithSessionContainingPosts(
                new Post { Title = expectedTitle, Tags = new List<Tag> { expectedTag, otherTag } },
                new Post { Title = expectedTitle, Tags = new List<Tag> { expectedTag } },
                new Post { Title = "Not Expected", Tags = new List<Tag> { otherTag } },
                new Post { Title = "Not Expected" });

            var repository = new PostRepository(session);

            var result = repository.ByTag(expectedTag);

            Assert.That(result.All(p => p.Title == expectedTitle));
        }
コード例 #3
0
        public void ByTagGetsPostsWithTagFromRepository()
        {
            var requestTag = new Tag { UrlName = "TagUrlName" };

            Mock.Get(repository)
                .Setup(r => r.ByTag(It.IsAny<Tag>()))
                .Returns(sampleEntities);

            var result = controller.ByTag(requestTag).Model as PostListViewModel;

            Mock.Get(repository).Verify(r => r.ByTag(requestTag));

            Assert.IsNotNull(result);
            Assert.That(result.Posts, Is.EqualTo(sampleSummaries));
            Assert.That(result.Title, Is.EqualTo("Posts tagged with \"TagFullName\""));
        }
コード例 #4
0
ファイル: PostRepository.cs プロジェクト: robbell/scribble
 public IList<Post> ByTag(Tag tag)
 {
     return OrderByDateDescending(session.Query<Post>().Where(p => p.Tags.Any(t => t.UrlName == tag.UrlName))).ToList();
 }