Exemplo n.º 1
0
        public void Scenario(string name, string folder, string inputFile, string expectedFile)
        {
            var parser = new CodeFileParser(folder);
            var snippets = parser.Parse(new[] { ".*code[.]cs" });

            var result = DocumentFileProcessor.Apply(snippets, inputFile);

            Assert.Equal(File.ReadAllText(expectedFile), result.Text);
        }
Exemplo n.º 2
0
        public void GetCodeSnippets_ProvidingARegex_ChoosesAllFiles()
        {
            var directory = @"data\use-regexes\".ToCurrentDirectory();

            var parser = new CodeFileParser(directory);
            var actual = parser.Parse(new[] { "[.]cs" });

            Assert.True(actual.Count == 2);
        }
Exemplo n.º 3
0
        public void GetCodeSnippets_ProvidingARegexWithFolder_ChoosesOneFile()
        {
            var directory = @"data\use-regexes\".ToCurrentDirectory();

            var parser = new CodeFileParser(directory);
            var actual = parser.Parse(new[] { @".*want.*[.]cs" });

            Assert.True(actual.Count == 1);
        }
Exemplo n.º 4
0
        public void GetCodeSnippets_WithNestedSnippets_ReturnsTwoValues()
        {
            var directory = @"data\get-code-snippets\".ToCurrentDirectory();

            var parser = new CodeFileParser(directory);
            var actual = parser.Parse(new[] { ".*nested-code[.]cs" });

            Assert.Equal(2, actual.Count);
            Assert.True(actual.All(c => !string.IsNullOrWhiteSpace(c.Value)));
        }
Exemplo n.º 5
0
        public void GetCodeSnippets_ReturnsMultipleResults_AllHaveValues()
        {
            var directory = @"data\get-code-snippets\".ToCurrentDirectory();

            var parser = new CodeFileParser(directory);
            var actual = parser.Parse(new[] { ".*code[.]cs" });

            Assert.True(actual.Count > 1);
            Assert.True(actual.All(c => !string.IsNullOrWhiteSpace(c.Value)));
        }
Exemplo n.º 6
0
        public void ApplySnippets_UsingFile_MatchesExpectedResult()
        {
            var directory = @"data\apply-snippets\".ToCurrentDirectory();
            var inputFile = Path.Combine(directory, @"input.md");
            var outputFile = Path.Combine(directory, @"output.md");

            var parser = new CodeFileParser(directory);
            var snippets = parser.Parse(new[] { ".*code[.]cs" });

            var result = DocumentFileProcessor.Apply(snippets, inputFile);

            Assert.Equal(File.ReadAllText(outputFile), result.Text);
        }
Exemplo n.º 7
0
        public static UpdateResult Update(string codeFolder, string[] extensionsToSearch, string docsFolder)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var result = new UpdateResult();

            var codeParser = new CodeFileParser(codeFolder);
            ICollection <CodeSnippet> snippets;

            using (TimingScope.Start("CodeParser.Parse"))
                snippets = codeParser.Parse(extensionsToSearch);

            var incompleteSnippets = snippets.Where(s => string.IsNullOrWhiteSpace(s.Value)).ToArray();

            if (incompleteSnippets.Any())
            {
                var messages = ErrorFormatter.FormatIncomplete(incompleteSnippets);
                result.Errors.AddRange(messages);
                return(result);
            }

            result.Snippets = snippets.Count;

            var processor     = new DocumentFileProcessor(docsFolder);
            var processResult = processor.Apply(snippets);

            var snippetsNotUsed = snippets.Except(processResult.SnippetsUsed).ToArray();

            var snippetsMissed = processResult.SnippetReferences;

            if (snippetsMissed.Any())
            {
                var messages = ErrorFormatter.FormatNotFound(snippetsMissed);
                result.Errors.AddRange(messages);
            }

            if (snippetsNotUsed.Any())
            {
                var messages = ErrorFormatter.FormatUnused(snippetsNotUsed);
                result.Warnings.AddRange(messages);
            }

            result.Files     = processResult.Count;
            result.Completed = !result.Errors.Any();
            stopwatch.Stop();
            result.ElapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            return(result);
        }
Exemplo n.º 8
0
        public static UpdateResult Update(string codeFolder, string[] extensionsToSearch, string docsFolder)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var result = new UpdateResult();

            var codeParser = new CodeFileParser(codeFolder);
            ICollection<CodeSnippet> snippets;
            using(TimingScope.Start("CodeParser.Parse"))
                snippets = codeParser.Parse(extensionsToSearch);

            var incompleteSnippets = snippets.Where(s => string.IsNullOrWhiteSpace(s.Value)).ToArray();
            if (incompleteSnippets.Any())
            {
                var messages = ErrorFormatter.FormatIncomplete(incompleteSnippets);
                result.Errors.AddRange(messages);
                return result;
            }

            result.Snippets = snippets.Count;

            var processor = new DocumentFileProcessor(docsFolder);
            var processResult = processor.Apply(snippets);

            var snippetsNotUsed = snippets.Except(processResult.SnippetsUsed).ToArray();

            var snippetsMissed = processResult.SnippetReferences;

            if (snippetsMissed.Any())
            {
                var messages = ErrorFormatter.FormatNotFound(snippetsMissed);
                result.Errors.AddRange(messages);
            }

            if (snippetsNotUsed.Any())
            {
                var messages = ErrorFormatter.FormatUnused(snippetsNotUsed);
                result.Warnings.AddRange(messages);
            }

            result.Files = processResult.Count;
            result.Completed = !result.Errors.Any();
            stopwatch.Stop();
            result.ElapsedMilliseconds = stopwatch.ElapsedMilliseconds;

            return result;
        }