Skip to content

Commit 1ed6475

Browse files
committed
Update SA1206 tests for covariant return types
1 parent c8d8d0a commit 1ed6475

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/OrderingRules/SA1206CSharp9UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp9.OrderingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.OrderingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.OrderingRules.SA1206DeclarationKeywordsMustFollowOrder,
13+
StyleCop.Analyzers.OrderingRules.SA1206CodeFixProvider>;
714

815
public partial class SA1206CSharp9UnitTests : SA1206CSharp8UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3975, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3975")]
19+
public async Task TestCovariantOverrideKeywordsOutOfOrderAsync()
20+
{
21+
var testCode = @"
22+
public class BaseType
23+
{
24+
}
25+
26+
public class DerivedType : BaseType
27+
{
28+
}
29+
30+
public class BaseClass
31+
{
32+
public virtual BaseType Create() => new BaseType();
33+
}
34+
35+
public class DerivedClass : BaseClass
36+
{
37+
override [|public|] DerivedType Create() => new DerivedType();
38+
}
39+
";
40+
41+
var fixedCode = @"
42+
public class BaseType
43+
{
44+
}
45+
46+
public class DerivedType : BaseType
47+
{
48+
}
49+
50+
public class BaseClass
51+
{
52+
public virtual BaseType Create() => new BaseType();
53+
}
54+
55+
public class DerivedClass : BaseClass
56+
{
57+
public override DerivedType Create() => new DerivedType();
58+
}
59+
";
60+
61+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
62+
}
1063
}
1164
}

0 commit comments

Comments
 (0)