Пример #1
0
        private void LoadTestScripts(string folder)
        {
            if (!Directory.Exists(folder))
            {
                return;
            }

            DirectoryInfo directoryInfo = new DirectoryInfo(folder);

            var scriptFilePaths = from file in directoryInfo.GetFiles("*" + SqlExtension)
                                  where SqlExtension.Equals(file.Extension, StringComparison.OrdinalIgnoreCase)
                                  select file.FullName;

            foreach (string scriptFile in scriptFilePaths)
            {
                try
                {
                    string contents = RuleTestUtils.ReadFileToString(scriptFile);
                    TestScripts.Add(Tuple.Create(contents, Path.GetFileName(scriptFile)));
                    Console.WriteLine($"Test file '{scriptFile}' loaded successfully");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error reading from file {scriptFile} with message '{ex.Message}'");
                    Console.WriteLine("Execution will continue...");
                }
            }
        }
Пример #2
0
        private void RunVerification(CodeAnalysisResult result, string resultsString)
        {
            string baseline = RuleTestUtils.ReadFileToString(BaselineFilePath);

            RuleTestUtils.SaveStringToFile(resultsString, OutputFilePath);

            string loadedTestScriptFiles = ListScriptFilenames();

            if (string.Compare(resultsString, baseline, false, System.Globalization.CultureInfo.CurrentCulture) != 0)
            {
                StringBuilder failureMessage = new StringBuilder();

                failureMessage.AppendLine($"The result is not the same as expected. Please compare actual output to baseline.");
                failureMessage.AppendLine("");
                failureMessage.AppendLine($"### Loaded Test Script Files ###");
                failureMessage.AppendLine(loadedTestScriptFiles);
                failureMessage.AppendLine("");
                failureMessage.AppendLine($"### View Baseline ###");
                failureMessage.AppendLine(BaselineFilePath);
                failureMessage.AppendLine("");
                failureMessage.AppendLine($"### View Action Output ###");
                failureMessage.AppendLine(OutputFilePath);
                failureMessage.AppendLine("");
                failureMessage.AppendLine($"### Test Folder ###");
                failureMessage.AppendLine(ScriptsFolder);

                Assert.Fail(failureMessage.ToString());
            }
        }