@@ -508,5 +508,81 @@ public void Test()
508508 } ;
509509 await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
510510 }
511+
512+ [ Theory ]
513+ [ InlineData ( "Method1" , "arg" , true ) ]
514+ [ InlineData ( "Method2" , "arg" , true ) ]
515+ [ InlineData ( "Method1" , "field1" , true ) ]
516+ [ InlineData ( "Method2" , "field1" , true ) ]
517+ [ InlineData ( "Method1" , "field2" , true ) ]
518+ [ InlineData ( "Method2" , "field2" , true ) ]
519+ [ InlineData ( "Const1" , "Method1" , false ) ]
520+ [ InlineData ( "Const1" , "Method2" , false ) ]
521+ [ InlineData ( "Method1" , "Const1" , false ) ]
522+ [ InlineData ( "Method2" , "Const1" , false ) ]
523+ [ WorkItem ( 3677 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3677" ) ]
524+ public async Task TestMethodsAsync ( string expr1 , string expr2 , bool shouldTrigger )
525+ {
526+ var testExpr = $ "{ expr1 } == { expr2 } ";
527+ var testCode = $@ "
528+ using System;
529+
530+ public class TestClass
531+ {{
532+ private static readonly Action Const1 = Method1;
533+
534+ private Action field1 = Method1;
535+ private readonly Action field2 = Method1;
536+
537+ public bool TestMethod(Action arg)
538+ {{
539+ return { ( shouldTrigger ? $ "[|{ testExpr } |]" : testExpr ) } ;
540+ }}
541+
542+ private static void Method1()
543+ {{
544+ }}
545+
546+ private void Method2()
547+ {{
548+ }}
549+ }}
550+ " ;
551+
552+ var fixedExpr = $ "{ expr2 } == { expr1 } ";
553+ var fixedCode = $@ "
554+ using System;
555+
556+ public class TestClass
557+ {{
558+ private static readonly Action Const1 = Method1;
559+
560+ private Action field1 = Method1;
561+ private readonly Action field2 = Method1;
562+
563+ public bool TestMethod(Action arg)
564+ {{
565+ return { fixedExpr } ;
566+ }}
567+
568+ private static void Method1()
569+ {{
570+ }}
571+
572+ private void Method2()
573+ {{
574+ }}
575+ }}
576+ " ;
577+
578+ if ( shouldTrigger )
579+ {
580+ await VerifyCSharpFixAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
581+ }
582+ else
583+ {
584+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
585+ }
586+ }
511587 }
512588}
0 commit comments