Пример #1
0
        public void BlogPost_CreateNewPost()
        {
            DateTime today = DateTime.Now.Date;
            BlogPost post = new BlogPost("Title", "Content");

            Assert.IsTrue(post.Title == "Title");
            Assert.IsTrue(post.Content == "Content");
            Assert.IsTrue(post.Author == "Robert Christ");
            Assert.IsTrue(post.PostDate == today);
            Assert.IsNotNull(post.BlogPostId);
        }
        public void CommentPost_CreateNewComment()
        {
            DateTime today = DateTime.Now.Date;
            BlogPost post = new BlogPost("title", "content");

            CommentPost comment = new CommentPost("commentAuthor", "commentContent", post.BlogPostId);

            Assert.IsTrue(comment.Content == "commentContent");
            Assert.IsTrue(comment.Author == "commentAuthor");
            Assert.IsTrue(comment.PostDate == today);
            Assert.IsNotNull(comment.CommentPostId);
        }
        /// <summary>
        /// Saves a new blog to the db.  Post cannot be null.
        /// </summary>
        /// <param name="post">The post to save, cannot be null.</param>
        public void CreateBlog(string title, string content)
        {
            if (String.IsNullOrWhiteSpace(title))
                throw new ArgumentNullException("Title");

            if (String.IsNullOrWhiteSpace(content))
                throw new ArgumentNullException("Content");

            //Selectively allow guaranteed safe html tags, encode everything else.
            content = ValidateUserInput(content);

            var post = new BlogPost(title, content);

            _context.Blogs.Add(post);
            _context.SaveChanges();
            _cache.Invalidate(CACHE_KEY_BLOG_TITLES);
        }
        public void UpdateBlog(int id, BlogPost newVersion)
        {
            //TODO: um, so this is wrong.
            newVersion.Content = ValidateUserInput(newVersion.Content);
            _context.Entry(newVersion).State = EntityState.Modified;

            _context.SaveChanges();
            _cache.Invalidate(CACHE_KEY_BLOG_TITLES);
        }