Exemple #1
0
        public void Get_ReturnsTheRightPost()
        {
            var slug     = "my-first-blog-post";
            var markdown = @"---
slug: my-first-blog-post
title:Game Development with C#
tags: c# .net game
date:1-may-2019
excerpt:I will tell you all about that game development
image: url-of-the-image.png
---
# heading 1";

            var markdownGetter = new Mock <IMarkdownGetter>();

            markdownGetter.Setup(x => x.GetBySlug(It.IsAny <string>())).Returns(() => markdown);

            var markdownConverter = new Mock <IMarkdownConverter>();

            markdownConverter.Setup(x => x.Convert(It.IsAny <string>())).Returns(() => "<h1>heading 1</h1>");

            var markdownPostData = new MarkdownPostData(markdownGetter.Object, markdownConverter.Object);

            var post = markdownPostData.GetBySlug(slug);

            Assert.Equal("<h1>heading 1</h1>", post.Content.Trim());
            Assert.Equal(new List <string> {
                "c#", ".net", "game"
            }, post.Tags);
            Assert.Equal(DateTime.Parse("1-may-2019"), post.PublishDate);
            Assert.Equal("I will tell you all about that game development", post.Excerpt);
            Assert.Equal("Game Development with C#", post.Title);
            Assert.Equal("my-first-blog-post", post.Slug);
            Assert.Equal("url-of-the-image.png", post.Image);
        }
Exemple #2
0
        public void GetBySlug_RetunsNull_WhenMarkdownDirectoryDoesnotExist()
        {
            var markdownGetter = new Mock <IMarkdownGetter>();

            markdownGetter.Setup(x => x.GetBySlug(It.IsAny <string>())).Throws <DirectoryNotFoundException>();
            var markdownConverter = new Mock <IMarkdownConverter>();

            markdownConverter.Setup(x => x.Convert(It.IsAny <string>())).Returns(() => "<h1>heading 1</h1>");

            var markdownPostData = new MarkdownPostData(markdownGetter.Object, markdownConverter.Object);
            var posts            = markdownPostData.GetBySlug("not-existed-post");

            Assert.Null(posts);
        }
Exemple #3
0
        public void GetPaginatedPosted_ReturnsAListOfPosts_WithTheRequestedCount(int pageSize)
        {
            var markdowns = new List <string>
            {
                @"---
title:Game Development with C#
tags: c# .net game
date:5-may-2019
excerpt:I will tell you all about that game development
---
# heading 1",
                @"---
title:Whats New With ASP.NET Core 3.2
tags: c# .net core
date:4-may-2019
excerpt:The new additions to ASP.NET Core 3.2 are...
---
## heading 2",
                @"---
title:Another Post About Programming
tags: deploy clean javascript
date:3-may-2019
excerpt:excerpt text
---
# heading 1",
                @"---
title:How To Learn Coding
tags: software programming coding
date:2-may-2019
excerpt:Another excerpt text
---
## heading 2",
            };

            var markdownGetter = new Mock <IMarkdownGetter>();

            markdownGetter.Setup(x => x.GetAll()).Returns(() => markdowns);

            var markdownConverter = new Mock <IMarkdownConverter>();

            markdownConverter.Setup(x => x.Convert(It.IsAny <string>())).Returns(() => "<h2>heading 2</h2>");

            var markdownPostData = new MarkdownPostData(markdownGetter.Object, markdownConverter.Object);

            var posts = markdownPostData.GetPaginatedPosts(1, pageSize);

            Assert.IsAssignableFrom <IEnumerable <Post> >(posts);
            Assert.Equal(pageSize, posts.Count);
        }