Skip to content

Commit e8d87e2

Browse files
authored
Merge pull request #2751 from sharwell/testing-library
Update unit tests to Microsoft.CodeAnalysis.Testing
2 parents fe64add + e43fa91 commit e8d87e2

File tree

310 files changed

+11279
-15353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

310 files changed

+11279
-15353
lines changed

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<configuration>
33
<packageSources>
44
<add key="roslyn" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
5+
<add key="roslyn-analyzers" value="https://dotnet.myget.org/F/roslyn-analyzers/api/v3/index.json" />
56
<add key="symreader-converter" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
67
</packageSources>
78
</configuration>

StyleCop.Analyzers/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<PropertyGroup>
17-
<LangVersion>7</LangVersion>
17+
<LangVersion>7.2</LangVersion>
1818
<Features>strict</Features>
1919
</PropertyGroup>
2020

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/MaintainabilityRules/SA1119CodeFixProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal class SA1119CodeFixProvider : CodeFixProvider
2727
{
2828
/// <inheritdoc/>
2929
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
30-
ImmutableArray.Create(SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId);
30+
ImmutableArray.Create(SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId, SA1119StatementMustNotUseUnnecessaryParenthesis.ParenthesesDiagnosticId);
3131

3232
/// <inheritdoc/>
3333
public override FixAllProvider GetFixAllProvider()
@@ -42,6 +42,11 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
4242

4343
foreach (var diagnostic in context.Diagnostics)
4444
{
45+
if (diagnostic.Id != SA1119StatementMustNotUseUnnecessaryParenthesis.DiagnosticId)
46+
{
47+
continue;
48+
}
49+
4550
SyntaxNode node = root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true, findInsideTrivia: true);
4651
if (node.IsMissing)
4752
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
namespace StyleCop.Analyzers.Test.CSharp7
5+
{
6+
public class AnalyzerConfigurationTestsCSharp7 : AnalyzerConfigurationTests
7+
{
8+
}
9+
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/DocumentationRules/SA1600CSharp7UnitTests.cs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
55
{
66
using System.Threading.Tasks;
7-
using Microsoft.CodeAnalysis;
87
using Microsoft.CodeAnalysis.CSharp;
98
using StyleCop.Analyzers.Test.DocumentationRules;
109
using Xunit;
1110

1211
public class SA1600CSharp7UnitTests : SA1600UnitTests
1312
{
14-
private string currentTestSettings;
13+
protected override LanguageVersion LanguageVersion => LanguageVersion.CSharp7_2;
1514

1615
[Fact]
1716
public async Task TestPrivateProtectedDelegateWithoutDocumentationAsync()
@@ -52,10 +51,10 @@ public async Task TestPrivateProtectedConstructorWithDocumentationAsync()
5251
[Fact]
5352
public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
5453
{
55-
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
54+
await this.TestFieldDeclarationDocumentationAsync(testSettings: null, "private protected", true, false).ConfigureAwait(false);
5655

5756
// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
58-
this.currentTestSettings = @"
57+
var testSettings = @"
5958
{
6059
""settings"": {
6160
""documentationRules"": {
@@ -65,10 +64,10 @@ public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
6564
}
6665
";
6766

68-
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
67+
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", true, false).ConfigureAwait(false);
6968

7069
// Re-test with the 'documentInternalElements' setting disabled (does impact fields)
71-
this.currentTestSettings = @"
70+
testSettings = @"
7271
{
7372
""settings"": {
7473
""documentationRules"": {
@@ -78,10 +77,10 @@ public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
7877
}
7978
";
8079

81-
await this.TestFieldDeclarationDocumentationAsync("private protected", false, false).ConfigureAwait(false);
80+
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, false).ConfigureAwait(false);
8281

8382
// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
84-
this.currentTestSettings = @"
83+
testSettings = @"
8584
{
8685
""settings"": {
8786
""documentationRules"": {
@@ -91,16 +90,16 @@ public async Task TestPrivateProtectedFieldWithoutDocumentationAsync()
9190
}
9291
";
9392

94-
await this.TestFieldDeclarationDocumentationAsync("private protected", true, false).ConfigureAwait(false);
93+
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", true, false).ConfigureAwait(false);
9594
}
9695

9796
[Fact]
9897
public async Task TestPrivateProtectedFieldWithDocumentationAsync()
9998
{
100-
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
99+
await this.TestFieldDeclarationDocumentationAsync(testSettings: null, "private protected", false, true).ConfigureAwait(false);
101100

102101
// Re-test with the 'documentPrivateElements' setting enabled (doesn't impact fields)
103-
this.currentTestSettings = @"
102+
var testSettings = @"
104103
{
105104
""settings"": {
106105
""documentationRules"": {
@@ -110,10 +109,10 @@ public async Task TestPrivateProtectedFieldWithDocumentationAsync()
110109
}
111110
";
112111

113-
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
112+
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, true).ConfigureAwait(false);
114113

115114
// Re-test with the 'documentInternalElements' setting disabled (does impact fields)
116-
this.currentTestSettings = @"
115+
testSettings = @"
117116
{
118117
""settings"": {
119118
""documentationRules"": {
@@ -123,10 +122,10 @@ public async Task TestPrivateProtectedFieldWithDocumentationAsync()
123122
}
124123
";
125124

126-
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
125+
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, true).ConfigureAwait(false);
127126

128127
// Re-test with the 'documentPrivateFields' setting enabled (does impact fields)
129-
this.currentTestSettings = @"
128+
testSettings = @"
130129
{
131130
""settings"": {
132131
""documentationRules"": {
@@ -136,7 +135,7 @@ public async Task TestPrivateProtectedFieldWithDocumentationAsync()
136135
}
137136
";
138137

139-
await this.TestFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
138+
await this.TestFieldDeclarationDocumentationAsync(testSettings, "private protected", false, true).ConfigureAwait(false);
140139
}
141140

142141
[Fact]
@@ -187,18 +186,6 @@ public async Task TestPrivateProtectedEventFieldWithDocumentationAsync()
187186
await this.TestEventFieldDeclarationDocumentationAsync("private protected", false, true).ConfigureAwait(false);
188187
}
189188

190-
protected override string GetSettings()
191-
{
192-
return this.currentTestSettings ?? base.GetSettings();
193-
}
194-
195-
protected override Project CreateProjectImpl(string[] sources, string language, string[] filenames)
196-
{
197-
var project = base.CreateProjectImpl(sources, language, filenames);
198-
var parseOptions = (CSharpParseOptions)project.ParseOptions;
199-
return project.WithParseOptions(parseOptions.WithLanguageVersion(LanguageVersion.CSharp7_2));
200-
}
201-
202189
protected override async Task TestTypeWithoutDocumentationAsync(string type, bool isInterface)
203190
{
204191
await base.TestTypeWithoutDocumentationAsync(type, isInterface).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/DocumentationRules/SA1623CSharp7UnitTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
88
using StyleCop.Analyzers.DocumentationRules;
99
using StyleCop.Analyzers.Test.DocumentationRules;
1010
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationAnalyzer,
13+
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationCodeFixProvider>;
1114

1215
public class SA1623CSharp7UnitTests : SA1623UnitTests
1316
{
@@ -71,11 +74,8 @@ public class TestClass
7174
}}
7275
";
7376

74-
var expected = this.CSharpDiagnostic(PropertySummaryDocumentationAnalyzer.SA1623Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument);
75-
76-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
77-
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
78-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
77+
var expected = Diagnostic(PropertySummaryDocumentationAnalyzer.SA1623Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument);
78+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
7979
}
8080
}
8181
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/DocumentationRules/SA1624CSharp7UnitTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace StyleCop.Analyzers.Test.CSharp7.DocumentationRules
88
using StyleCop.Analyzers.DocumentationRules;
99
using StyleCop.Analyzers.Test.DocumentationRules;
1010
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationAnalyzer,
13+
StyleCop.Analyzers.DocumentationRules.PropertySummaryDocumentationCodeFixProvider>;
1114

1215
public class SA1624CSharp7UnitTests : SA1624UnitTests
1316
{
@@ -69,11 +72,8 @@ public class TestClass
6972
}}
7073
";
7174

72-
var expected = this.CSharpDiagnostic(PropertySummaryDocumentationAnalyzer.SA1624Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument1, expectedArgument2);
73-
74-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
75-
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
76-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
75+
var expected = Diagnostic(PropertySummaryDocumentationAnalyzer.SA1624Descriptor).WithLocation(9, 7 + accessibility.Length + type.Length).WithArguments(expectedArgument1, expectedArgument2);
76+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
7777
}
7878
}
7979
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/LayoutRules/SA1500CSharp7UnitTests.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.LayoutRules;
910
using TestHelper;
1011
using Xunit;
12+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
13+
StyleCop.Analyzers.LayoutRules.SA1500BracesForMultiLineStatementsMustNotShareLine,
14+
StyleCop.Analyzers.LayoutRules.SA1500CodeFixProvider>;
1115

1216
public class SA1500CSharp7UnitTests : SA1500UnitTests
1317
{
@@ -50,7 +54,7 @@ void LocalFunction5()
5054
}
5155
}";
5256

53-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
57+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
5458
}
5559

5660
/// <summary>
@@ -141,28 +145,26 @@ void LocalFunction6()
141145
DiagnosticResult[] expectedDiagnostics =
142146
{
143147
// Invalid local function #1
144-
this.CSharpDiagnostic().WithLocation(8, 31),
148+
Diagnostic().WithLocation(8, 31),
145149

146150
// Invalid local function #2
147-
this.CSharpDiagnostic().WithLocation(12, 31),
151+
Diagnostic().WithLocation(12, 31),
148152

149153
// Invalid local function #3
150-
this.CSharpDiagnostic().WithLocation(17, 31),
151-
this.CSharpDiagnostic().WithLocation(18, 29),
154+
Diagnostic().WithLocation(17, 31),
155+
Diagnostic().WithLocation(18, 29),
152156

153157
// Invalid local function #4
154-
this.CSharpDiagnostic().WithLocation(21, 31),
158+
Diagnostic().WithLocation(21, 31),
155159

156160
// Invalid local function #5
157-
this.CSharpDiagnostic().WithLocation(27, 29),
161+
Diagnostic().WithLocation(27, 29),
158162

159163
// Invalid local function #6
160-
this.CSharpDiagnostic().WithLocation(31, 9),
164+
Diagnostic().WithLocation(31, 9),
161165
};
162166

163-
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
164-
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
165-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
167+
await VerifyCSharpFixAsync(testCode, expectedDiagnostics, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
166168
}
167169
}
168170
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/LayoutRules/SA1502CSharp7UnitTests.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ namespace StyleCop.Analyzers.Test.CSharp7.LayoutRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.LayoutRules;
910
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.LayoutRules.SA1502ElementMustNotBeOnASingleLine,
13+
StyleCop.Analyzers.LayoutRules.SA1502CodeFixProvider>;
1014

1115
public class SA1502CSharp7UnitTests : SA1502UnitTests
1216
{
@@ -27,7 +31,7 @@ void Bar()
2731
}
2832
}";
2933

30-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
34+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3135
}
3236

3337
/// <summary>
@@ -45,8 +49,8 @@ void Bar() { }
4549
}
4650
}";
4751

