Skip to content

Commit

Permalink
Test records as well
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyIX committed Nov 29, 2023
1 parent 5ecef98 commit 31643cf
Showing 1 changed file with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.DocumentationRules;
using StyleCop.Analyzers.Test.Helpers;
using StyleCop.Analyzers.Test.Verifiers;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1648InheritDocMustBeUsedWithInheritingClass>;
Expand All @@ -16,66 +17,70 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
/// </summary>
public class SA1648UnitTests
{
[Fact]
public async Task TestConstructorWithNoParametersInheritsFromParentAsync()
[Theory]
[MemberData(nameof(CommonMemberData.ReferenceTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
public async Task TestConstructorWithNoParametersInheritsFromParentAsync(string keyword)
{
var testCode = @"class Base
var testCode = @"$KEYWORD$ Base
{
/// <summary>Base constructor.</summary>
public Base() { }
}
class Test : Base
$KEYWORD$ Test : Base
{
/// <inheritdoc/>
public Test() { }
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode.Replace("$KEYWORD$", keyword), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestConstructorWithParametersInheritsFromParentAsync()
[Theory]
[MemberData(nameof(CommonMemberData.ReferenceTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
public async Task TestConstructorWithParametersInheritsFromParentAsync(string keyword)
{
var testCode = @"class Base
var testCode = @"$KEYWORD$ Base
{
/// <summary>Base constructor.</summary>
public Base(string s, int a) { }
}
class Test : Base
$KEYWORD$ Test : Base
{
/// <inheritdoc/>
public Test(string s, int b)
: base(s, b) { }
}
";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode.Replace("$KEYWORD$", keyword), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestConstructorInheritsImplicitlyFromSystemObjectAsync()
[Theory]
[MemberData(nameof(CommonMemberData.ReferenceTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
public async Task TestConstructorInheritsImplicitlyFromSystemObjectAsync(string keyword)
{
var testCode = @"class Test
var testCode = @"$KEYWORD$ Test
{
/// <inheritdoc/>
public Test() { }
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode.Replace("$KEYWORD$", keyword), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestConstructorInheritsExplicitlyFromSystemObjectAsync()
[Theory]
[MemberData(nameof(CommonMemberData.ReferenceTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
public async Task TestConstructorInheritsExplicitlyFromSystemObjectAsync(string keyword)
{
var testCode = @"class Test : System.Object
var testCode = @"$KEYWORD$ Test : System.Object
{
/// <inheritdoc/>
public Test() { }
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await VerifyCSharpDiagnosticAsync(testCode.Replace("$KEYWORD$", keyword), DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
Expand All @@ -85,6 +90,9 @@ public async Task TestConstructorInheritsExplicitlyFromTypeInDifferentAssemblyAs
{
/// <inheritdoc/>
public MyArgumentException() { }
/// <inheritdoc/>
public MyArgumentException(string message) : base(message) { }
}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
Expand Down

0 comments on commit 31643cf

Please sign in to comment.