Example #1
0
        public void Post_should_map_properties_to_concrete_LinkPostModel()
        {
            Post post = new Post { Link = new Link { Type = LinkType.Html, Description = "desc" } };

            PostModel model = mapper.Map<Post, PostModel>(post);

            Assert.AreEqual("desc", ((LinkPostModel)model).LinkDescription);
        }
Example #2
0
        public void Post_should_map_to_concrete_LinkPostModel()
        {
            Post post = new Post { Link = new Link { Type = LinkType.Html } };

            PostModel model = mapper.Map<Post, PostModel>(post);

            Assert.IsInstanceOfType(model, typeof(LinkPostModel));
        }
Example #3
0
        public void post_should_map_properties_to_concrete_ImagePostModel()
        {
            Post post = new Post { Link = new Link { Type = LinkType.Image, Picture = "pic" } };

            PostModel model = mapper.Map<Post, PostModel>(post);

            Assert.AreEqual("pic", ((ImagePostModel)model).LinkPicture);
        }
Example #4
0
        public void Post_should_map_Comments_property_even_if_empty()
        {
            Post post = new Post { Id = 2, Link = new Link { Type = LinkType.Image, Picture = "pic" } };

            PostModel model = mapper.Map<Post, PostModel>(post);

            Assert.IsNotNull(model.Comments);
        }
Example #5
0
        /// <summary>
        /// Parses links and smileys in user input, removing undersired links, highlighting
        /// the others, and turning smileys into their appropriate image tags.
        /// </summary>
        /// <param name="message">A message provided by a user.</param>
        /// <param name="post">The post the user message belongs to, if any.</param>
        /// <returns>The message formatted how we want to display it.</returns>
        public IHtmlString BeautifyUserMessage(string message, Post post = null)
        {
            if (message == null)
            {
                return null;
            }
            string encoded = HttpUtility.HtmlEncode(message); // all user input must be html-encoded.

            Func<Uri, bool> filter = uri => post == null || !linkService.AreEqual(uri, post.Link);
            string hotLinked = linkService.HotLinkHtml(encoded, filter);
            string htmlString = smileyService.ReplaceSmileys(hotLinked, true);
            IHtmlString html = new MvcHtmlString(htmlString.TrimAll(includeLineBreaks: false));
            return html;
        }
Example #6
0
 internal string DetailsRoute(Post post)
 {
     return urlHelper.Action("Details", "Posts", new
     {
         id = post.Id,
         slug = postService.GetTitleSlug(post)
     });
 }
Example #7
0
 public IEnumerable<Comment> GetComments(Post post)
 {
     IEnumerable<Comment> comments = commentRepository.GetByPostId(post.Id);
     return comments;
 }
Example #8
0
 public string GetTitleSlug(Post post)
 {
     if (post.Link == null)
     {
         return textHelper.Slugify(post.UserMessage, 40);
     }
     else
     {
         return textHelper.Slugify(post.Link.Title);
     }
 }