protected override SyntaxNodeAnalyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes cryptTypes)
 {
     SyntaxNodeAnalyzer analyzer = new SyntaxNodeAnalyzer(cryptTypes);
     context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode,
                                      SyntaxKind.InvocationExpression,
                                      SyntaxKind.ObjectCreationExpression);
     return analyzer;
 }
Ejemplo n.º 2
0
            public static void DuplicateId()
            {
                var expected   = "SyntaxNodeAnalyzer.SupportedDiagnostics has more than one descriptor with ID 'ID1'.";
                var analyzer   = new SyntaxNodeAnalyzer(Descriptors.Id1, Descriptors.Id1Duplicate);
                var descriptor = Descriptors.Id1;
                var exception  = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, descriptor, string.Empty));

                Assert.AreEqual(expected, exception.Message);
            }
Ejemplo n.º 3
0
        protected override SyntaxNodeAnalyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes cryptTypes)
        {
            SyntaxNodeAnalyzer analyzer = new SyntaxNodeAnalyzer(cryptTypes);

            context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode,
                                             SyntaxKind.InvocationExpression,
                                             SyntaxKind.ObjectCreationExpression);
            return(analyzer);
        }
Ejemplo n.º 4
0
            public static void DuplicateId()
            {
                var expected           = "SyntaxNodeAnalyzer.SupportedDiagnostics has more than one descriptor with ID 'ID1'.";
                var analyzer           = new SyntaxNodeAnalyzer(Descriptors.Id1, Descriptors.Id1Duplicate);
                var fix                = new DuplicateIdFix();
                var expectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.Id1);
                var exception          = Assert.Throws <AssertException>(() => RoslynAssert.FixAll(analyzer, fix, expectedDiagnostic, string.Empty, string.Empty));

                Assert.AreEqual(expected, exception.Message);
            }
        protected override SyntaxNodeAnalyzer GetAnalyzer(CodeBlockStartAnalysisContext <SyntaxKind> context, CompilationSecurityTypes types)
        {
            SyntaxNodeAnalyzer analyzer = new SyntaxNodeAnalyzer(types, CSharpSyntaxNodeHelper.Default);

            context.RegisterSyntaxNodeAction(
                analyzer.AnalyzeNode,
                SyntaxKind.InvocationExpression,
                SyntaxKind.ObjectCreationExpression,
                SyntaxKind.SimpleAssignmentExpression,
                SyntaxKind.VariableDeclarator);

            return(analyzer);
        }
Ejemplo n.º 6
0
            public static void WithExpectedDiagnosticWithWrongId()
            {
                var code     = @"
namespace N
{
    class C
    {
        private readonly int value1;
    }
}";
                var expected = "SyntaxNodeAnalyzer does not produce a diagnostic with ID 'ID2'.\r\n" +
                               "SyntaxNodeAnalyzer.SupportedDiagnostics: 'ID1'.\r\n" +
                               "The expected diagnostic is: 'ID2'.";

                var descriptor = Descriptors.Id2;
                var analyzer   = new SyntaxNodeAnalyzer(Descriptors.Id1);
                var exception  = Assert.Throws <AssertException>(() => RoslynAssert.Valid(analyzer, descriptor, code));

                Assert.AreEqual(expected, exception.Message);
            }