/// <summary> /// Print a list of the resources detected in the documentation set to the console. /// </summary> /// <param name="options"></param> /// <param name="docset"></param> /// <returns></returns> private static async Task PrintResourcesAsync(DocSetOptions options, DocSet docset) { docset = docset ?? await GetDocSetAsync(options); if (null == docset) { return; } FancyConsole.WriteLine(); FancyConsole.WriteLine(FancyConsole.ConsoleHeaderColor, "Defined resources:"); FancyConsole.WriteLine(); var sortedResources = docset.Resources.OrderBy(x => x.ResourceType); foreach (var resource in sortedResources) { if (options.EnableVerboseOutput) { string metadata = JsonConvert.SerializeObject(resource.Metadata); FancyConsole.Write(" "); FancyConsole.Write(FancyConsole.ConsoleHeaderColor, resource.ResourceType); FancyConsole.WriteLine(" flags: {1}", resource.ResourceType, metadata); } else { FancyConsole.WriteLineIndented(" ", FancyConsole.ConsoleHeaderColor, resource.ResourceType); } FancyConsole.WriteLineIndented(" ", FancyConsole.ConsoleCodeColor, resource.JsonExample); FancyConsole.WriteLine(); } }
/// <summary> /// Validate that the CSDL metadata defined for a service matches the documentation. /// </summary> /// <param name="options"></param> /// <returns></returns> private static async Task <bool> CheckServiceMetadataAsync(CheckMetadataOptions options) { List <Schema> schemas = await TryGetMetadataSchemasAsync(options); if (null == schemas) { return(false); } FancyConsole.WriteLine(FancyConsole.ConsoleSuccessColor, " found {0} schema definitions: {1}", schemas.Count, (from s in schemas select s.Namespace).ComponentsJoinedByString(", ")); var docSet = await GetDocSetAsync(options); if (null == docSet) { return(false); } const string testname = "validate-service-metadata"; TestReport.StartTest(testname); List <ResourceDefinition> foundResources = ODataParser.GenerateResourcesFromSchemas(schemas); CheckResults results = new CheckResults(); List <ValidationError> collectedErrors = new List <ValidationError>(); foreach (var resource in foundResources) { FancyConsole.WriteLine(); FancyConsole.Write(FancyConsole.ConsoleHeaderColor, "Checking resource: {0}...", resource.Metadata.ResourceType); FancyConsole.VerboseWriteLine(); FancyConsole.VerboseWriteLine(resource.JsonExample); FancyConsole.VerboseWriteLine(); // Verify that this resource matches the documentation ValidationError[] errors; docSet.ResourceCollection.ValidateJsonExample(resource.Metadata, resource.JsonExample, out errors, new ValidationOptions { RelaxedStringValidation = true }); results.IncrementResultCount(errors); collectedErrors.AddRange(errors); await WriteOutErrorsAndFinishTestAsync(errors, options.SilenceWarnings, successMessage : " no errors."); } if (options.IgnoreWarnings) { results.ConvertWarningsToSuccess(); } var output = (from e in collectedErrors select e.ErrorText).ComponentsJoinedByString("\r\n"); await TestReport.FinishTestAsync(testname, results.WereFailures?TestOutcome.Failed : TestOutcome.Passed, stdOut : output); results.PrintToConsole(); return(!results.WereFailures); }
public static void StartTest(string testName, string filename = null) { FancyConsole.WriteLine(); FancyConsole.Write(FancyConsole.ConsoleHeaderColor, "Starting test: "); FancyConsole.Write(FancyConsole.ConsoleDefaultColor, testName); if (null != filename) { FancyConsole.Write(" [{0}]", filename); TestStartFilename[testName] = filename; } FancyConsole.WriteLine(); TestStartTimes[testName] = DateTimeOffset.Now.Ticks; }
public static async Task FinishTestAsync(string testName, TestOutcome outcome, string message = null, string filename = null, string stdOut = null, bool printFailuresOnly = false) { var endTime = DateTimeOffset.Now.Ticks; TimeSpan duration; long startTime; if (TestStartTimes.TryGetValue(testName, out startTime)) { duration = new TimeSpan(endTime - startTime); TestStartTimes.Remove(testName); } else { duration = TimeSpan.Zero; } if (null == filename) { TestStartFilename.TryGetValue(testName, out filename); TestStartFilename.Remove(testName); } if (!printFailuresOnly || outcome != TestOutcome.Passed) { FancyConsole.Write("Test {0} complete.", testName); switch (outcome) { case TestOutcome.Failed: FancyConsole.Write(ConsoleColor.Red, " Failed: {0}", message); break; case TestOutcome.Passed: FancyConsole.Write(ConsoleColor.Green, " Passed: {0}", message); break; default: FancyConsole.Write(" {0}: {1}", outcome, message); break; } FancyConsole.WriteLine(" duration: {0}", duration); } await BuildWorkerApi.RecordTestAsync(testName, TestFrameworkName, outcome : outcome, durationInMilliseconds : (long)duration.TotalMilliseconds, errorMessage : message, filename : filename, stdOut : stdOut); }
public void PrintToConsole(bool addNewLine = true) { if (addNewLine) { FancyConsole.WriteLine(); FancyConsole.Write("Runs completed. "); } const string percentCompleteFormat = "{0:0.00}% passed"; FancyConsole.Write( this.PercentSuccessful == 100.0 ? FancyConsole.ConsoleSuccessColor : FancyConsole.ConsoleWarningColor, percentCompleteFormat, this.PercentSuccessful); List <string> resultsOutput = new List <string>(); if (this.FailureCount > 0 || this.WarningCount > 0) { FancyConsole.Write(" ("); if (this.FailureCount > 0) { FancyConsole.Write(FancyConsole.ConsoleErrorColor, "{0} errors", this.FailureCount); } if (this.WarningCount > 0 && this.FailureCount > 0) { FancyConsole.Write(", "); } if (this.WarningCount > 0) { FancyConsole.Write(FancyConsole.ConsoleWarningColor, "{0} warnings", this.WarningCount); } if ((this.WarningCount > 0 || this.FailureCount > 0) && this.SuccessCount > 0) { FancyConsole.Write(", "); } if (this.SuccessCount > 0) { FancyConsole.Write(FancyConsole.ConsoleSuccessColor, "{0} successful", this.SuccessCount); } FancyConsole.Write(")"); } FancyConsole.WriteLine(); }
public void PrintToConsole() { FancyConsole.WriteLine(); FancyConsole.Write("Runs completed. "); const string percentCompleteFormat = "{0:0.00}% passed"; FancyConsole.Write( this.PercentSuccessful == 100.0 ? FancyConsole.ConsoleSuccessColor : FancyConsole.ConsoleWarningColor, percentCompleteFormat, this.PercentSuccessful); if (this.FailureCount > 0 || this.WarningCount > 0) { FancyConsole.Write(" ("); if (this.FailureCount > 0) { FancyConsole.Write(FancyConsole.ConsoleErrorColor, "{0} errors", this.FailureCount); } if (this.WarningCount > 0 && this.FailureCount > 0) { FancyConsole.Write(", "); } if (this.WarningCount > 0) { FancyConsole.Write(FancyConsole.ConsoleWarningColor, "{0} warnings", this.WarningCount); } if (this.WarningCount > 0 || this.FailureCount > 0 && this.SuccessCount > 0) { FancyConsole.Write(", "); } if (this.SuccessCount > 0) { FancyConsole.Write(FancyConsole.ConsoleSuccessColor, "{0} successful", this.SuccessCount); } FancyConsole.Write(")"); } FancyConsole.WriteLine(); }