Skip to content

Commit 64e8d46

Browse files
committed
Simplify CommonMemberData
1 parent eceae28 commit 64e8d46

File tree

4 files changed

+58
-104
lines changed

4 files changed

+58
-104
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1605UnitTests.cs

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
namespace StyleCop.Analyzers.Test.DocumentationRules
55
{
6-
using System.Collections.Generic;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.DocumentationRules;
11-
using StyleCop.Analyzers.Lightup;
10+
using StyleCop.Analyzers.Test.Helpers;
1211
using StyleCop.Analyzers.Test.Verifiers;
1312
using Xunit;
1413
using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1605PartialElementDocumentationMustHaveSummary>;
@@ -28,35 +27,8 @@ public class SA1605UnitTests
2827
}
2928
";
3029

31-
public static IEnumerable<object[]> TypeDeclarationKeywords
32-
{
33-
get
34-
{
35-
yield return new[] { "class" };
36-
yield return new[] { "struct" };
37-
yield return new[] { "interface" };
38-
if (LightupHelpers.SupportsCSharp9)
39-
{
40-
yield return new[] { "record" };
41-
}
42-
}
43-
}
44-
45-
public static IEnumerable<object[]> BaseTypeDeclarationKeywords
46-
{
47-
get
48-
{
49-
foreach (var keyword in TypeDeclarationKeywords)
50-
{
51-
yield return keyword;
52-
}
53-
54-
yield return new[] { "enum" };
55-
}
56-
}
57-
5830
[Theory]
59-
[MemberData(nameof(TypeDeclarationKeywords))]
31+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
6032
public async Task TestTypeNoDocumentationAsync(string typeName)
6133
{
6234
var testCode = @"
@@ -67,7 +39,7 @@ public async Task TestTypeNoDocumentationAsync(string typeName)
6739
}
6840

6941
[Theory]
70-
[MemberData(nameof(TypeDeclarationKeywords))]
42+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
7143
public async Task TestTypeWithSummaryDocumentationAsync(string typeName)
7244
{
7345
var testCode = @"
@@ -81,7 +53,7 @@ public async Task TestTypeWithSummaryDocumentationAsync(string typeName)
8153
}
8254

8355
[Theory]
84-
[MemberData(nameof(TypeDeclarationKeywords))]
56+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
8557
public async Task TestTypeWithContentDocumentationAsync(string typeName)
8658
{
8759
var testCode = @"
@@ -95,7 +67,7 @@ public async Task TestTypeWithContentDocumentationAsync(string typeName)
9567
}
9668

9769
[Theory]
98-
[MemberData(nameof(TypeDeclarationKeywords))]
70+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
9971
public async Task TestTypeWithInheritedDocumentationAsync(string typeName)
10072
{
10173
var testCode = @"
@@ -107,7 +79,7 @@ public async Task TestTypeWithInheritedDocumentationAsync(string typeName)
10779
}
10880

10981
[Theory]
110-
[MemberData(nameof(TypeDeclarationKeywords))]
82+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
11183
public async Task TestTypeWithoutDocumentationAsync(string typeName)
11284
{
11385
var testCode = @"
@@ -123,7 +95,7 @@ public async Task TestTypeWithoutDocumentationAsync(string typeName)
12395
}
12496

