public static void VerifyNoDiagnostic( IEnumerable <string> sources, DiagnosticDescriptor descriptor, DiagnosticAnalyzer analyzer, string language) { Assert.True(analyzer.Supports(descriptor), $"Diagnostic \"{descriptor.Id}\" is not supported by analyzer \"{analyzer.GetType().Name}\"."); IEnumerable <Document> documents = WorkspaceFactory.CreateDocuments(sources, language); VerifyNoCompilerError(documents); Diagnostic[] diagnostics = DiagnosticUtility.GetSortedDiagnostics(documents, analyzer); Assert.True(diagnostics.Length == 0 || diagnostics.All(f => !string.Equals(f.Id, descriptor.Id, StringComparison.Ordinal)), $"No diagnostic expected{diagnostics.Where(f => string.Equals(f.Id, descriptor.Id, StringComparison.Ordinal)).ToDebugString()}"); }
public static void VerifyDiagnostic( IEnumerable <string> sources, DiagnosticAnalyzer analyzer, string language, params Diagnostic[] expectedDiagnostics) { foreach (Diagnostic diagnostic in expectedDiagnostics) { Assert.True(analyzer.Supports(diagnostic.Descriptor), $"Diagnostic \"{diagnostic.Descriptor.Id}\" is not supported by analyzer \"{analyzer.GetType().Name}\"."); } Diagnostic[] diagnostics = DiagnosticUtility.GetSortedDiagnostics(sources, analyzer, language); if (diagnostics.Length > 0 && analyzer.SupportedDiagnostics.Length > 1) { diagnostics = diagnostics .Where(diagnostic => expectedDiagnostics.Any(expectedDiagnostic => DiagnosticComparer.Id.Equals(diagnostic, expectedDiagnostic))) .ToArray(); } VerifyDiagnostics(diagnostics, expectedDiagnostics); }