Skip to content

Commit

Permalink
Add tests for 'private protected' accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Sep 9, 2018
1 parent 5712cf8 commit dddf185
Showing 4 changed files with 250 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -3,9 +3,214 @@

namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
{
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Test.DocumentationRules;
using Xunit;

public class SA1600CSharp7UnitTests : SA1600UnitTests
{
private string currentTestSettings;

[Fact]
public async Task TestPrivateProtectedDelegateWithoutDocumentationAsync()
{
await this.TestNestedDelegateDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedDelegateWithDocumentationAsync()
{
await this.TestNestedDelegateDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedMethodWithoutDocumentationAsync()
{
await this.TestMethodDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedMethodWithDocumentationAsync()
{
await this.TestMethodDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedConstructorWithoutDocumentationAsync()
{
await this.TestConstructorDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedConstructorWithDocumentationAsync()
{
await this.TestConstructorDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
{
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);

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

await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);

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

await this.TestFieldDeclarationDocumentationAsync("private protected", false, false).ConfigureAwait(false);

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

await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedFieldWithDocumentationAsync()
{
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);

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

await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);

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

await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);

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

await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedPropertyWithoutDocumentationAsync()
{
await this.TestPropertyDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedPropertyWithDocumentationAsync()
{
await this.TestPropertyDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedIndexerWithoutDocumentationAsync()
{
await this.TestIndexerDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedIndexerWithDocumentationAsync()
{
await this.TestIndexerDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedEventWithoutDocumentationAsync()
{
await this.TestEventDeclarationDocumentationAsync("private protected", false, true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedEventWithDocumentationAsync()
{
await this.TestEventDeclarationDocumentationAsync("private protected", false, false, true).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedEventFieldWithoutDocumentationAsync()
{
await this.TestEventFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
}

[Fact]
public async Task TestPrivateProtectedEventFieldWithDocumentationAsync()
{
await this.TestEventFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
}

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

protected override Project CreateProjectImpl(string[] sources, string language, string[] filenames)
{
var project = base.CreateProjectImpl(sources, language, filenames);
var parseOptions = (CSharpParseOptions)project.ParseOptions;
return project.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.CSharp7_2));
}

protected override async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
{
await base.TestTypeWithoutDocumentationAsync(type, isInterface).ConfigureAwait(false);

await this.TestNestedTypeDeclarationDocumentationAsync(type, "private protected", true, false).ConfigureAwait(false);
}

protected override async Task TestTypeWithDocumentationAsync(string type)
{
await base.TestTypeWithDocumentationAsync(type).ConfigureAwait(false);

await this.TestNestedTypeDeclarationDocumentationAsync(type, "private protected", false, true).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -855,7 +855,7 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()
return new SA1600CodeFixProvider();
}

private async Task TestTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @"
{0} {1}
@@ -876,7 +876,7 @@ private async Task TestTypeDeclarationDocumentationAsync(string type, string mod
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, type), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestNestedTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestNestedTypeDeclarationDocumentationAsync(string type, string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -909,7 +909,7 @@ public class OuterClass
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, type), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @"
{0} delegate void
@@ -926,7 +926,7 @@ private async Task TestDelegateDeclarationDocumentationAsync(string modifiers, b
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestNestedDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestNestedDelegateDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -955,7 +955,7 @@ public class OuterClass
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestMethodDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceMethod, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestMethodDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceMethod, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -997,7 +997,7 @@ public interface IInterface {{ void MemberName(); }}
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestInterfaceMethodDeclarationDocumentationAsync(bool hasDocumentation)
protected async Task TestInterfaceMethodDeclarationDocumentationAsync(bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1026,7 +1026,7 @@ public interface InterfaceName
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestInterfacePropertyDeclarationDocumentationAsync(bool hasDocumentation)
protected async Task TestInterfacePropertyDeclarationDocumentationAsync(bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1061,7 +1061,7 @@ string MemberName
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestInterfaceEventDeclarationDocumentationAsync(bool hasDocumentation)
protected async Task TestInterfaceEventDeclarationDocumentationAsync(bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1090,7 +1090,7 @@ public interface InterfaceName
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestInterfaceIndexerDeclarationDocumentationAsync(bool hasDocumentation)
protected async Task TestInterfaceIndexerDeclarationDocumentationAsync(bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1119,7 +1119,7 @@ public interface InterfaceName
await this.VerifyCSharpDiagnosticAsync(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, !hasDocumentation ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestConstructorDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestConstructorDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1152,7 +1152,7 @@ public class OuterClass
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestDestructorDeclarationDocumentationAsync(bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestDestructorDeclarationDocumentationAsync(bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1183,7 +1183,7 @@ public class OuterClass
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestPropertyDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceProperty, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestPropertyDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceProperty, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1223,7 +1223,7 @@ public interface IInterface {{ string MemberName {{ get; set; }} }}
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestIndexerDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceIndexer, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestIndexerDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceIndexer, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1263,7 +1263,7 @@ public interface IInterface {{ string this[string key] {{ get; set; }} }}
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestEventDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceEvent, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestEventDeclarationDocumentationAsync(string modifiers, bool isExplicitInterfaceEvent, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1325,7 +1325,7 @@ public interface IInterface {{ event System.Action MyEvent; }}
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers, explicitInterfaceText), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1354,7 +1354,7 @@ public class OuterClass
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestEventFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
protected async Task TestEventFieldDeclarationDocumentationAsync(string modifiers, bool requiresDiagnostic, bool hasDocumentation)
{
var testCodeWithoutDocumentation = @" /// <summary>
/// A summary
@@ -1383,7 +1383,7 @@ public class OuterClass
await this.VerifyCSharpDiagnosticAsync(string.Format(hasDocumentation ? testCodeWithDocumentation : testCodeWithoutDocumentation, modifiers), requiresDiagnostic ? expected : EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

private async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
protected virtual async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
{
await this.TestTypeDeclarationDocumentationAsync(type, string.Empty, true, false).ConfigureAwait(false);
await this.TestTypeDeclarationDocumentationAsync(type, "internal", true, false).ConfigureAwait(false);
@@ -1397,7 +1397,7 @@ private async Task TestTypeWithoutDocumentationAsync(string type, bool isInterfa
await this.TestNestedTypeDeclarationDocumentationAsync(type, "public", true, false).ConfigureAwait(false);
}

private async Task TestTypeWithDocumentationAsync(string type)
protected virtual async Task TestTypeWithDocumentationAsync(string type)
{
await this.TestTypeDeclarationDocumentationAsync(type, string.Empty, false, true).ConfigureAwait(false);
await this.TestTypeDeclarationDocumentationAsync(type, "internal", false, true).ConfigureAwait(false);
Loading

0 comments on commit dddf185

Please sign in to comment.