12597
[Theory]
126-
[MemberData(nameof(BaseTypeDeclarationKeywords))]
98+
[MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
12799
public async Task TestNonPartialTypeWithoutDocumentationAsync(string typeName)
128100
{
129101
var testCode = @"

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1607UnitTests.cs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
namespace StyleCop.Analyzers.Test.DocumentationRules
55
{
6-
using System.Collections.Generic;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.DocumentationRules;
11-
using StyleCop.Analyzers.Lightup;
10+
using StyleCop.Analyzers.Test.Helpers;
1211
using StyleCop.Analyzers.Test.Verifiers;
1312
using Xunit;
1413
using static StyleCop.Analyzers.Test.Verifiers.CustomDiagnosticVerifier<StyleCop.Analyzers.DocumentationRules.SA1607PartialElementDocumentationMustHaveSummaryText>;
@@ -18,35 +17,8 @@ namespace StyleCop.Analyzers.Test.DocumentationRules
1817
/// </summary>
1918
public class SA1607UnitTests
2019
{
21-
public static IEnumerable<object[]> TypeDeclarationKeywords
22-
{
23-
get
24-
{
25-
yield return new[] { "class" };
26-
yield return new[] { "struct" };
27-
yield return new[] { "interface" };
28-
if (LightupHelpers.SupportsCSharp9)
29-
{
30-
yield return new[] { "record" };
31-
}
32-
}
33-
}
34-
35-
public static IEnumerable<object[]> BaseTypeDeclarationKeywords
36-
{
37-
get
38-
{
39-
foreach (var keyword in TypeDeclarationKeywords)
40-
{
41-
yield return keyword;
42-
}
43-
44-
yield return new[] { "enum" };
45-
}
46-
}
47-
4820
[Theory]
49-
[MemberData(nameof(TypeDeclarationKeywords))]
21+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
5022
public async Task TestTypeNoDocumentationAsync(string typeName)
5123
{
5224
var testCode = @"
@@ -57,7 +29,7 @@ public async Task TestTypeNoDocumentationAsync(string typeName)
5729
}
5830

5931
[Theory]
60-
[MemberData(nameof(TypeDeclarationKeywords))]
32+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
6133
public async Task TestTypeWithSummaryDocumentationAsync(string typeName)
6234
{
6335
var testCode = @"
@@ -71,7 +43,7 @@ public async Task TestTypeWithSummaryDocumentationAsync(string typeName)
7143
}
7244

7345
[Theory]
74-
[MemberData(nameof(TypeDeclarationKeywords))]
46+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
7547
public async Task TestTypeWithContentDocumentationAsync(string typeName)
7648
{
7749
var testCode = @"
@@ -85,7 +57,7 @@ public async Task TestTypeWithContentDocumentationAsync(string typeName)
8557
}
8658

8759
[Theory]
88-
[MemberData(nameof(TypeDeclarationKeywords))]
60+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
8961
public async Task TestTypeWithInheritedDocumentationAsync(string typeName)
9062
{
9163
var testCode = @"
@@ -97,7 +69,7 @@ public async Task TestTypeWithInheritedDocumentationAsync(string typeName)
9769
}
9870

9971
[Theory]
100-
[MemberData(nameof(TypeDeclarationKeywords))]
72+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
10173
public async Task TestTypeWithoutSummaryDocumentationAsync(string typeName)
10274
{
10375
var testCode = @"
@@ -115,7 +87,7 @@ public async Task TestTypeWithoutSummaryDocumentationAsync(string typeName)
11587
}
11688

11789
[Theory]
118-
[MemberData(nameof(BaseTypeDeclarationKeywords))]
90+
[MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
11991
public async Task TestNonPartialTypeWithoutSummaryDocumentationAsync(string typeName)
12092
{
12193
var testCode = @"
@@ -130,7 +102,7 @@ public async Task TestNonPartialTypeWithoutSummaryDocumentationAsync(string type
130102
}
131103

132104
[Theory]
133-
[MemberData(nameof(TypeDeclarationKeywords))]
105+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
134106
public async Task TestTypeWithoutContentDocumentationAsync(string typeName)
135107
{
136108
var testCode = @"
@@ -148,7 +120,7 @@ public async Task TestTypeWithoutContentDocumentationAsync(string typeName)
148120
}
149121

150122
[Theory]
151-
[MemberData(nameof(BaseTypeDeclarationKeywords))]
123+
[MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
152124
public async Task TestNonPartialTypeWithoutContentDocumentationAsync(string typeName)
153125
{
154126
var testCode = @"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.Helpers
5+
{
6+
using System.Collections.Generic;
7+
using StyleCop.Analyzers.Lightup;
8+
9+
public static class CommonMemberData
10+
{
11+
public static IEnumerable<object[]> TypeDeclarationKeywords
12+
{
13+
get
14+
{
15+
yield return new[] { "class" };
16+
yield return new[] { "struct" };
17+
yield return new[] { "interface" };
18+
if (LightupHelpers.SupportsCSharp9)
19+
{
20+
yield return new[] { "record" };
21+
}
22+
}
23+
}
24+
25+
public static IEnumerable<object[]> BaseTypeDeclarationKeywords
26+
{
27+
get
28+
{
29+
foreach (var keyword in TypeDeclarationKeywords)
30+
{
31+
yield return keyword;
32+
}
33+
34+
yield return new[] { "enum" };
35+
}
36+
}
37+
}
38+
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1137UnitTests.cs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
namespace StyleCop.Analyzers.Test.ReadabilityRules
55
{
6-
using System.Collections.Generic;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
10-
using StyleCop.Analyzers.Lightup;
119
using StyleCop.Analyzers.ReadabilityRules;
10+
using StyleCop.Analyzers.Test.Helpers;
1211
using Xunit;
1312
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1413
StyleCop.Analyzers.ReadabilityRules.SA1137ElementsShouldHaveTheSameIndentation,
@@ -19,35 +18,8 @@ namespace StyleCop.Analyzers.Test.ReadabilityRules
1918
/// </summary>
2019
public class SA1137UnitTests
2120
{
22-
public static IEnumerable<object[]> TypeDeclarationKeywords
23-
{
24-
get
25-
{
26-
yield return new[] { "class" };
27-
yield return new[] { "struct" };
28-
yield return new[] { "interface" };
29-
if (LightupHelpers.SupportsCSharp9)
30-
{
31-
yield return new[] { "record" };
32-
}
33-
}
34-
}
35-
36-
public static IEnumerable<object[]> BaseTypeDeclarationKeywords
37-
{
38-
get
39-
{
40-
foreach (var keyword in TypeDeclarationKeywords)
41-
{
42-
yield return keyword;
43-
}
44-
45-
yield return new[] { "enum" };
46-
}
47-
}
48-
4921
[Theory]
50-
[MemberData(nameof(BaseTypeDeclarationKeywords))]
22+
[MemberData(nameof(CommonMemberData.BaseTypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
5123
public async Task TestNamespaceDeclarationAsync(string baseTypeKind)
5224
{
5325
string testCode = $@"
@@ -174,7 +146,7 @@ class MyAttribute : Attribute {{ }}
174146
}
175147

176148
[Theory]
177-
[MemberData(nameof(TypeDeclarationKeywords))]
149+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
178150
public async Task TestTypeDeclarationConstraintClausesAsync(string typeKind)
179151
{
180152
string testCode = $@"
@@ -243,7 +215,7 @@ public async Task TestTypeDeclarationConstraintClausesAsync(string typeKind)
243215
}
244216

245217
[Theory]
246-
[MemberData(nameof(TypeDeclarationKeywords))]
218+
[MemberData(nameof(CommonMemberData.TypeDeclarationKeywords), MemberType = typeof(CommonMemberData))]
247219
public async Task TestTypeDeclarationMembersAsync(string typeKind)
248220
{
249221
string fieldType = typeKind switch

0 commit comments

Comments
 (0)