44namespace StyleCop . Analyzers . Test . DocumentationRules
55{
66 using System . Collections . Generic ;
7+ using System . Threading ;
78 using System . Threading . Tasks ;
89 using Microsoft . CodeAnalysis . CodeFixes ;
910 using Microsoft . CodeAnalysis . Diagnostics ;
@@ -17,9 +18,9 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1718 public class InheritdocCodeFixProviderUnitTests : CodeFixVerifier
1819 {
1920 [ Theory ]
20- [ InlineData ( "string TestMember { get; set; }" ) ]
21- [ InlineData ( "string TestMember() { return null; }" ) ]
22- [ InlineData ( "string this[int a] { get { return \" a\" ; } set { } }" ) ]
21+ [ InlineData ( "string TestMember { get; set; }" ) ]
22+ [ InlineData ( "string TestMember() { return null; }" ) ]
23+ [ InlineData ( "string this[int a] { get { return \" a\" ; } set { } }" ) ]
2324 [ InlineData ( "event EventHandler TestMember { add { } remove { } }" ) ]
2425 public async Task TestClassVirtualInheritedMembersAsync ( string memberData )
2526 {
@@ -54,13 +55,28 @@ public override {memberData}
5455}}
5556" ;
5657
57- await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
58+ DiagnosticResult [ ] expected =
59+ {
60+ this . CSharpDiagnostic ( ) . WithLocation ( 2 , 14 ) ,
61+ this . CSharpDiagnostic ( ) . WithLocation ( 10 , 14 ) ,
62+ this . CSharpDiagnostic ( ) . WithLocation ( 12 , 40 ) ,
63+ } ;
64+
65+ DiagnosticResult [ ] expectedFixed =
66+ {
67+ this . CSharpDiagnostic ( ) . WithLocation ( 2 , 14 ) ,
68+ this . CSharpDiagnostic ( ) . WithLocation ( 10 , 14 ) ,
69+ } ;
70+
71+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
72+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , expectedFixed , CancellationToken . None ) . ConfigureAwait ( false ) ;
73+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
5874 }
5975
6076 [ Theory ]
61- [ InlineData ( "string TestMember { get; set; }" , "string TestMember { get; set; }" ) ]
62- [ InlineData ( "string TestMember();" , "string TestMember() { return null; }" ) ]
63- [ InlineData ( "string this[int a] { get; set; }" , "string this[int a] { get { return \" a\" ; } set { } }" ) ]
77+ [ InlineData ( "string TestMember { get; set; }" , "string TestMember { get; set; }" ) ]
78+ [ InlineData ( "string TestMember();" , "string TestMember() { return null; }" ) ]
79+ [ InlineData ( "string this[int a] { get; set; }" , "string this[int a] { get { return \" a\" ; } set { } }" ) ]
6480 [ InlineData ( "event EventHandler TestMember;" , "event EventHandler TestMember { add { } remove { } }" ) ]
6581 public async Task TestInterfaceInheritedMembersAsync ( string parentData , string childData )
6682 {
@@ -95,13 +111,28 @@ public class ChildClass : IParent
95111}}
96112" ;
97113
98- await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
114+ DiagnosticResult [ ] expected =
115+ {
116+ this . CSharpDiagnostic ( ) . WithLocation ( 2 , 18 ) ,
117+ this . CSharpDiagnostic ( ) . WithLocation ( 10 , 14 ) ,
118+ this . CSharpDiagnostic ( ) . WithLocation ( 12 , 31 ) ,
119+ } ;
120+
121+ DiagnosticResult [ ] expectedFixed =
122+ {
123+ this . CSharpDiagnostic ( ) . WithLocation ( 2 , 18 ) ,
124+ this . CSharpDiagnostic ( ) . WithLocation ( 10 , 14 ) ,
125+ } ;
126+
127+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
128+ await this . VerifyCSharpDiagnosticAsync ( fixedCode , expectedFixed , CancellationToken . None ) . ConfigureAwait ( false ) ;
129+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
99130 }
100131
101132 [ Theory ]
102- [ InlineData ( "string TestMember { get; set; }" ) ]
103- [ InlineData ( "string TestMember() { return null; }" ) ]
104- [ InlineData ( "string this[int a] { get { return \" a\" ; } set { } }" ) ]
133+ [ InlineData ( "string TestMember { get; set; }" ) ]
134+ [ InlineData ( "string TestMember() { return null; }" ) ]
135+ [ InlineData ( "string this[int a] { get { return \" a\" ; } set { } }" ) ]
105136 [ InlineData ( "event EventHandler TestMember { add { } remove { } }" ) ]
106137 public async Task TestNonvirtualHiddenInheritedMembersAsync ( string memberData )
107138 {
@@ -120,28 +151,21 @@ public class ChildClass : ParentClass
120151}}
121152" ;
122153
123- var fixedCode = $@ "using System;
124- public class ParentClass
125- {{
126- /// <summary>
127- /// Some documentation.
128- /// </summary>
129- public { memberData }
130- }}
131-
132- public class ChildClass : ParentClass
133- {{
134- public new { memberData }
135- }}
136- " ;
154+ DiagnosticResult [ ] expected =
155+ {
156+ this . CSharpDiagnostic ( ) . WithLocation ( 2 , 14 ) ,
157+ this . CSharpDiagnostic ( ) . WithLocation ( 10 , 14 ) ,
158+ this . CSharpDiagnostic ( ) . WithLocation ( 12 , 35 ) ,
159+ } ;
137160
138- await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
161+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
162+ await this . VerifyCSharpFixAsync ( testCode , testCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
139163 }
140164
141165 [ Theory ]
142- [ InlineData ( "string TestMember { get; set; }" ) ]
143- [ InlineData ( "string TestMember() { return null; }" ) ]
144- [ InlineData ( "string this[int a] { get { return \" a\" ; } set { } }" ) ]
166+ [ InlineData ( "string TestMember { get; set; }" ) ]
167+ [ InlineData ( "string TestMember() { return null; }" ) ]
168+ [ InlineData ( "string this[int a] { get { return \" a\" ; } set { } }" ) ]
145169 [ InlineData ( "event EventHandler TestMember { add { } remove { } }" ) ]
146170 public async Task TestVirtualHiddenInheritedMembersAsync ( string memberData )
147171 {
@@ -160,22 +184,17 @@ public class ChildClass : ParentClass
160184}}
161185" ;
162186
163- var fixedCode = $@ "using System;
164- public class ParentClass
165- {{
166- /// <summary>
167- /// Some documentation.
168- /// </summary>
169- public virtual { memberData }
170- }}
187+ var fixedCode = testCode ;
171188
172- public class ChildClass : ParentClass
173- {{
174- public new { memberData }
175- }}
176- " ;
189+ DiagnosticResult [ ] expected =
190+ {
191+ this . CSharpDiagnostic ( ) . WithLocation ( 2 , 14 ) ,
192+ this . CSharpDiagnostic ( ) . WithLocation ( 10 , 14 ) ,
193+ this . CSharpDiagnostic ( ) . WithLocation ( 12 , 35 ) ,
194+ } ;
177195
178- await this . VerifyCSharpFixAsync ( testCode , fixedCode ) . ConfigureAwait ( false ) ;
196+ await this . VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
197+ await this . VerifyCSharpFixAsync ( testCode , fixedCode , cancellationToken : CancellationToken . None ) . ConfigureAwait ( false ) ;
179198 }
180199
181200 /// <inheritdoc/>
0 commit comments