|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using StyleCop.Analyzers.DocumentationRules; |
6 | 9 | using StyleCop.Analyzers.Test.DocumentationRules; |
| 10 | + using Xunit; |
7 | 11 |
|
8 | 12 | public class SA1623CSharp7UnitTests : SA1623UnitTests |
9 | 13 | { |
| 14 | + /// <summary> |
| 15 | + /// Verifies that property documentation that does not start with the appropriate text will result in a |
| 16 | + /// diagnostic. This test extends |
| 17 | + /// <see cref="SA1623UnitTests.VerifyDocumentationWithWrongStartingTextWillProduceDiagnosticAsync"/> for the |
| 18 | + /// purpose of testing expression-bodied property accessors. |
| 19 | + /// </summary> |
| 20 | + /// <param name="accessibility">The accessibility of the property.</param> |
| 21 | + /// <param name="type">The type to use for the property.</param> |
| 22 | + /// <param name="accessors">The accessors for the property.</param> |
| 23 | + /// <param name="expectedArgument">The expected argument for the diagnostic message.</param> |
| 24 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 25 | + [Theory] |
| 26 | + [InlineData("public", "int", "{ get => 0; set => this.field = value; }", "Gets or sets")] |
| 27 | + [InlineData("public", "int", "{ get => 0; protected set => this.field = value; }", "Gets or sets")] |
| 28 | + [InlineData("public", "int", "{ get => 0; protected internal set => this.field = value; }", "Gets or sets")] |
| 29 | + [InlineData("public", "int", "{ get => 0; internal set => this.field = value; }", "Gets")] |
| 30 | + [InlineData("public", "int", "{ get => 0; private set => this.field = value; }", "Gets")] |
| 31 | + [InlineData("public", "int", "{ get => 0; }", "Gets")] |
| 32 | + [InlineData("public", "int", "{ set => this.field = value; }", "Sets")] |
| 33 | + [InlineData("public", "int", "{ internal get => 0; set => this.field = value; }", "Sets")] |
| 34 | + [InlineData("public", "int", "{ private get => 0; set => this.field = value; }", "Sets")] |
| 35 | + [InlineData("public", "bool", "{ get => true; set => this.field = value; }", "Gets or sets a value indicating whether")] |
| 36 | + [InlineData("public", "bool", "{ get => true; }", "Gets a value indicating whether")] |
| 37 | + [InlineData("public", "bool", "{ get => true; private set => this.field = value; }", "Gets a value indicating whether")] |
| 38 | + [InlineData("public", "bool", "{ set => this.field = value; }", "Sets a value indicating whether")] |
| 39 | + [InlineData("public", "bool", "{ private get => false; set => this.field = value; }", "Sets a value indicating whether")] |
| 40 | + [InlineData("protected", "int", "{ get => 0; private set => this.field = value; }", "Gets")] |
| 41 | + [InlineData("protected", "int", "{ private get => 0; set => this.field = value; }", "Sets")] |
| 42 | + [InlineData("protected internal", "int", "{ get => 0; internal set => this.field = value; }", "Gets")] |
| 43 | + [InlineData("protected internal", "int", "{ get => 0; private set => this.field = value; }", "Gets")] |
| 44 | + [InlineData("protected internal", "int", "{ internal get => 0; set => this.field = value; }", "Sets")] |
| 45 | + [InlineData("protected internal", "int", "{ private get => 0; set => this.field = value; }", "Sets")] |
| 46 | + [InlineData("internal", "int", "{ get => 0; private set => this.field = value; }", "Gets")] |
| 47 | + [InlineData("internal", "int", "{ private get => 0; set => this.field = value; }", "Sets")] |
| 48 | + public async Task VerifyDocumentationWithWrongStartingTextWillProduceDiagnosticWithExpressionBodiedAccessorsAsync(string accessibility, string type, string accessors, string expectedArgument) |
| 49 | + { |
| 50 | + var testCode = $@" |
| 51 | +public class TestClass |
| 52 | +{{ |
| 53 | + private object field; |
| 54 | +
|
| 55 | + /// <summary> |
| 56 | + /// The first test value. |
| 57 | + /// </summary> |
| 58 | + {accessibility} {type} TestProperty {accessors} |
| 59 | +}} |
| 60 | +"; |
| 61 | + |
| 62 | + var fixedTestCode = $@" |
| 63 | +public class TestClass |
| 64 | +{{ |
| 65 | + private object field; |
| 66 | +
|
| 67 | + /// <summary> |
| 68 | + /// {expectedArgument} the first test value. |
| 69 | + /// </summary> |
| 70 | + {accessibility} {type} TestProperty {accessors} |
| 71 | +}} |
| 72 | +"; |
| 73 | + |
| 74 | + var expected = this.CSharpDiagnostic(PropertySummaryDocumentationAnalyzer.SA1623Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument); |
| 75 | + |
| 76 | + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); |
| 77 | + await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 78 | + await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false); |
| 79 | + } |
10 | 80 | } |
11 | 81 | } |
0 commit comments