Ejemplo n.º 1
0
        private async Task TestBasicCore(string source, DiagnosticResult missingGetFixAllProviderOverrideDiagnostic,
                                         bool withCustomCodeActions = false, CompilerDiagnostics compilerDiagnostics = CompilerDiagnostics.Errors,
                                         params DiagnosticResult[] expected)
        {
            var fixAllProviderString = @"Public Overrides Function GetFixAllProvider() As FixAllProvider
	Return WellKnownFixAllProviders.BatchFixer
End Function
";

            var sourceSuffix = @"
End Class
";

            if (withCustomCodeActions)
            {
                sourceSuffix += VisualBasicCustomCodeActions;
            }

            // Verify expected diagnostics for fixer that supports FixAllProvider.
            await VerifyVB.VerifyAnalyzerAsync(source + fixAllProviderString + sourceSuffix, compilerDiagnostics, expected);

            // Verify RS1016 (OverrideGetFixAllProviderRule) diagnostic for fixer that does not support FixAllProvider.
            expected = new DiagnosticResult[] { missingGetFixAllProviderOverrideDiagnostic };
            await VerifyVB.VerifyAnalyzerAsync(source + sourceSuffix, compilerDiagnostics, expected);
        }
Ejemplo n.º 2
0
        public static async Task VerifyAnalyzerAsync(string source, CompilerDiagnostics compilerDiagnostics, params DiagnosticResult[] expected)
        {
            var test = new Test
            {
                TestCode            = source,
                CompilerDiagnostics = compilerDiagnostics
            };

            test.ExpectedDiagnostics.AddRange(expected);
            await test.RunAsync();
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        protected override bool IsCompilerDiagnosticIncluded(Diagnostic diagnostic, CompilerDiagnostics compilerDiagnostics)
        {
            if (base.IsCompilerDiagnosticIncluded(diagnostic, compilerDiagnostics))
            {
                return(true);
            }

            return(CodeFixProvidersHandleDiagnostic(diagnostic));

            bool CodeFixProvidersHandleDiagnostic(Diagnostic localDiagnostic)
            {
                var codeFixProviders = GetCodeFixProviders();

                return(codeFixProviders
                       .Any(provider => provider.FixableDiagnosticIds.Any(fixerDiagnosticId => string.Equals(fixerDiagnosticId, localDiagnostic.Id, StringComparison.OrdinalIgnoreCase))));
            }
        }
Ejemplo n.º 4
0
        private async Task TestCSharpCoreAsync(string source, DiagnosticResult missingGetFixAllProviderOverrideDiagnostic,
                                               bool withCustomCodeActions = false, CompilerDiagnostics compilerDiagnostics = CompilerDiagnostics.Errors,
                                               params DiagnosticResult[] expected)
        {
            var fixAllProviderString = @"public override FixAllProvider GetFixAllProvider()
    {
        return WellKnownFixAllProviders.BatchFixer;
    }";

            var sourceSuffix = @"
}";

            if (withCustomCodeActions)
            {
                sourceSuffix += CSharpCustomCodeActions;
            }

            // Verify expected diagnostics for fixer that supports FixAllProvider.
            await VerifyCS.VerifyAnalyzerAsync(source + fixAllProviderString + sourceSuffix, compilerDiagnostics, expected);

            // Verify RS1016 (OverrideGetFixAllProviderRule) diagnostic for fixer that does not support FixAllProvider.
            expected = new DiagnosticResult[] { missingGetFixAllProviderOverrideDiagnostic };
            await VerifyCS.VerifyAnalyzerAsync(source + sourceSuffix, compilerDiagnostics, expected);
        }
            protected override bool IsCompilerDiagnosticIncluded(Diagnostic diagnostic, CompilerDiagnostics compilerDiagnostics)
            {
                if (_ignoreSuppressedDiagnostics && diagnostic.IsSuppressed)
                {
                    return(false);
                }

                return(base.IsCompilerDiagnosticIncluded(diagnostic, compilerDiagnostics));
            }
Ejemplo n.º 6
0
 public IEnumerable <Diagnostic> GetAllDiagnostics()
 {
     return(CompilerDiagnostics.Concat(Diagnostics));
 }
Ejemplo n.º 7
0
 // CS8795: Partial method '{0}' must have an implementation part because it has accessibility modifiers.
 protected override bool IsCompilerDiagnosticIncluded(Diagnostic diagnostic, CompilerDiagnostics compilerDiagnostics) => base.IsCompilerDiagnosticIncluded(diagnostic, compilerDiagnostics) && diagnostic.Id != "CS8795";