public static void VerifyCodeFix(string path, string pathToExpected, string pathToBatchExpected, SonarDiagnosticAnalyzer diagnosticAnalyzer, SonarCodeFixProvider codeFixProvider, IEnumerable <ParseOptions> options = null, params MetadataReference[] additionalReferences) { CodeFixVerifier.VerifyCodeFix(path, pathToExpected, pathToBatchExpected, diagnosticAnalyzer, codeFixProvider, null, options, additionalReferences); }
public static void VerifyCodeFix(string path, string pathToExpected, SonarDiagnosticAnalyzer diagnosticAnalyzer, SonarCodeFixProvider codeFixProvider, string codeFixTitle, IEnumerable <ParseOptions> options = null, IEnumerable <MetadataReference> additionalReferences = null) { CodeFixVerifier.VerifyCodeFix(path, pathToExpected, pathToExpected, diagnosticAnalyzer, codeFixProvider, codeFixTitle, options, additionalReferences); }
public static void VerifyNoFix( string source, DiagnosticAnalyzer analyzer, CodeFixProvider fixProvider) { CodeFixVerifier.VerifyNoFix( source: source, analyzer: analyzer, fixProvider: fixProvider, language: LanguageNames.CSharp); }
private static async Task <Diagnostic> GetDiagnosticAsync(Document document) { var diagnostics = await CodeFixVerifier.GetCompilerDiagnosticsAsync(document); Assert.NotEmpty(diagnostics); var methodNameDiagnostic = diagnostics.FirstOrDefault(d => d.Id == "CS1520"); Assert.NotNull(methodNameDiagnostic); return(methodNameDiagnostic); }
public static void VerifyFix( string source, string newSource, DiagnosticAnalyzer analyzer, CodeFixProvider fixProvider, bool allowNewCompilerDiagnostics = false) { CodeFixVerifier.VerifyFix( source: source, newSource: newSource, analyzer: analyzer, fixProvider: fixProvider, language: LanguageNames.CSharp, allowNewCompilerDiagnostics: allowNewCompilerDiagnostics); }
public async Task CodeFixTest(string test, string source, string expected) { var document = DocumentProvider.GetDocument(source); var diagnostic = await GetDiagnosticAsync(document); var actions = new List <CodeAction>(); var context = new CodeFixContext(document, diagnostic, (a, d) => actions.Add(a), CancellationToken.None); await codeFixProvider.RegisterCodeFixesAsync(context); Assert.Single(actions); document = await CodeFixVerifier.ApplyFixAsync(document, actions[0]); var actual = await CodeFixVerifier.GetStringFromDocumentAsync(document); Assert.Equal(expected, actual); }
public async Task Should_trigger_on_generic_struct() { var code = @" using System; using Thinktecture; namespace TestNamespace { [ValueObject] public readonly partial struct {|#0:TestValueObject|}<T> { } }"; var expected = CodeFixVerifier <ThinktectureRuntimeExtensionsAnalyzer, ThinktectureRuntimeExtensionsCodeFixProvider> .Diagnostic(_DIAGNOSTIC_ID).WithLocation(0).WithArguments("Value Object", "TestValueObject<T>"); await CodeFixVerifier <ThinktectureRuntimeExtensionsAnalyzer, ThinktectureRuntimeExtensionsCodeFixProvider> .VerifyAnalyzerAsync(code, new[] { typeof(IEnum <>).Assembly }, expected); }
public async Task Should_trigger_on_generic_struct() { var code = @" using System; using Thinktecture; namespace TestNamespace { public readonly partial struct {|#0:TestEnum|}<T> : IValidatableEnum<string> { public static readonly TestEnum<T> Item1 = default; } }"; var expected = CodeFixVerifier <ThinktectureRuntimeExtensionsAnalyzer, ThinktectureRuntimeExtensionsCodeFixProvider> .Diagnostic(_DIAGNOSTIC_ID).WithLocation(0).WithArguments("Enumeration", "TestEnum<T>"); await CodeFixVerifier <ThinktectureRuntimeExtensionsAnalyzer, ThinktectureRuntimeExtensionsCodeFixProvider> .VerifyAnalyzerAsync(code, new[] { typeof(IEnum <>).Assembly }, expected); }
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/> public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) => CodeFixVerifier <TAnalyzer, TCodeFix> .Diagnostic(descriptor);
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(string)"/> public static DiagnosticResult Diagnostic(string diagnosticId) => CodeFixVerifier <TAnalyzer, TCodeFix> .Diagnostic(diagnosticId);
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic()"/> public static DiagnosticResult Diagnostic() => CodeFixVerifier <TAnalyzer, TCodeFix> .Diagnostic();
public static DiagnosticResult Diagnostic <TDiagnosticAnalyzer, TCodeFix>(string diagnosticId) where TDiagnosticAnalyzer : DiagnosticAnalyzer, new() where TCodeFix : CodeFixProvider, new() => CodeFixVerifier <TDiagnosticAnalyzer, TCodeFix, CSharpCodeFixTest <TDiagnosticAnalyzer, TCodeFix, XUnitVerifier>, XUnitVerifier> .Diagnostic(diagnosticId);