private void AnalyzeNode(SyntaxNodeAnalysisContext context) { var methodDeclaration = (MethodDeclarationSyntax)context.Node; if (!TestMethodHelpers.IsTestCase(methodDeclaration, context)) { return; } if (!IsTestPrametersMoreThanLimit(methodDeclaration)) { return; } context.ReportDiagnostic(Diagnostic.Create(_diagnosticDescriptor, methodDeclaration.GetLocation())); }
private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { var methodDeclaration = context.Node as MethodDeclarationSyntax; if (!TestMethodHelpers.IsTestCase(methodDeclaration, context)) { return; } // check if the method body invokes some kind of Assertion or not if (HasInvokedAssertStaticMethod(methodDeclaration, context) || HasInvokedAssertExtensionMethod(methodDeclaration, context)) { return; } context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); }
private static void AnalyzeNode(SyntaxNodeAnalysisContext context) { var classDeclaration = (ClassDeclarationSyntax)context.Node; if (classDeclaration.BaseList == null) { return; } var hasTestMethod = classDeclaration .ChildNodes() .OfType <MethodDeclarationSyntax>() .Any(x => TestMethodHelpers.IsTestCase(x, context)); if (!hasTestMethod) { return; } context.ReportDiagnostic(Diagnostic.Create(Descriptor, classDeclaration.GetLocation())); }
private void AnalyzeNode(SyntaxNodeAnalysisContext context) { var methodDeclaration = (MethodDeclarationSyntax)context.Node; // ensure is test case if (!TestMethodHelpers.IsTestCase(methodDeclaration, context)) { return; } // ensure name is valid var methodName = methodDeclaration.Identifier.ValueText; if (MatchValidTestName.IsMatch(methodName)) { return; } // report error at position of method name var methodNameToken = methodDeclaration.ChildTokens().First(t => t.IsKind(SyntaxKind.IdentifierToken)); context.ReportDiagnostic(Diagnostic.Create(Descriptor, methodNameToken.GetLocation())); }
private void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context) { var methodSyntax = (MethodDeclarationSyntax)context.Node; var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodSyntax); // check the method is declared in the right namespace if (!MatchNamespaces.Any(r => r.IsMatch(methodSymbol.ContainingNamespace.ToString()))) { return; } // ensure it's a test method if (!TestMethodHelpers.IsTestCase(methodSyntax, context)) { return; } // check if the method has the attribute if (methodSymbol.GetAttributes().Any(a => a.AttributeClass.Name == OWNED_BY_ATTRIBUTE_CLASS_NAME)) { return; } // check if the class has the attribute var classHasAttribute = methodSyntax.Ancestors() .OfType <ClassDeclarationSyntax>() .SelectMany(classDeclarationSyntax => context.SemanticModel.GetDeclaredSymbol(classDeclarationSyntax).GetAttributes()) .Any(a => a.AttributeClass.Name == OWNED_BY_ATTRIBUTE_CLASS_NAME); if (classHasAttribute) { return; } context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation())); }