Skip to content

Commit 89f57f7

Browse files
committed
Add SA1623/SA1624 tests for expression-bodied members
1 parent 995e93d commit 89f57f7

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1623UnitTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ public class SA1623UnitTests : CodeFixVerifier
3232
[InlineData("public", "int", "{ get; internal set; }", "Gets")]
3333
[InlineData("public", "int", "{ get; private set; }", "Gets")]
3434
[InlineData("public", "int", "{ get; }", "Gets")]
35+
[InlineData("public", "int", "{ get; } = 0;", "Gets")]
36+
[InlineData("public", "int", "=> 0;", "Gets")]
3537
[InlineData("public", "int", "{ set { } }", "Sets")]
3638
[InlineData("public", "int", "{ internal get { return 0; } set { } }", "Sets")]
3739
[InlineData("public", "int", "{ private get { return 0; } set { } }", "Sets")]
3840
[InlineData("public", "bool", "{ get; set; }", "Gets or sets a value indicating whether")]
3941
[InlineData("public", "bool", "{ get; }", "Gets a value indicating whether")]
42+
[InlineData("public", "bool", "{ get; } = true;", "Gets a value indicating whether")]
43+
[InlineData("public", "bool", "=> true;", "Gets a value indicating whether")]
4044
[InlineData("public", "bool", "{ get; private set; }", "Gets a value indicating whether")]
4145
[InlineData("public", "bool", "{ set { } }", "Sets a value indicating whether")]
4246
[InlineData("public", "bool", "{ private get { return false; } set { } }", "Sets a value indicating whether")]

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1624UnitTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,36 @@ public class TestClass
7777
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
7878
}
7979

80+
/// <summary>
81+
/// Verifies that documentation that starts with the proper text for multiple accessors will not produce this
82+
/// diagnostic when the property has an expression body.
83+
/// </summary>
84+
/// <param name="accessibility">The accessibility of the property.</param>
85+
/// <param name="type">The type to use for the property.</param>
86+
/// <param name="summaryPrefix">The prefix to use in the summary text.</param>
87+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
88+
[Theory]
89+
[InlineData("public", "int", "Gets or sets")]
90+
[InlineData("public", "bool", "Gets or sets a value indicating whether")]
91+
[InlineData("protected", "int", "Gets or sets")]
92+
[InlineData("protected internal", "int", "Gets or sets")]
93+
[InlineData("internal", "int", "Gets or sets")]
94+
public async Task VerifyThatInvalidDocumentationWillReportDiagnosticForExpressionBodyAsync(string accessibility, string type, string summaryPrefix)
95+
{
96+
var testCode = $@"
97+
public class TestClass
98+
{{
99+
/// <summary>
100+
/// {summaryPrefix} the test property.
101+
/// </summary>
102+
{accessibility} {type} TestProperty =>
103+
default({type});
104+
}}
105+
";
106+
107+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
108+
}
109+
80110
/// <summary>
81111
/// Verify that no diagnostic will be reported when a public and a private accessor are present within a property that is defined in a contained class of a private class.
82112
/// </summary>
@@ -109,6 +139,12 @@ public int TestProperty
109139
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
110140
}
111141

142+
/// <inheritdoc/>
143+
protected override IEnumerable<string> GetDisabledDiagnostics()
144+
{
145+
yield return PropertySummaryDocumentationAnalyzer.SA1623Descriptor.Id;
146+
}
147+
112148
/// <inheritdoc/>
113149
protected override CodeFixProvider GetCSharpCodeFixProvider()
114150
{

0 commit comments

Comments
 (0)