public void VerifySupportedDiagnostics() { var analyzer = new TestMethodUsageAnalyzer(); var diagnostics = analyzer.SupportedDiagnostics; var expectedIdentifiers = new List <string> { AnalyzerIdentifiers.TestMethodExpectedResultTypeMismatchUsage, AnalyzerIdentifiers.TestMethodSpecifiedExpectedResultForVoidUsage, AnalyzerIdentifiers.TestMethodNoExpectedResultButNonVoidReturnType, AnalyzerIdentifiers.TestMethodAsyncNoExpectedResultAndVoidReturnTypeUsage, AnalyzerIdentifiers.TestMethodAsyncNoExpectedResultAndNonTaskReturnTypeUsage, AnalyzerIdentifiers.TestMethodAsyncExpectedResultAndNonGenricTaskReturnTypeUsage }; CollectionAssert.AreEquivalent(expectedIdentifiers, diagnostics.Select(d => d.Id)); foreach (var diagnostic in diagnostics) { Assert.That(diagnostic.Title.ToString(), Is.Not.Empty, $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.Title)}"); Assert.That(diagnostic.Category, Is.EqualTo(Categories.Structure), $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.Category)}"); Assert.That(diagnostic.DefaultSeverity, Is.EqualTo(DiagnosticSeverity.Error), $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.DefaultSeverity)}"); } var diagnosticMessage = diagnostics.Select(_ => _.MessageFormat.ToString()).ToImmutableArray(); Assert.That(diagnosticMessage, Contains.Item(TestMethodUsageAnalyzerConstants.ExpectedResultTypeMismatchMessage), $"{TestMethodUsageAnalyzerConstants.ExpectedResultTypeMismatchMessage} is missing."); Assert.That(diagnosticMessage, Contains.Item(TestMethodUsageAnalyzerConstants.SpecifiedExpectedResultForVoidMethodMessage), $"{TestMethodUsageAnalyzerConstants.SpecifiedExpectedResultForVoidMethodMessage} is missing."); }
public void VerifySupportedDiagnostics() { var analyzer = new TestMethodUsageAnalyzer(); var diagnostics = analyzer.SupportedDiagnostics; Assert.That(diagnostics.Length, Is.EqualTo(2), nameof(DiagnosticAnalyzer.SupportedDiagnostics)); foreach (var diagnostic in diagnostics) { Assert.That(diagnostic.Id, Is.EqualTo(AnalyzerIdentifiers.TestCaseUsage), $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.Id)}"); Assert.That(diagnostic.Title.ToString(), Is.EqualTo(TestMethodUsageAnalyzerConstants.Title), $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.Title)}"); Assert.That(diagnostic.Category, Is.EqualTo(Categories.Usage), $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.Category)}"); Assert.That(diagnostic.DefaultSeverity, Is.EqualTo(DiagnosticSeverity.Error), $"{diagnostic.Id} : {nameof(DiagnosticDescriptor.DefaultSeverity)}"); } var diagnosticMessage = diagnostics.Select(_ => _.MessageFormat.ToString()).ToImmutableArray(); Assert.That(diagnosticMessage, Contains.Item(TestMethodUsageAnalyzerConstants.ExpectedResultTypeMismatchMessage), $"{TestMethodUsageAnalyzerConstants.ExpectedResultTypeMismatchMessage} is missing."); Assert.That(diagnosticMessage, Contains.Item(TestMethodUsageAnalyzerConstants.SpecifiedExpectedResultForVoidMethodMessage), $"{TestMethodUsageAnalyzerConstants.SpecifiedExpectedResultForVoidMethodMessage} is missing."); }