Exemplo n.º 1
0
    void Basic()
    {
        #region markdownProcessing

        // setup version convention and extract snippets from files
        var snippetExtractor = new DirectorySnippetExtractor(
            directoryFilter: x => true,
            fileFilter: s => s.EndsWith(".vm") || s.EndsWith(".cs"));
        var snippets = snippetExtractor.ReadSnippets(@"C:\path");

        // Merge with some markdown text
        var markdownProcessor = new MarkdownProcessor(snippets, SimpleSnippetMarkdownHandling.AppendGroup);

        using (var reader = File.OpenText(@"C:\path\inputMarkdownFile.md"))
            using (var writer = File.CreateText(@"C:\path\outputMarkdownFile.md"))
            {
                var result = markdownProcessor.Apply(reader, writer);

                // snippets that the markdown file expected but did not exist in the input snippets
                var missingSnippets = result.MissingSnippets;

                // snippets that the markdown file used
                var usedSnippets = result.UsedSnippets;
            }

        #endregion
    }
Exemplo n.º 2
0
    public void VerifyLambdasAreCalled()
    {
        var directories     = new ConcurrentBag <CapturedDirectory>();
        var files           = new ConcurrentBag <CapturedFile>();
        var targetDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory,
                                           "DirectorySnippetExtractor/VerifyLambdasAreCalled");
        var result    = new TestResult();
        var extractor = new DirectorySnippetExtractor(
            directoryFilter: path =>
        {
            var capture = new CapturedDirectory
            {
                Path = path
            };
            directories.Add(capture);
            return(true);
        },
            fileFilter: path =>
        {
            var capture = new CapturedFile
            {
                Path = path
            };
            files.Add(capture);
            return(true);
        },
            packageOrder: component => new List <string>()
            );

        extractor.ReadComponents(targetDirectory);
        result.Files       = files.OrderBy(file => file.Path).ToList();
        result.Directories = directories.OrderBy(file => file.Path).ToList();
        ObjectApprover.VerifyWithJson(result, Scrubber.Scrub);
    }
Exemplo n.º 3
0
    public Task Simple()
    {
        var directory = Path.Combine(AssemblyLocation.CurrentDirectory, "DirectorySnippetExtractor/Simple");
        var extractor = new DirectorySnippetExtractor();
        var snippets  = extractor.ReadSnippets(directory);

        return(Verify(snippets));
    }
Exemplo n.º 4
0
    public void Nested()
    {
        var directory  = Path.Combine(AssemblyLocation.CurrentDirectory, "DirectorySnippetExtractor/Nested");
        var extractor  = new DirectorySnippetExtractor(packageOrder: component => new List <string>());
        var components = extractor.ReadComponents(directory);

        ObjectApprover.VerifyWithJson(components.AllSnippets, Scrubber.Scrub);
    }
Exemplo n.º 5
0
    public void Simple()
    {
        var directory  = Path.Combine(AssemblyLocation.CurrentDirectory, "DirectorySnippetExtractor/Simple");
        var extractor  = new DirectorySnippetExtractor();
        var components = extractor.ReadSnippets(directory);

        ObjectApprover.VerifyWithJson(components, Scrubber.Scrub);
    }
Exemplo n.º 6
0
    public void Case()
    {
        var directory = Path.Combine(AssemblyLocation.CurrentDirectory, "DirectorySnippetExtractor/Case");
        var extractor = new DirectorySnippetExtractor();
        var snippets  = extractor.ReadSnippets(directory);

        AssertCaseInsensitive(snippets.Lookup);
        ObjectApprover.VerifyWithJson(snippets, Scrubber.Scrub);
    }
Exemplo n.º 7
0
    public Task Case()
    {
        var directory = Path.Combine(AssemblyLocation.CurrentDirectory, "DirectorySnippetExtractor/Case");
        var extractor = new DirectorySnippetExtractor();
        var snippets  = extractor.ReadSnippets(directory);

        AssertCaseInsensitive(snippets.Lookup);

        return(Verify(snippets));
    }
Exemplo n.º 8
0
    void ReadingDirectory()
    {
        #region ReadingDirectory

        IEnumerable <string> PackageOrder(string component)
        {
            if (component == "component1")
            {
                return(new List <string>
                {
                    "package1",
                    "package2"
                });
            }

            return(Enumerable.Empty <string>());
        }

        string TranslatePackage(string packageAlias)
        {
            if (packageAlias == "shortName")
            {
                return("theFullPackageName");
            }

            return(packageAlias);
        }

        // setup version convention and extract snippets from files
        var snippetExtractor = new DirectorySnippetExtractor(
            // all directories except bin and obj
            directoryFilter: dirPath => !dirPath.EndsWith("bin") && !dirPath.EndsWith("obj"),
            // all vm and cs files
            fileFilter: filePath => filePath.EndsWith(".vm") || filePath.EndsWith(".cs"),
            // package order is optional
            packageOrder: PackageOrder,
            // package translation is optional
            translatePackage: TranslatePackage
            );
        var components            = snippetExtractor.ReadComponents(@"C:\path");
        var component1            = components.GetComponent("Component1");
        var packagesForComponent1 = component1.Packages;
        var snippetsForComponent1 = component1.Snippets;

        var packages            = snippetExtractor.ReadPackages(@"C:\path");
        var package1            = components.GetComponent("Package1");
        var snippetsForPackage1 = package1.Snippets;

        // The below snippets could also be accessed via
        //  * packages.Snippets
        //  * components.AllSnippets
        var snippets = snippetExtractor.ReadSnippets(@"C:\path");

        #endregion
    }
