Ejemplo n.º 1
0
        public static void VerifyCodeFix(string path, string pathToExpected, string pathToBatchExpected,
                                         SonarDiagnosticAnalyzer diagnosticAnalyzer, SonarCodeFixProvider codeFixProvider, string codeFixTitle,
                                         IEnumerable <ParseOptions> options = null, IEnumerable <MetadataReference> additionalReferences = null)
        {
            var parseOptions = options ?? ParseOptionsHelper.GetParseOptionsByFileExtension(Path.GetExtension(path));

            foreach (var parseOption in parseOptions)
            {
                RunCodeFixWhileDocumentChanges(diagnosticAnalyzer, codeFixProvider, codeFixTitle,
                                               CreateDocument(path, additionalReferences), parseOption, pathToExpected);
            }

            var fixAllProvider = codeFixProvider.GetFixAllProvider();

            if (fixAllProvider == null)
            {
                return;
            }

            foreach (var parseOption in parseOptions)
            {
                RunFixAllProvider(diagnosticAnalyzer, codeFixProvider, codeFixTitle, fixAllProvider,
                                  CreateDocument(path, additionalReferences), parseOption, pathToBatchExpected);
            }
        }
Ejemplo n.º 2
0
        public static void VerifyCodeFix(string path, string pathToExpected, string pathToBatchExpected,
                                         SonarDiagnosticAnalyzer diagnosticAnalyzer, SonarCodeFixProvider codeFixProvider, string codeFixTitle,
                                         IEnumerable <ParseOptions> options = null,
                                         OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary,
                                         IEnumerable <MetadataReference> additionalReferences = null)
        {
            var document     = CreateDocument(path, outputKind, additionalReferences);
            var parseOptions = ParseOptionsHelper.GetParseOptionsOrDefault(options)
                               .Where(ParseOptionsHelper.GetFilterByLanguage(document.Project.Language))
                               .ToArray();

            foreach (var parseOption in parseOptions)
            {
                RunCodeFixWhileDocumentChanges(diagnosticAnalyzer, codeFixProvider, codeFixTitle, document, parseOption, pathToExpected);
            }

            var fixAllProvider = codeFixProvider.GetFixAllProvider();

            if (fixAllProvider == null)
            {
                return;
            }

            foreach (var parseOption in parseOptions)
            {
                RunFixAllProvider(diagnosticAnalyzer, codeFixProvider, codeFixTitle, fixAllProvider, document, parseOption, pathToBatchExpected);
            }
        }
Ejemplo n.º 3
0
        public IReadOnlyList <Compilation> Compile(params ParseOptions[] parseOptions)
        {
            var options = ParseOptionsHelper.GetParseOptionsOrDefault(parseOptions);

            return(Solution
                   .Projects
                   .SelectMany(project => options
                               .Where(ParseOptionsHelper.GetFilterByLanguage(project.Language))
                               .Select(o => GetCompilation(project, o)))
                   .ToList()
                   .AsReadOnly());
        }