Skip to content

Commit c8d8d0a

Browse files
committed
Update SA1615 tests for covariant return types
1 parent dd7c01e commit c8d8d0a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/DocumentationRules/SA1615CSharp9UnitTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,73 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.DocumentationRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.DocumentationRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1615ElementReturnValueMustBeDocumented>;
712

813
public partial class SA1615CSharp9UnitTests : SA1615CSharp8UnitTests
914
{
15+
[Fact]
16+
[WorkItem(3975, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3975")]
17+
public async Task TestCovariantOverrideMissingReturnsDocumentationAsync()
18+
{
19+
var testCode = @"
20+
public class BaseType
21+
{
22+
}
23+
24+
public class DerivedType : BaseType
25+
{
26+
}
27+
28+
public class BaseClass
29+
{
30+
/// <summary>Creates a base instance.</summary>
31+
/// <returns>A <see cref=""BaseType""/> instance.</returns>
32+
public virtual BaseType Create() => new BaseType();
33+
}
34+
35+
public class DerivedClass : BaseClass
36+
{
37+
/// <summary>Creates a derived instance.</summary>
38+
public override [|DerivedType|] Create() => new DerivedType();
39+
}
40+
";
41+
42+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
43+
}
44+
45+
[Fact]
46+
[WorkItem(3975, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3975")]
47+
public async Task TestCovariantOverrideInheritsReturnsDocumentationAsync()
48+
{
49+
var testCode = @"
50+
public class BaseType
51+
{
52+
}
53+
54+
public class DerivedType : BaseType
55+
{
56+
}
57+
58+
public class BaseClass
59+
{
60+
/// <summary>Creates a base instance.</summary>
61+
/// <returns>A <see cref=""BaseType""/> instance.</returns>
62+
public virtual BaseType Create() => new BaseType();
63+
}
64+
65+
public class DerivedClass : BaseClass
66+
{
67+
/// <inheritdoc/>
68+
public override DerivedType Create() => new DerivedType();
69+
}
70+
";
71+
72+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
73+
}
1074
}
1175
}

0 commit comments

Comments
 (0)