Exemplo n.º 9
0
    public void Simple()
    {
        var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "DirectorySnippetExtractor/Simple");
        var extractor = new DirectorySnippetExtractor(
            directoryFilter: path => true,
            fileFilter: path => true,
            packageOrder: component => new List <string>()
            );
        var components = extractor.ReadComponents(directory);

        ObjectApprover.VerifyWithJson(components, Scrubber.Scrub);
    }
Exemplo n.º 10
0
    void ReadingDirectory()
    {
        #region ReadingDirectorySimple

        // extract snippets from files
        var snippetExtractor = new DirectorySnippetExtractor(
            // all directories except bin and obj
            directoryFilter: dirPath => !dirPath.EndsWith("bin") &&
            !dirPath.EndsWith("obj"));
        var snippets = snippetExtractor.ReadSnippets(@"C:\path");

        #endregion
    }
Exemplo n.º 11
0
    public void Sorting()
    {
        var directory  = Path.Combine(AssemblyLocation.CurrentDirectory, "DirectorySnippetExtractor/Sorting");
        var extractor  = new DirectorySnippetExtractor(packageOrder: PackageOrder);
        var components = extractor.ReadComponents(directory);
        var snippets   = components
                         .Components
                         .SelectMany(_ => _.Packages)
                         .SelectMany(_ => _.Snippets)
                         .Select(_ => $"{_.Package} {_.Version.SimplePrint()} {_.IsCurrent}");

        ObjectApprover.VerifyWithJson(snippets, Scrubber.Scrub);
    }
    public Task VerifyLambdasAreCalled()
    {
        var directories     = new ConcurrentBag <string>();
        var targetDirectory = Path.Combine(AssemblyLocation.CurrentDirectory,
                                           "DirectorySnippetExtractor/VerifyLambdasAreCalled");
        var extractor = new DirectorySnippetExtractor(
            directoryFilter: path =>
        {
            directories.Add(path);
            return(true);
        });

        extractor.ReadSnippets(targetDirectory);
        return(Verifier.Verify(directories.OrderBy(file => file)));
    }
Exemplo n.º 13
0
    public void Case()
    {
        var directory = Path.Combine(TestContext.CurrentContext.TestDirectory, "DirectorySnippetExtractor/Case");
        var extractor = new DirectorySnippetExtractor(
            directoryFilter: _ => true,
            fileFilter: _ => true,
            packageOrder: _ => new List <string>()
            );
        var components = extractor.ReadComponents(directory);

        AssertCaseInsensitive(components.Lookup);
        var component = components.GetComponent("ComponentY");

        AssertCaseInsensitive(component.Lookup);
        var package = component.Packages.Single();

        AssertCaseInsensitive(package.Lookup);
        AssertCaseInsensitive(package.Versions.First().Lookup);
        ObjectApprover.VerifyWithJson(components, Scrubber.Scrub);
    }
Exemplo n.º 14
0
    void Basic()
    {
        #region markdownProcessingSimple

        var directory = @"C:\path";

        // extract snippets from files
        var snippetExtractor = new DirectorySnippetExtractor();
        var snippets         = snippetExtractor.ReadSnippets(directory);

        // extract includes from files
        var includeFinder = new IncludeFinder();
        var includes      = includeFinder.ReadIncludes(directory);

        // Merge with some markdown text
        var markdownProcessor = new MarkdownProcessor(
            convention: DocumentConvention.SourceTransform,
            snippets: snippets.Lookup,
            includes: includes,
            appendSnippets: SimpleSnippetMarkdownHandling.Append,
            snippetSourceFiles: new List <string>(),
            tocLevel: 2,
            writeHeader: true,
            rootDirectory: directory,
            validateContent: true);

        var path = @"C:\path\inputMarkdownFile.md";
        using var reader = File.OpenText(path);
        using var writer = File.CreateText(@"C:\path\outputMarkdownFile.md");
        var result = markdownProcessor.Apply(reader, writer, path);
        // snippets that the markdown file expected but did not exist in the input snippets
        var missingSnippets = result.MissingSnippets;

        // snippets that the markdown file used
        var usedSnippets = result.UsedSnippets;

        #endregion
    }