Beispiel #1
0
        public void CreateExcerpt_BodyLengthDoesNotExceedMaxLength_ExcerptEqualsBody()
        {
            BlogDataStore    testDataStore        = new BlogDataStore(new FakeFileSystem());
            ExcerptGenerator testExcerptGenerator = new ExcerptGenerator(50);
            string           testExcerpt          = testExcerptGenerator.CreateExcerpt("This is the body");

            Assert.Equal("This is the body", testExcerpt);
        }
Beispiel #2
0
        public void CreateExcerpt_BodyLengthExceedsMaxLength_ExcerptIsTruncated()
        {
            BlogDataStore    testDataStore        = new BlogDataStore(new FakeFileSystem());
            ExcerptGenerator testExcerptGenerator = new ExcerptGenerator(5);
            string           testExcerpt          = testExcerptGenerator.CreateExcerpt("This is the body");

            Assert.Equal("This ...", testExcerpt);
        }
Beispiel #3
0
        public void SavePost(Post post)
        {
            Post.Tags = Request.Form["Tags"][0].Replace(" ", "").Split(",").ToList();

            SlugGenerator slugGenerator = new SlugGenerator(_dataStore);

            Post.Slug = slugGenerator.CreateSlug(Post.Title);

            if (Post.Excerpt == null)
            {
                ExcerptGenerator excerptGenerator = new ExcerptGenerator();
                Post.Excerpt = excerptGenerator.CreateExcerpt(Post.Body, 140);
            }

            _dataStore.SavePost(Post);
            _blog.Posts.Add(Post);
        }
Beispiel #4
0
        public void UpdatePost(Post newPost, string slug)
        {
            oldPost         = _dataStore.GetPost(slug);
            newPost.PubDate = oldPost.PubDate;
            newPost.Tags    = Request.Form["Tags"][0].Replace(" ", "").Split(",").ToList();
            if (newPost.Excerpt == null)
            {
                ExcerptGenerator excerptGenerator = new ExcerptGenerator();
                newPost.Excerpt = excerptGenerator.CreateExcerpt(newPost.Body, 140);
            }

            if (Request.Form["updateslug"] == "true")
            {
                SlugGenerator slugGenerator = new SlugGenerator(_dataStore);
                newPost.Slug = slugGenerator.CreateSlug(newPost.Title);
            }
            else
            {
                newPost.Slug = oldPost.Slug;
            }
            newPost.Comments = oldPost.Comments;

            _dataStore.UpdatePost(newPost, oldPost);
        }