예제 #1
0
        public void Update_UsingSourceAndDocsFolder_WillReturnCodeSnippetCount()
        {
            var directory = @"data\test-site\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");
            var result     = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            Assert.Equal(14, result.Snippets);
        }
예제 #2
0
        public void When_Code_Snippet_Defined_But_Not_Used_Returns_True()
        {
            var directory = @"data\validation\no-reference\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            var result = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            Assert.True(result.Completed);
        }
예제 #3
0
        public void When_Incomplete_Snippet_Found_Does_Not_Import()
        {
            var directory = @"data\validation\bad-snippet\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            var result = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            Assert.False(result.Completed);
        }
예제 #4
0
        public void When_Tag_Found_In_Docs_But_Not_Found_In_Code_Returns_False()
        {
            var directory = @"data\validation\no-snippets\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            var result = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            Assert.False(result.Completed);
        }
예제 #5
0
        public void Update_UsingSourceAndDocsFolder_WillFormatWithCodeSnippet()
        {
            var directory = @"data\test-site\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            var indexFile = Path.Combine(directory, @"docs\index.md");
            var actual    = File.ReadAllText(indexFile);

            var outputFile = Path.Combine(directory, @"output.md");
            var expected   = File.ReadAllText(outputFile);

            Assert.Equal(expected, actual);
        }
예제 #6
0
        public void ProcessTheJsonDotNetDocs()
        {
            var directory = @"D:\Code\github\shiftkey\Newtonsoft.Json";

            var codeFolder = directory;
            var docsFolder = Path.Combine(directory, @"docs\");
            var result     = CodeImporter.Update(codeFolder, new[] { ".*Documentation.*Tests[.]cs" }, docsFolder);

            Console.WriteLine("Completed: {0}", result.Completed);
            Console.WriteLine("Duration: {0}ms", result.ElapsedMilliseconds);

            foreach (var message in result.Errors)
            {
                Console.WriteLine("Error: {0}", message);
            }

            foreach (var message in result.Warnings)
            {
                Console.WriteLine("Warning: {0}", message);
            }
        }
예제 #7
0
        public void When_Incomplete_Snippet_Found_Displays_Error_Message()
        {
            var directory = @"data\validation\bad-snippet\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            var expectedFile = Path.Combine(codeFolder, "code.cs");

            var result = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            var error = result.Errors.First();

            // message explains error
            Assert.Equal(error.Message, "Code snippet reference 'ThisIsAInvalidCodeSnippet' was not closed (specify 'end code ThisIsAInvalidCodeSnippet').");

            // file is as we expected
            Assert.Equal(error.File, expectedFile);

            // and we have the right line number to look at
            Assert.Equal(30, error.LineNumber);
        }
예제 #8
0
        public void When_Code_Snippet_Defined_But_Not_Used_In_Docs_Displays_Warning_Message()
        {
            var directory = @"data\validation\no-reference\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            var expectedFile = Path.Combine(codeFolder, "code.cs");

            var result = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            var warning = result.Warnings.First();

            // message explains error
            Assert.Equal(warning.Message, "Code snippet reference 'LinqToJsonCreateParse' is not used in any pages and can be removed");

            // file is as we expected
            Assert.Equal(warning.File, expectedFile);

            // and we have the right line number to look at
            Assert.Equal(32, warning.LineNumber);
        }
예제 #9
0
        public void When_Tag_Found_In_Docs_But_Not_Found_In_Code_Display_Error()
        {
            var directory = @"data\validation\no-snippets\".ToCurrentDirectory();

            var codeFolder = Path.Combine(directory, @"source\");
            var docsFolder = Path.Combine(directory, @"docs\");

            var expectedFile = Path.Combine(docsFolder, "index.md");

            var result = CodeImporter.Update(codeFolder, new[] { "*.cs" }, docsFolder);

            var error = result.Errors.First();

            // message explains error
            Assert.Equal(error.Message, "Could not find a code snippet for reference 'LinqToJsonCreateParse'");

            // file is as we expected
            Assert.Equal(error.File, expectedFile);

            // and we have the right line number to look at
            Assert.Equal(15, error.LineNumber);
        }