Skip to content

Commit aaf4a5a

Browse files
committed
Add initial tests for RenderAsMarkdown
1 parent 5be3ae8 commit aaf4a5a

3 files changed

Lines changed: 213 additions & 0 deletions

File tree

DocumentationAnalyzers/DocumentationAnalyzers.CodeFixes/RefactoringRules/DOC900CodeFixProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ private SyntaxNode RenderBlockElementAsMarkdown(SyntaxNode originalNode, SyntaxN
273273
{
274274
case XmlCommentHelper.SummaryXmlTag:
275275
case XmlCommentHelper.RemarksXmlTag:
276+
case XmlCommentHelper.ExampleXmlTag:
276277
case XmlCommentHelper.ReturnsXmlTag:
277278
case XmlCommentHelper.ValueXmlTag:
278279
break;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT license. See LICENSE in the project root for license information.
3+
4+
namespace DocumentationAnalyzers.Test.CSharp7.RefactoringRules
5+
{
6+
using DocumentationAnalyzers.Test.RefactoringRules;
7+
8+
public class DOC900CSharp7UnitTests : DOC900UnitTests
9+
{
10+
}
11+
}
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT license. See LICENSE in the project root for license information.
3+
4+
namespace DocumentationAnalyzers.Test.RefactoringRules
5+
{
6+
using System.Threading.Tasks;
7+
using DocumentationAnalyzers.RefactoringRules;
8+
using Microsoft.CodeAnalysis.CSharp.Testing;
9+
using Microsoft.CodeAnalysis.Testing;
10+
using Microsoft.CodeAnalysis.Testing.Verifiers;
11+
using Xunit;
12+
13+
/// <summary>
14+
/// This class contains unit tests for <see cref="DOC900RenderAsMarkdown"/>.
15+
/// </summary>
16+
public class DOC900UnitTests
17+
{
18+
[Fact]
19+
public async Task TestMultiParagraphSummaryAsync()
20+
{
21+
var testCode = @"
22+
///$$ <summary>
23+
/// Para 1
24+
///
25+
/// Para 2
26+
/// </summary>
27+
class TestClass { }
28+
";
29+
var fixedCode = @"
30+
///$$ <summary>
31+
/// <para>Para 1</para>
32+
/// <para>Para 2</para>
33+
/// </summary>
34+
class TestClass { }
35+
";
36+
37+
await new CSharpCodeFixTest<DOC900RenderAsMarkdown, DOC900CodeFixProvider, XUnitVerifier>
38+
{
39+
TestCode = testCode,
40+
FixedCode = fixedCode,
41+
FixedState = { MarkupHandling = MarkupMode.Allow },
42+
BatchFixedState = { MarkupHandling = MarkupMode.Allow },
43+
44+
// The first iteration fully renders the documentation. The second iteration offers a code fix to render
45+
// documentation, but no changes are made by the fix so the iterations stop.
46+
NumberOfIncrementalIterations = 2,
47+
}.RunAsync();
48+
}
49+
50+
[Fact]
51+
public async Task TestBulletedListAsync()
52+
{
53+
var testCode = @"
54+
///$$ <summary>
55+
/// Para 1
56+
///
57+
/// * Item 1
58+
/// * Item 2
59+
/// * Item 3
60+
/// </summary>
61+
class TestClass { }
62+
";
63+
var fixedCode = @"
64+
///$$ <summary>
65+
/// <para>Para 1</para>
66+
/// <list type=""bullet"">
67+
/// <item>Item 1</item>
68+
/// <item>Item 2</item>
69+
/// <item>Item 3</item>
70+
/// </list>
71+
/// </summary>
72+
class TestClass { }
73+
";
74+
75+
await new CSharpCodeFixTest<DOC900RenderAsMarkdown, DOC900CodeFixProvider, XUnitVerifier>
76+
{
77+
TestCode = testCode,
78+
FixedCode = fixedCode,
79+
FixedState = { MarkupHandling = MarkupMode.Allow },
80+
BatchFixedState = { MarkupHandling = MarkupMode.Allow },
81+
82+
// The first iteration fully renders the documentation. The second iteration offers a code fix to render
83+
// documentation, but no changes are made by the fix so the iterations stop.
84+
NumberOfIncrementalIterations = 2,
85+
}.RunAsync();
86+
}
87+
88+
[Fact]
89+
public async Task TestNumberedListAsync()
90+
{
91+
var testCode = @"
92+
///$$ <summary>
93+
/// Para 1
94+
///
95+
/// 1. Item 1
96+
/// 1. Item 2
97+
/// 1. Item 3
98+
/// </summary>
99+
class TestClass { }
100+
";
101+
var fixedCode = @"
102+
///$$ <summary>
103+
/// <para>Para 1</para>
104+
/// <list type=""number"">
105+
/// <item>Item 1</item>
106+
/// <item>Item 2</item>
107+
/// <item>Item 3</item>
108+
/// </list>
109+
/// </summary>
110+
class TestClass { }
111+
";
112+
113+
await new CSharpCodeFixTest<DOC900RenderAsMarkdown, DOC900CodeFixProvider, XUnitVerifier>
114+
{
115+
TestCode = testCode,
116+
FixedCode = fixedCode,
117+
FixedState = { MarkupHandling = MarkupMode.Allow },
118+
BatchFixedState = { MarkupHandling = MarkupMode.Allow },
119+
120+
// The first iteration fully renders the documentation. The second iteration offers a code fix to render
121+
// documentation, but no changes are made by the fix so the iterations stop.
122+
NumberOfIncrementalIterations = 2,
123+
}.RunAsync();
124+
}
125+
126+
[Fact]
127+
public async Task TestExampleCodeAsync()
128+
{
129+
var testCode = @"
130+
///$$ <summary>
131+
/// Summary text
132+
/// </summary>
133+
/// <example>
134+
/// The following example shows constructing a new `TestClass` instance:
135+
///
136+
/// ```csharp
137+
/// var x = new TestClass();
138+
/// ```
139+
/// </example>
140+
class TestClass { }
141+
";
142+
var fixedCode = @"
143+
///$$ <summary>
144+
/// Summary text
145+
/// </summary>
146+
/// <example>
147+
/// <para>The following example shows constructing a new <c>TestClass</c> instance:</para>
148+
/// <code language=""csharp"">
149+
/// var x = new TestClass();
150+
/// </code>
151+
/// </example>
152+
class TestClass { }
153+
";
154+
155+
await new CSharpCodeFixTest<DOC900RenderAsMarkdown, DOC900CodeFixProvider, XUnitVerifier>
156+
{
157+
TestCode = testCode,
158+
FixedCode = fixedCode,
159+
FixedState = { MarkupHandling = MarkupMode.Allow },
160+
BatchFixedState = { MarkupHandling = MarkupMode.Allow },
161+
162+
// The first iteration fully renders the documentation. The second iteration offers a code fix to render
163+
// documentation, but no changes are made by the fix so the iterations stop.
164+
NumberOfIncrementalIterations = 2,
165+
}.RunAsync();
166+
}
167+
168+
[Fact]
169+
public async Task TestParameterReferenceAsync()
170+
{
171+
var testCode = @"
172+
class TestClass {
173+
///$$ <summary>
174+
/// Provide a value for `param`.
175+
/// </summary>
176+
void Method(int param) { }
177+
}
178+
";
179+
var fixedCode = @"
180+
class TestClass {
181+
///$$ <summary>
182+
/// Provide a value for <c>param</c>.
183+
/// </summary>
184+
void Method(int param) { }
185+
}
186+
";
187+
188+
await new CSharpCodeFixTest<DOC900RenderAsMarkdown, DOC900CodeFixProvider, XUnitVerifier>
189+
{
190+
TestCode = testCode,
191+
FixedCode = fixedCode,
192+
FixedState = { MarkupHandling = MarkupMode.Allow },
193+
BatchFixedState = { MarkupHandling = MarkupMode.Allow },
194+
195+
// The first iteration fully renders the documentation. The second iteration offers a code fix to render
196+
// documentation, but no changes are made by the fix so the iterations stop.
197+
NumberOfIncrementalIterations = 2,
198+
}.RunAsync();
199+
}
200+
}
201+
}

0 commit comments

Comments
 (0)