コード例 #1
0
ファイル: Converter.cs プロジェクト: rnielikki/Pagene
 /// <summary>
 /// Start converting data.
 /// </summary>
 /// <remarks>See other documentation page about converting format and file path.</remarks>
 public async Task BuildAsync()
 {
     var mdFileType     = new PostFileType(_fileSystem);
     var attachmentType = new AttachmentFileType(_fileSystem);
     await Task.WhenAll(
         new[] {
         new PartialConverter(mdFileType, _fileSystem).BuildAsync(),
         new PartialConverter(attachmentType, _fileSystem).BuildAsync()
     }
         ).ConfigureAwait(false);
 }
コード例 #2
0
ファイル: SavePostTest.cs プロジェクト: rnielikki/Pagene
        public async Task SaveFormatTest()
        {
            const string title       = "Random";
            const string content     = "asdfasdf";
            string       contentPath = $"{Models.FormatterTestModel.OutputContentPath}something.json";

            MockFileSystem fileSystem = new(
                new Dictionary <string, MockFileData>()
            {
                { contentPath, new MockFileData(content) },
            }
                );

            var dateTime     = new System.DateTime(2020, 2, 2);
            var editDateTime = new System.DateTime(2020, 3, 25);
            var fileInfo     = fileSystem.FileInfo.FromFileName(contentPath);

            using var fileStream   = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(content));
            fileInfo.CreationTime  = dateTime;
            fileInfo.LastWriteTime = editDateTime;

            var formatterMock = new Mock <IFormatter>();

            formatterMock.Setup(obj => obj.GetBlogHeadAsync(It.IsAny <System.IO.Abstractions.IFileInfo>(), It.IsAny <System.IO.StreamReader>()))
            .ReturnsAsync(new BlogEntry {
                Title = title, Date = dateTime, Summary = "--", Url = contentPath, Tags = new string[] { "book", "game", "music" }
            });
            var tagManager = new TagManager(fileSystem);
            var fileType   = new PostFileType(fileSystem, formatterMock.Object, tagManager);

            await fileType.SaveAsync(fileInfo, fileStream).ConfigureAwait(false);

            using System.IO.Stream resultStream = fileSystem.File.Open(contentPath, System.IO.FileMode.Open);
            var result = await JsonSerializer.DeserializeAsync <BlogItem>(resultStream).ConfigureAwait(false);

            Assert.Equal(dateTime, result.CreationDate);
            Assert.Equal(editDateTime, result.ModificationDate);
            Assert.Equal(content, result.Content);
        }