48-
var expected = this.CSharpDiagnostic().WithLocation(5, 20);
49-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
52+
var expected = Diagnostic().WithLocation(5, 20);
53+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
5054
}
5155

5256
/// <summary>
@@ -64,8 +68,8 @@ public void Method()
6468
}
6569
}";
6670

67-
var expected = this.CSharpDiagnostic().WithLocation(5, 19);
68-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
71+
var expected = Diagnostic().WithLocation(5, 19);
72+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
6973
}
7074

7175
/// <summary>
@@ -84,8 +88,8 @@ int Bar()
8488
}
8589
}";
8690

87-
var expected = this.CSharpDiagnostic().WithLocation(6, 9);
88-
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
91+
var expected = Diagnostic().WithLocation(6, 9);
92+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
8993
}
9094

9195
/// <summary>
@@ -104,7 +108,7 @@ int Bar() {
104108
}
105109
}";
106110

107-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
111+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
108112
}
109113

110114
/// <summary>
@@ -122,7 +126,7 @@ public void Method()
122126
}
123127
}";
124128

125-
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
129+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
126130
}
127131

128132
/// <summary>
@@ -149,7 +153,8 @@ void Bar()
149153
}
150154
}";
151155

152-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
156+
var expected = Diagnostic().WithLocation(5, 20);
157+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
153158
}
154159

155160
/// <summary>
@@ -177,7 +182,8 @@ int Bar()
177182
}
178183
}";
179184

180-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
185+
var expected = Diagnostic().WithLocation(5, 19);
186+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
181187
}
182188

183189
/// <summary>
@@ -206,7 +212,8 @@ int Bar()
206212
}
207213
}";
208214

209-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
215+
var expected = Diagnostic().WithLocation(6, 9);
216+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
210217
}
211218

212219
/// <summary>
@@ -234,7 +241,8 @@ int Bar() /* TR1 */
234241
}
235242
}";
236243

237-
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
244+
var expected = Diagnostic().WithLocation(5, 29);
245+
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
238246
}
239247
}
240248
}

0 commit comments

Comments
 (0)