public void OnGet() { var blogPath = Path.Combine(_env.WebRootPath, BlogRelativePath); var loader = new BlogPostLoader(_env, Url); Index = loader.LoadIndex(blogPath); }
public async System.Threading.Tasks.Task BlogPostSaveTest(KeyValuePair <string, MockFileData> data, string fileName) { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>() { { data.Key, data.Value } }); var loader = new BlogPostLoader(fileSystem, new PostSerializer()); var item = new BlogItem { Title = "title", Content = "x", Tags = new string[] { "a", "b", "c" } }; await loader.SaveBlogItem(item, fileName).ConfigureAwait(true); Assert.True(fileSystem.FileExists(AppPathInfo.BlogInputPath + fileName)); string[] fileContents = fileSystem.File.ReadAllLines(AppPathInfo.BlogInputPath + fileName); Assert.Equal("[a,b,c]", fileContents[0]); Assert.Equal("# title", fileContents[1]); Assert.Equal("x", fileContents[2]); }
public void GetPostListTest() { const string newerFile = "bbb.md"; const string fileName = "placeholder.md"; IFileSystem fileSystem = new MockFileSystem( new Dictionary <string, MockFileData>() { { AppPathInfo.BlogInputPath + fileName, new MockFileData($"[tag1, tag2, tag3]{Environment.NewLine}# x{Environment.NewLine}x") }, { $"{AppPathInfo.BlogInputPath}asdfadsf.md", new MockFileData($"[tag1, tag2, tag3]{Environment.NewLine}# y{Environment.NewLine}y") }, { AppPathInfo.BlogInputPath + newerFile, new MockFileData($"[tag1, tag2, tag3]{Environment.NewLine}# 123123{Environment.NewLine}y") }, { $"{AppPathInfo.BlogInputPath}test.md", new MockFileData($"[tag1, tag2, tag3]{Environment.NewLine}# 234234{Environment.NewLine}y") }, } ); var filePaths = fileSystem.DirectoryInfo.FromDirectoryName(AppPathInfo.BlogInputPath).GetFiles(); int day = 1; foreach (var file in filePaths) { if (file.Name == newerFile) { file.CreationTime = new DateTime(2020, 10, 2); } else { file.CreationTime = new DateTime(2015, 10, day); } day += 4; } var serializerMock = new Mock <IPostSerializer>(); serializerMock.Setup(obj => obj.DeserializeAsync(It.IsAny <Stream>())).ReturnsAsync(new BlogItem()); var postLoader = new BlogPostLoader(fileSystem, serializerMock.Object); var files = postLoader.LoadPosts().Select(post => post.FileName); Assert.Contains(fileName, files); Assert.Equal(newerFile, files.FirstOrDefault()); }
public async Task OnGet(string url) { var blogPath = Path.Combine(_env.WebRootPath, BlogRelativePath); var loader = new BlogPostLoader(_env, Url); var index = loader.LoadIndex(blogPath); RecentPosts = index.Take(10); var articlePath = string.IsNullOrWhiteSpace(url) ? index.FirstOrDefault()?.Path : NormalizeMarkdownPath(Path.Combine(blogPath, url)); if (!string.IsNullOrWhiteSpace(articlePath) && System.IO.File.Exists(articlePath)) { var selected = index.FirstOrDefault(x => x.Path == articlePath); if (selected is object) { selected.IsSelected = true; } Article = await loader.LoadArticle(articlePath); } }