private IEnumerable <TestAttributes> GetSampleData() { List <TestAttributes> result = new List <TestAttributes>(); foreach (string L in _lorem) { foreach (string N in _nullam) { foreach (string Q in _quisque) { foreach (string A in _aliquam) { TestAttributes t = new TestAttributes { Attributes = new Dictionary <string, string>(), val = 1 }; t.Attributes.Add("Lorem", L); t.Attributes.Add("Nullam", N); t.Attributes.Add("Quisque", Q); t.Attributes.Add("Aliquam", A); result.Add(t); } } } } return(result); }
private void Analyze(SyntaxNodeAnalysisContext context) { MethodDeclarationSyntax methodDeclaration = (MethodDeclarationSyntax)context.Node; TestAttributes attributes = TestAttributes.None; foreach (var kvp in _attributes) { if ((kvp.Value & _interestedAttributes) == 0) { continue; } if (!Helper.HasAttribute(methodDeclaration.AttributeLists, context, kvp.Key)) { continue; } attributes |= kvp.Value; } if (attributes != TestAttributes.None) { OnTestAttributeMethod(context, methodDeclaration, attributes); } }
private IEnumerable<TestAttributes> GetSampleData() { List<TestAttributes> result = new List<TestAttributes>(); foreach (string L in Lorem) { foreach (string N in Nullam) { foreach (string Q in Quisque) { foreach (string A in Aliquam) { TestAttributes t = new TestAttributes { Attributes = new Dictionary<string, string>(), val = 1 }; t.Attributes.Add("Lorem", L); t.Attributes.Add("Nullam", N); t.Attributes.Add("Quisque", Q); t.Attributes.Add("Aliquam", A); result.Add(t); } } } } return result; }
protected override void OnTestAttributeMethod(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax methodDeclaration, TestAttributes attributes) { if (methodDeclaration.Body == null) { //during the intellisense phase the body of a method can be non-existent. return; } if (methodDeclaration.Body.Statements.Any()) { //not empty return; } context.ReportDiagnostic(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation(), methodDeclaration.Identifier)); }
protected abstract void OnTestAttributeMethod(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax methodDeclaration, TestAttributes attributes);
protected TestAttributeDiagnosticAnalyzer(TestAttributes interestedAttributes) { _interestedAttributes = interestedAttributes; }
protected override void OnTestAttributeMethod(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax methodDeclaration, TestAttributes attributes) { bool isTestMethod = attributes.HasFlag(TestAttributes.TestMethod); bool isDataTestMethod = attributes.HasFlag(TestAttributes.DataTestMethod); if (!isTestMethod && !isDataTestMethod) { return; } OnTestMethod(context, methodDeclaration, isDataTestMethod); }
protected override void OnTestAttributeMethod(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax methodDeclaration, TestAttributes attributes) { if (Helper.IsInTestClass(context)) { return; } var symbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration); if (symbol != null && symbol.ContainingType.IsAbstract) { return; } context.ReportDiagnostic(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation(), methodDeclaration.Identifier)); }
protected override void OnTestAttributeMethod(SyntaxNodeAnalysisContext context, MethodDeclarationSyntax methodDeclaration, TestAttributes attributes) { if (Helper.IsInTestClass(context)) { return; } context.ReportDiagnostic(Diagnostic.Create(Rule, methodDeclaration.Identifier.GetLocation(), methodDeclaration.Identifier)); }