Example #1
0
        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)));
        }
        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));
        }
Example #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\""));
        }
Example #4
0
 public IList<Post> ByTag(Tag tag)
 {
     return OrderByDateDescending(session.Query<Post>().Where(p => p.Tags.Any(t => t.UrlName == tag.UrlName))).ToList();
 }