Skip to content

Commit

Permalink
Update test cases to cover all changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jun 20, 2017
1 parent e0b4ec1 commit 6912572
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using StyleCop.Analyzers.DocumentationRules;
using TestHelper;
Expand All @@ -17,6 +16,8 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
/// </summary>
public class SA1600UnitTests : DiagnosticVerifier
{
private string currentTestSettings;

[Theory]
[InlineData("public string TestMember;", 15)]
[InlineData("public string TestMember { get; set; }", 15)]
Expand Down Expand Up @@ -189,6 +190,42 @@ public async Task TestFieldWithoutDocumentationAsync()
await this.TestFieldDeclarationDocumentationAsync("internal", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected internal", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("public", true, false).ConfigureAwait(false);

// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
this.currentTestSettings = @"
{
""settings"": {
""documentationRules"": {
""documentPrivateElements"": true
}
}
}
";

await this.TestFieldDeclarationDocumentationAsync(string.Empty, false, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("private", false, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("internal", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected internal", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("public", true, false).ConfigureAwait(false);

// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
this.currentTestSettings = @"
{
""settings"": {
""documentationRules"": {
""documentPrivateFields"": true
}
}
}
";

await this.TestFieldDeclarationDocumentationAsync(string.Empty, true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("private", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("internal", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected internal", true, false).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("public", true, false).ConfigureAwait(false);
}

[Fact]
Expand All @@ -200,6 +237,42 @@ public async Task TestFieldWithDocumentationAsync()
await this.TestFieldDeclarationDocumentationAsync("internal", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected internal", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("public", false, true).ConfigureAwait(false);

// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
this.currentTestSettings = @"
{
""settings"": {
""documentationRules"": {
""documentPrivateElements"": true
}
}
}
";

await this.TestFieldDeclarationDocumentationAsync(string.Empty, false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("private", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("internal", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected internal", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("public", false, true).ConfigureAwait(false);

// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
this.currentTestSettings = @"
{
""settings"": {
""documentationRules"": {
""documentPrivateFields"": true
}
}
}
";

await this.TestFieldDeclarationDocumentationAsync(string.Empty, false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("private", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("internal", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("protected internal", false, true).ConfigureAwait(false);
await this.TestFieldDeclarationDocumentationAsync("public", false, true).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -430,6 +503,11 @@ public void SomeMethod() { }
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

protected override string GetSettings()
{
return this.currentTestSettings ?? base.GetSettings();
}

protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers()
{
yield return new SA1600ElementsMustBeDocumented();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class SA1601UnitTests : DiagnosticVerifier
}
";

private string currentTestSettings = TestSettings;

[Theory]
[InlineData("class")]
[InlineData("struct")]
Expand Down Expand Up @@ -58,6 +60,20 @@ public partial {0}
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(3, 1);

await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeKeyword), expected, CancellationToken.None).ConfigureAwait(false);

// The same situation is allowed if 'documentExposedElements' and 'documentInterfaces' is false
string interfaceSettingName = typeKeyword == "interface" ? "documentInterfaces" : "ignoredProperty";
this.currentTestSettings = $@"
{{
""settings"": {{
""documentationRules"": {{
""documentExposedElements"": false,
""{interfaceSettingName}"": false
}}
}}
}}
";
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeKeyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Theory]
Expand All @@ -78,6 +94,20 @@ public partial {0}
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(6, 1);

await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeKeyword), expected, CancellationToken.None).ConfigureAwait(false);

// The same situation is allowed if 'documentExposedElements' and 'documentInterfaces' is false
string interfaceSettingName = typeKeyword == "interface" ? "documentInterfaces" : "ignoredProperty";
this.currentTestSettings = $@"
{{
""settings"": {{
""documentationRules"": {{
""documentExposedElements"": false,
""{interfaceSettingName}"": false
}}
}}
}}
";
await this.VerifyCSharpDiagnosticAsync(string.Format(testCode, typeKeyword), EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand Down Expand Up @@ -112,6 +142,10 @@ public partial class TypeName
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(7, 18);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

// The same situation is allowed if 'documentPrivateElements' is false (the default)
this.currentTestSettings = null;
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand All @@ -132,12 +166,16 @@ public partial class TypeName
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(10, 18);

await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);

// The same situation is allowed if 'documentPrivateElements' is false (the default)
this.currentTestSettings = null;
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <inheritdoc/>
protected override string GetSettings()
{
return TestSettings;
return this.currentTestSettings ?? base.GetSettings();
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ enum TypeName
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestNestedPrivateEnumWithoutDocumentationAsync()
{
var testCode = @"
class ClassName
{
private enum TypeName
{
Bar
}
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestEnumWithEmptyDocumentationAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static IEnumerable<object[]> Data
get
{
// These method names are chosen so that the position of the parameters are always the same. This makes testing easier
yield return new object[] { " ClassName(string param1, string param2, string param3) { }" };
yield return new object[] { "void Foooooooooooo(string param1, string param2, string param3) { }" };
yield return new object[] { "delegate void Fooo(string param1, string param2, string param3);" };
yield return new object[] { "System.String this[string param1, string param2, string param3] { get { return param1; } }" };
Expand Down Expand Up @@ -173,6 +174,20 @@ private void Test2(int arg) { }
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(2444, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2444")]
public async Task TestPrivateMethodMissingParametersInIncludedDocumentationAsync()
{
var testCode = @"
internal class ClassName
{
/// <include file='MissingElementDocumentation.xml' path='/TestClass/TestMethod/*' />
private void TestMethod(string param1, string param2, string param3) { }
}";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

/// <summary>
/// Verifies that valid operator declarations will not produce diagnostics.
/// </summary>
Expand Down

0 comments on commit 6912572

Please sign in to comment.