コード例 #1
0
 /// <summary>
 /// Parse the command line parameters into a set of methods that match the command line parameters.
 /// </summary>
 /// <param name="options"></param>
 /// <param name="docset"></param>
 /// <returns></returns>
 private static MethodDefinition[] FindTestMethods(BasicCheckOptions options, DocSet docset)
 {
     MethodDefinition[] methods = null;
     if (!string.IsNullOrEmpty(options.MethodName))
     {
         var foundMethod = LookUpMethod(docset, options.MethodName);
         if (null == foundMethod)
         {
             FancyConsole.WriteLine(FancyConsole.ConsoleErrorColor, "Unable to locate method '{0}' in docset.", options.MethodName);
             Exit(failure: true);
         }
         methods = new MethodDefinition[] { LookUpMethod(docset, options.MethodName) };
     }
     else if (!string.IsNullOrEmpty(options.FileName))
     {
         var selectedFileQuery = from f in docset.Files where f.DisplayName == options.FileName select f;
         var selectedFile      = selectedFileQuery.SingleOrDefault();
         if (selectedFile == null)
         {
             FancyConsole.WriteLine(FancyConsole.ConsoleErrorColor, "Unable to locate file '{0}' in docset.", options.FileName);
             Exit(failure: true);
         }
         methods = selectedFile.Requests;
     }
     else
     {
         methods = docset.Methods;
     }
     return(methods);
 }
コード例 #2
0
        /// <summary>
        /// Performs an internal consistency check on the methods (requests/responses) in the documentation.
        /// Prints the results of the tests to the console.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docset"></param>
        /// <returns></returns>
        private static async Task <CheckResults> CheckMethodsAsync(BasicCheckOptions options, DocSet docset)
        {
            MethodDefinition[] methods = FindTestMethods(options, docset);
            CheckResults       results = new CheckResults();

            foreach (var method in methods)
            {
                var testName = "check-method-syntax: " + method.Identifier;
                TestReport.StartTest(testName, method.SourceFile.DisplayName);

                if (string.IsNullOrEmpty(method.ExpectedResponse))
                {
                    await TestReport.FinishTestAsync(testName, TestOutcome.Failed, "Null response where one was expected.");

                    results.FailureCount++;
                    continue;
                }

                var parser           = new HttpParser();
                var expectedResponse = parser.ParseHttpResponse(method.ExpectedResponse);

                ValidationError[] errors;
                method.ValidateResponse(expectedResponse, null, null, out errors);

                await WriteOutErrorsAndFinishTestAsync(errors, options.SilenceWarnings, "   ", "No errors.", false, testName, "Warnings detected", "Errors detected");

                results.IncrementResultCount(errors);
            }

            return(results);
        }
コード例 #3
0
        /// <summary>
        /// Perform internal consistency checks on the documentation, including verify that
        /// code blocks have proper formatting, that resources are used properly, and that expected
        /// responses and examples conform to the resource definitions.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docs"></param>
        /// <returns></returns>
        private static async Task <bool> CheckDocsAsync(BasicCheckOptions options, DocSet docs = null)
        {
            var docset = docs ?? await GetDocSetAsync(options);

            if (null == docset)
            {
                return(false);
            }

            FancyConsole.WriteLine();

            var resultMethods = await CheckMethodsAsync(options, docset);

            CheckResults resultExamples = new CheckResults();

            if (string.IsNullOrEmpty(options.MethodName))
            {
                resultExamples = await CheckExamplesAsync(options, docset);
            }

            var combinedResults = resultMethods + resultExamples;

            if (options.IgnoreWarnings)
            {
                combinedResults.ConvertWarningsToSuccess();
            }

            combinedResults.PrintToConsole();

            return(combinedResults.FailureCount == 0);
        }
コード例 #4
0
        /// <summary>
        /// Perform all of the local documentation based checks. This is the "compile"
        /// command for the documentation that verifies that everything is clean inside the
        /// documentation itself.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private static async Task <bool> CheckDocsAllAsync(BasicCheckOptions options)
        {
            var docset = await GetDocSetAsync(options);

            if (null == docset)
            {
                return(false);
            }

            var checkLinksResult = await CheckLinksAsync(options, docset);

            var checkDocsResults = await CheckDocsAsync(options, docset);

            return(checkLinksResult && checkDocsResults);
        }
コード例 #5
0
        /// <summary>
        /// Perform an internal consistency check on the examples defined in the documentation. Prints
        /// the results of the tests to the console.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="docset"></param>
        /// <returns></returns>
        private static async Task <CheckResults> CheckExamplesAsync(BasicCheckOptions options, DocSet docset)
        {
            var results = new CheckResults();

            foreach (var doc in docset.Files)
            {
                if (doc.Examples.Length == 0)
                {
                    continue;
                }

                FancyConsole.WriteLine(FancyConsole.ConsoleHeaderColor, "Checking examples in \"{0}\"...", doc.DisplayName);

                foreach (var example in doc.Examples)
                {
                    if (example.Metadata == null)
                    {
                        continue;
                    }
                    if (example.Language != CodeLanguage.Json)
                    {
                        continue;
                    }

                    var testName = string.Format("check-example: {0}", example.Metadata.MethodName, example.Metadata.ResourceType);
                    TestReport.StartTest(testName, doc.DisplayName);

                    ValidationError[] errors;
                    docset.ResourceCollection.ValidateJsonExample(example.Metadata, example.SourceExample, out errors);

                    await WriteOutErrorsAndFinishTestAsync(errors, options.SilenceWarnings, "   ", "No errors.", false, testName, "Warnings detected", "Errors detected");

                    results.IncrementResultCount(errors);
                }
            }

            return(results);
        }