Skip to content

Commit 71afe9b

Browse files
committed
Add tests for <include> elements referencing missing content
1 parent 046752f commit 71afe9b

File tree

9 files changed

+136
-1
lines changed

9 files changed

+136
-1
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1608UnitTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ public class ClassName
185185
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
186186
}
187187

188+
[Fact]
189+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
190+
public async Task TestClassWithIncludedMissingDocumentationAsync()
191+
{
192+
var testCode = @"
193+
/// <include file='MissingFile.xml' path='/ClassName/*' />
194+
public class ClassName
195+
{
196+
}";
197+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
198+
}
199+
188200
[Fact]
189201
public async Task TestClassWithIncludedSummaryDocumentationAsync()
190202
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1611UnitTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,36 @@ public void TestMethod(string param1, string param2, string param3)
312312
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
313313
}
314314

315+
/// <summary>
316+
/// Verifies that included documentation with missing documentation file produces no diagnostics.
317+
/// </summary>
318+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
319+
[Fact]
320+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
321+
public async Task VerifyIncludedMissingDocumentationAsync()
322+
{
323+
var testCode = @"
324+
/// <summary>
325+
/// Foo
326+
/// </summary>
327+
public class ClassName
328+
{
329+
/// <include file='MissingFile.xml' path='/TestClass/TestMethod/*' />
330+
public void TestMethod(string {|#0:param1|}, string {|#1:param2|}, string {|#2:param3|})
331+
{
332+
}
333+
}";
334+
335+
DiagnosticResult[] expected =
336+
{
337+
Diagnostic().WithLocation(0).WithArguments("param1"),
338+
Diagnostic().WithLocation(1).WithArguments("param2"),
339+
Diagnostic().WithLocation(2).WithArguments("param3"),
340+
};
341+
342+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
343+
}
344+
315345
/// <summary>
316346
/// Verifies that included documentation with missing elements documented produces the expected diagnostics.
317347
/// </summary>

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1612UnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,22 @@ public class ClassName
285285
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
286286
}
287287

288+
[Fact]
289+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
290+
public async Task VerifyIncludedMissingFileIsNotReportedAsync()
291+
{
292+
var testCode = @"
293+
/// <summary>
294+
/// Foo
295+
/// </summary>
296+
public class ClassName
297+
{
298+
/// <include file='MissingFile.xml' path='/ClassName/Method/*' />
299+
public ClassName Method() { return null; }
300+
}";
301+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
302+
}
303+
288304
[Fact]
289305
public async Task VerifyIncludedMemberWithValidParamsIsNotReportedAsync()
290306
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1613UnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ public class ClassName
154154
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
155155
}
156156

157+
[Fact]
158+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
159+
public async Task VerifyIncludedMissingFileAsync()
160+
{
161+
var testCode = @"
162+
/// <summary>
163+
/// Foo
164+
/// </summary>
165+
public class ClassName
166+
{
167+
/// <include file='MissingFile.xml' path='/ClassName/Method/*' />
168+
public ClassName Method(string foo, string bar) { return null; }
169+
}";
170+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
171+
}
172+
157173
[Fact]
158174
public async Task VerifyMemberWithValidParamsAndIncludedDocumentationAsync()
159175
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1614UnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ public class ClassName
154154
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
155155
}
156156

157+
[Fact]
158+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
159+
public async Task VerifyIncludedMissingFileAsync()
160+
{
161+
var testCode = @"
162+
/// <summary>
163+
/// Foo
164+
/// </summary>
165+
public class ClassName
166+
{
167+
/// <include file='MissingFile.xml' path='/ClassName/Method/*' />
168+
public ClassName Method(string foo, string bar) { return null; }
169+
}";
170+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
171+
}
172+
157173
[Fact]
158174
public async Task VerifyMemberIncludedDocumentationWithoutParamsAsync()
159175
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1616UnitTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,22 @@ public class ClassName
443443
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
444444
}
445445

446+
[Fact]
447+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
448+
public async Task VerifyMemberIncludedMissingFileAsync()
449+
{
450+
var testCode = @"
451+
/// <summary>
452+
/// Foo
453+
/// </summary>
454+
public class ClassName
455+
{
456+
/// <include file='MissingFile.xml' path='/ClassName/Method/*' />
457+
public ClassName Method(string foo, string bar) { return null; }
458+
}";
459+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
460+
}
461+
446462
[Fact]
447463
public async Task VerifyMemberIncludedDocumentationWithoutReturnsAsync()
448464
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1625UnitTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,21 @@ public class TestClass2 {{ }}
321321
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
322322
}
323323

324+
[Fact]
325+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
326+
public async Task VerifyThatMissingIncludedDocumentationDoesNotReportADiagnosticAsync()
327+
{
328+
var testCode = $@"
329+
public class TestClass
330+
{{
331+
/// <include file='MissingFile.xml' path='/TestClass/Test/*' />
332+
public void Test() {{ }}
333+
}}
334+
public class TestClass2 {{ }}
335+
";
336+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
337+
}
338+
324339
[Fact]
325340
public async Task VerifyThatTheAnalyzerDoesNotCrashOnIncludedInheritDocAsync()
326341
{

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1629UnitTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ public class TestClass
315315
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
316316
}
317317

318+
[Fact]
319+
[WorkItem(3150, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3150")]
320+
public async Task TestIncludedMissingFileAsync()
321+
{
322+
var testCode = @"
323+
/// <include file='MissingFile.xml' path='/TestClass/*'/>
324+
public class TestClass
325+
{
326+
}
327+
";
328+
329+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
330+
}
331+
318332
[Fact]
319333
[WorkItem(2680, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2680")]
320334
public async Task TestReportingAfterEmptyElementAsync()

StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="1.3.2" />
21-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.1-beta1.20623.3" />
21+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.1-beta1.21159.2" />
2222
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="16.1.8" />
2323
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2424
<PackageReference Include="xunit" Version="2.4.1" />

0 commit comments

Comments
 (0)