@@ -7,7 +7,7 @@ public static class CodeFix
77{
88 private static readonly RoutedEventCallbackAnalyzer Analyzer = new ( ) ;
99 private static readonly RenameMemberFix Fix = new ( ) ;
10- private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic . Create ( Descriptors . WPF0091AddAndRemoveHandlerCallbackNameShouldMatchEvent ) ;
10+ private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic . Create ( Descriptors . WPF0091CallbackNameShouldMatchEvent ) ;
1111
1212 [ Test ]
1313 public static void MessageAddHandler ( )
@@ -61,8 +61,9 @@ private static void WrongName(object sender, RoutedEventArgs e)
6161 RoslynAssert . Diagnostics ( Analyzer , ExpectedDiagnostic . WithMessage ( "Rename to OnSizeChanged to match the event" ) , code ) ;
6262 }
6363
64- [ Test ]
65- public static void WhenCorrectNameAddHandlerSizeChangedEvent ( )
64+ [ TestCase ( "new RoutedEventHandler(↓WrongName)" , "new RoutedEventHandler(OnSizeChanged)" ) ]
65+ [ TestCase ( "new RoutedEventHandler((o, e) => ↓WrongName(o, e))" , "new RoutedEventHandler((o, e) => OnSizeChanged(o, e))" ) ]
66+ public static void WhenCorrectNameAddHandlerSizeChangedEvent ( string beforeExpression , string afterExpression )
6667 {
6768 var before = @"
6869namespace N
@@ -82,7 +83,7 @@ private static void WrongName(object sender, RoutedEventArgs e)
8283 throw new System.NotImplementedException();
8384 }
8485 }
85- }" ;
86+ }" . AssertReplace ( "new RoutedEventHandler(↓WrongName)" , beforeExpression ) ;
8687
8788 var after = @"
8889namespace N
@@ -102,12 +103,13 @@ private static void OnSizeChanged(object sender, RoutedEventArgs e)
102103 throw new System.NotImplementedException();
103104 }
104105 }
105- }" ;
106+ }" . AssertReplace ( "new RoutedEventHandler(OnSizeChanged)" , afterExpression ) ;
106107 RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
107108 }
108109
109- [ Test ]
110- public static void WhenCorrectNameRemoveHandlerSizeChangedEvent ( )
110+ [ TestCase ( "new RoutedEventHandler(↓WrongName)" , "new RoutedEventHandler(OnSizeChanged)" ) ]
111+ [ TestCase ( "new RoutedEventHandler((o, e) => ↓WrongName(o, e))" , "new RoutedEventHandler((o, e) => OnSizeChanged(o, e))" ) ]
112+ public static void WhenCorrectNameRemoveHandlerSizeChangedEvent ( string beforeExpression , string afterExpression )
111113 {
112114 var before = @"
113115namespace N
@@ -127,7 +129,7 @@ private static void WrongName(object sender, RoutedEventArgs e)
127129 throw new System.NotImplementedException();
128130 }
129131 }
130- }" ;
132+ }" . AssertReplace ( "new RoutedEventHandler(↓WrongName)" , beforeExpression ) ;
131133
132134 var after = @"
133135namespace N
@@ -147,7 +149,7 @@ private static void OnSizeChanged(object sender, RoutedEventArgs e)
147149 throw new System.NotImplementedException();
148150 }
149151 }
150- }" ;
152+ }" . AssertReplace ( "new RoutedEventHandler(OnSizeChanged)" , afterExpression ) ;
151153 RoslynAssert . CodeFix ( Analyzer , Fix , ExpectedDiagnostic , before , after ) ;
152154 }
153155
0 commit comments