private void RunVerification(CodeAnalysisResult result, string resultsString) { // Check if the resultsString matches our baseline. If not, output the test files that // were loaded, and some commands to easily overwrite the existing baseline with the output. // once you've overwritten it you can compare the new and old baselines using the Diff tools // in Team Explorer string baseline = RuleTestUtils.ReadFileToString(this.BaselineFilePath); RuleTestUtils.SaveStringToFile(resultsString, this.OutputFilePath); string loadedTestScriptFiles = this.ListScriptFilenames(); if (string.Compare(resultsString, baseline, false, CultureInfo.CurrentCulture) != 0) { Assert.Fail(String.Format( "The result is not the same as expected. It's recommended you compare the actual output " + "to the baseline. If the output matches your expectations, update the baseline file inside " + "the project.\r\n\r\n" + "################## loaded test script files ################## \r\n" + loadedTestScriptFiles + "\r\n" + "rem ################## View Baseline: ##################\r\n" + "Notepad++ \"{0}\" \r\n\r\n" + "rem ################## View Actual Output: ##################\r\n" + "Notepad++ \"{1}\" \r\n\r\n" + "################## cd test folder command ##################\r\n" + "cd \"{2}\"\r\n", this.BaselineFilePath, this.OutputFilePath, this.ScriptsFolder)); } }
private void LoadTestScripts() { // Load all files ending in ".sql". Note that due to strange Win32 behavior we need to double check the // file name actually ends in ".sql" since suffixes like ".sqlOther" would also be included in the results DirectoryInfo di = new DirectoryInfo(this.ScriptsFolder); var scriptFilepaths = from file in di.GetFiles("*" + SqlExt) where SqlExt.Equals(file.Extension, StringComparison.OrdinalIgnoreCase) select file.FullName; foreach (string scriptFile in scriptFilepaths) { try { string contents = RuleTestUtils.ReadFileToString(scriptFile); this.TestScripts.Add(Tuple.Create(contents, scriptFile)); Console.WriteLine("Test script file '{0}' loaded", scriptFile); } catch (Exception ex) { Console.WriteLine( "Error reading from file '{0}', message is '{1}'. Continuing processing since missing files treated as warning for test", scriptFile, ex.Message); } } }