public void Can_Filter_BlogPosts_By_Tag()
 {
     // Arrange: Given a series of blogposts with tags associated, a repository and a blog controller
     var tag = new Tag {TagID = 1, Name = "tag 1"};
     var tag2 = new Tag {TagID = 2, Name = "tag 2"};
     var blogPost = new BlogPost {ContentID = 1};
     var blogPost2 = new BlogPost() {ContentID = 2};
     var blogPost3 = new BlogPost() {ContentID = 3};
     blogPost.Tags.Add(tag);
     blogPost2.Tags.Add(tag2);
     blogPost3.Tags.Add(tag);
     blogPost3.Tags.Add(tag2);
     // mock blog post repository
     var moqBlogPostRepository = UnitTestHelpers.MockBlogPostRepositoryReturnsMoqObject(blogPost, blogPost2, blogPost3);
     moqBlogPostRepository.
         Setup(x => x.GetQueryableBlogPostByTagName(tag.Name)).             // when a user wants to filter by tag
         Returns((new List<BlogPost> {blogPost, blogPost3}).AsQueryable()); // They will obtain the filtered blogposts
     var controller = new BlogController(moqBlogPostRepository.Object);
     // Act: when the user clicks on a tag
     var result = controller.Tag("tag-1");
     // Assert: the result will be a view with a list of blogposts filtered by tag
     var model = ((BlogPostViewModel) result.ViewData.Model).BlogPostPagedList;
     model.Count.ShouldEqual(2);
     model.Single(x => x.ContentID == 1).ContentID.ShouldEqual(1);
     model.Single(x => x.ContentID == 3).ContentID.ShouldEqual(3);
     Assert.IsNull(model.FirstOrDefault(x => x.ContentID == 2));
 }
Example #2
0
 public void GivenASeriesOfTags()
 {
     Tag1 = new Tag {Name = "tag 1", TagID = 1};
     Tag2 = new Tag {Name = "tag 2", TagID = 2};
     Tag3 = new Tag {Name = "tag 3", TagID = 3};
     Tag4 = new Tag {Name = "tag 4", TagID = 4};
     Post1 = new BlogPost {ContentID = 1};
     Post2 = new BlogPost {ContentID = 2};
     Tag1.ContentContainers.Add(Post1);
     Tag1.ContentContainers.Add(Post2);
     Tag2.ContentContainers.Add(Post1);
 }
Example #3
0
        /// <summary>
        /// obtains the tag detail
        /// </summary>
        /// <param name="id">identifier of tag</param>
        /// <returns>returns the result to action</returns>
        public ActionResult Detail(int?id)
        {
            TagRepository objtag = new TagRepository(SessionCustom);

            Domain.Entities.Tag tag = null;

            if (id != null)
            {
                objtag.Entity.TagId = id;
                objtag.Load();
                tag        = objtag.Entity;
                ViewBag.id = id;
            }

            return(this.View(new Tags()
            {
                UserPrincipal = CustomUser,
                Module = this.Module,
                TagCustom = tag,
                ColModul = CustomMemberShipProvider.GetModuls(CustomUser.UserId, SessionCustom, HttpContext),
                CurrentLanguage = CurrentLanguage
            }));
        }
 /// <summary>
 /// Manages the tags from the list of tags, Extracts the tags from the comma separated list of tags
 /// and obtains the equivalent Tag object, either from the database, or it creates a new one
 /// </summary>
 /// <param name="listOfTags"></param>
 /// <returns></returns>
 private IEnumerable<Tag> ManageTagsFromListOfTags(IEnumerable<string> listOfTags)
 {
     List<Tag> tags = new List<Tag>();
     foreach (string tagString in listOfTags)
     {
         // looks in the database to see if the tag already exists
         Tag tag = _context.Tags.FirstOrDefault(x => x.Name == tagString);
         // if it doesn't it creates a new tag
         if (tag == null)
         {
             tag = new Tag { Name = tagString };
             _context.Tags.AddObject(tag);
         }
         tags.Add(tag);
     }
     return tags;
 }
 /// <summary>
 /// Adds a tag to the context
 /// </summary>
 /// <param name="tag"></param>
 public void AddTag(Tag tag)
 {
     GetUnitOfWork.Tags.AddObject(tag);
 }
Example #6
0
 public static MvcHtmlString TagLink(this HtmlHelper helper, Tag tag)
 {
     return helper.ActionLink(tag.Name, "Tag", "Post", new { tagSlug = tag.UrlSlug },
         new { title = String.Format("See all posts in {0}", tag.Name) });
 }
Example #7
0
 public ActionResult Tags(Tag tag)
 {
     if (ModelState.IsValid)
     {
         // add to context
         BlogPostRepo.AddTag(tag);
         // submit changes
         // BlogPostRepo.SubmitChanges();
         // redirect to category management index
         TempData[vinCMS.Infraestructure.Constants.VIEW_MESSAGE] = SUCCESS_TAG_ADD;
         return RedirectToAction("tags");
     }
     else
     {
         // return the same view
         var tagViewModel = new AdminTagViewModel
         {
             NewTag = tag,
             PagedListTags = new PagedList.StaticPagedList<Tag>(
                 BlogPostRepo.GetQueryableOrderedTags().Skip(0).Take(TAGS_PER_PAGE).ToList(),
                 0,
                 TAGS_PER_PAGE,
                 BlogPostRepo.GetQueryableTags().Count()
                 )
         };
         // the view will show a series of validation error messages
         return View(tagViewModel);
     }
 }