예제 #1
0
        public void TestFileAbstractLayerWithRedirectionFolder()
        {
            // arrange
            var input = GetRandomFolder();

            Directory.CreateDirectory(Path.Combine(input, "structured"));
            Directory.CreateDirectory(Path.Combine(input, "authored"));
            Directory.CreateDirectory(Path.Combine(input, "standalone"));
            File.WriteAllText(Path.Combine(input, "structured/temp1.yml"), "I pair with authored/temp1.yml.md");
            File.WriteAllText(Path.Combine(input, "authored/temp1.yml.md"), "I am paired by structured/temp1.yml");
            File.WriteAllText(Path.Combine(input, "structured/temp2.yml"), "I pair with authored/temp2.yml.md");
            File.WriteAllText(Path.Combine(input, "structured/temp2.yml.md"), "I am not paired by authored/temp2.yml.md");
            File.WriteAllText(Path.Combine(input, "standalone/temp3"), "I am not affected by folder redirection rules");
            var fdm = new FolderRedirectionManager(new[] { new FolderRedirectionRule("structured", "authored") });

            // act
            var fal = FileAbstractLayerBuilder.Default
                      .ReadFromRealFileSystem(input)
                      .ReadWithFolderRedirection(fdm)
                      .Create();

            // assert
            Assert.True(fal.Exists("structured/temp1.yml.md"));
            Assert.Equal("I am paired by structured/temp1.yml", fal.ReadAllText("structured/temp1.yml.md"));
            Assert.False(fal.Exists("structured/temp2.yml.md"));
            Assert.True(fal.Exists("standalone/temp3"));
            Assert.Equal("I am not affected by folder redirection rules", fal.ReadAllText("standalone/temp3"));
        }
        public SchemaDrivenDocumentProcessor(
            DocumentSchema schema,
            ICompositionContainer container,
            MarkdigMarkdownService markdigMarkdownService,
            FolderRedirectionManager folderRedirectionManager)
        {
            if (string.IsNullOrWhiteSpace(schema.Title))
            {
                throw new ArgumentException("Title for schema must not be empty");
            }

            _schemaName               = schema.Title;
            _schema                   = schema;
            SchemaValidator           = schema.Validator;
            _allowOverwrite           = schema.AllowOverwrite;
            _serializerPool           = new ResourcePoolManager <JsonSerializer>(GetSerializer, 0x10);
            _markdigMarkdownService   = markdigMarkdownService ?? throw new ArgumentNullException(nameof(MarkdigMarkdownService));
            _folderRedirectionManager = folderRedirectionManager;
            if (container != null)
            {
                var commonSteps         = container.GetExports <IDocumentBuildStep>(nameof(SchemaDrivenDocumentProcessor));
                var schemaSpecificSteps = container.GetExports <IDocumentBuildStep>($"{nameof(SchemaDrivenDocumentProcessor)}.{_schemaName}");
                BuildSteps = commonSteps.Union(schemaSpecificSteps).ToList();
            }
        }
예제 #3
0
        public void TestFolderRedirection()
        {
            var fdm = new FolderRedirectionManager(
                new[]
            {
                new FolderRedirectionRule("a", "b"),
                new FolderRedirectionRule("c", "d"),
            });

            Assert.Equal("b/test.md", fdm.GetRedirectedPath((RelativePath)"a/test.md"));
            Assert.Equal("b/sub/test.md", fdm.GetRedirectedPath((RelativePath)"a/sub/test.md"));
            Assert.Equal("d/test.md", fdm.GetRedirectedPath((RelativePath)"c/test.md"));
            Assert.Equal("e/test.md", fdm.GetRedirectedPath((RelativePath)"e/test.md"));
        }