Skip to content

Commit cd5736f

Browse files
authored
Merge 4ba311b into b209e4e
2 parents b209e4e + 4ba311b commit cd5736f

File tree

18 files changed

+302
-179
lines changed

18 files changed

+302
-179
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/NamingRules/SA1313CSharp10UnitTests.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp10.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp9.NamingRules;
11-
using StyleCop.Analyzers.Test.Verifiers;
1210
using Xunit;
1311
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1412
StyleCop.Analyzers.NamingRules.SA1313ParameterNamesMustBeginWithLowerCaseLetter,
@@ -42,12 +40,7 @@ public R(int a, int b)
4240
}}
4341
";
4442

45-
await new CSharpTest()
46-
{
47-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
48-
TestCode = testCode,
49-
FixedCode = fixedCode,
50-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
43+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
5144
}
5245
}
5346
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp10/ReadabilityRules/SA1101CSharp10UnitTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp10.ReadabilityRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp9.ReadabilityRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
@@ -29,11 +29,7 @@ public bool Method(Test arg)
2929
}
3030
}";
3131

32-
await new CSharpTest()
33-
{
34-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet60,
35-
TestCode = testCode,
36-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
32+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3733
}
3834
}
3935
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/OrderingRules/SA1206CSharp11CodeFixProviderUnitTests.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp11.OrderingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.OrderingRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.OrderingRules.SA1206DeclarationKeywordsMustFollowOrder,
@@ -43,17 +43,13 @@ internal struct SomeStruct
4343
public required int Field;
4444
}";
4545

46-
await new CSharpTest()
46+
DiagnosticResult[] expected =
4747
{
48-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet70,
49-
TestCode = testCode,
50-
FixedCode = fixedCode,
51-
ExpectedDiagnostics =
52-
{
53-
Diagnostic().WithLocation(0).WithArguments("public", "required"),
54-
Diagnostic().WithLocation(1).WithArguments("public", "required"),
55-
},
56-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
48+
Diagnostic().WithLocation(0).WithArguments("public", "required"),
49+
Diagnostic().WithLocation(1).WithArguments("public", "required"),
50+
};
51+
52+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5753
}
5854
}
5955
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/SpacingRules/SA1010CSharp11UnitTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111

1212
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -40,11 +40,7 @@ public void TestMethod(List<int> x)
4040
}}
4141
";
4242

43-
await new CSharpTest()
44-
{
45-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
46-
TestCode = testCode,
47-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
43+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
4844
}
4945
}
5046
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp11/SpacingRules/SA1012CSharp11UnitTests.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.SpacingRules.SA1012OpeningBracesMustBeSpacedCorrectly,
@@ -40,20 +40,16 @@ void M(string[] a)
4040
}
4141
";
4242

43-
await new CSharpTest()
43+
DiagnosticResult[] expected =
4444
{
45-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
46-
TestCode = testCode,
47-
ExpectedDiagnostics =
48-
{
49-
// Opening brace should not be preceded by a space
50-
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
45+
// Opening brace should not be preceded by a space
46+
Diagnostic().WithLocation(0).WithArguments(" not", "preceded"),
5147

52-
// Opening brace should be preceded by a space
53-
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
54-
},
55-
FixedCode = fixedCode,
56-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
48+
// Opening brace should be preceded by a space
49+
Diagnostic().WithLocation(1).WithArguments(string.Empty, "preceded"),
50+
};
51+
52+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
5753
}
5854
}
5955
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/OrderingRules/SA1202CSharp8UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp8.OrderingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp7.OrderingRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.OrderingRules.SA1202ElementsMustBeOrderedByAccess,
12+
StyleCop.Analyzers.OrderingRules.ElementOrderCodeFixProvider>;
713

814
public class SA1202CSharp8UnitTests : SA1202CSharp7UnitTests
915
{
16+
/// <summary>
17+
/// Verifies that the analyzer will properly handle property access levels.
18+
/// </summary>
19+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
20+
[Fact]
21+
public async Task TestPropertiesOfInterfaceAsync()
22+
{
23+
var testCode = @"public interface TestClass
24+
{
25+
private string TestProperty1 { get { return """"; } set { } }
26+
protected string {|#0:TestProperty2|} { get; set; }
27+
protected internal string {|#1:TestProperty3|} { get; set; }
28+
internal string {|#2:TestProperty4|} { get; set; }
29+
public string {|#3:TestProperty5|} { get; set; }
30+
string TestProperty0 { get; set; }
31+
}
32+
";
33+
34+
var fixedCode = @"public interface TestClass
35+
{
36+
public string TestProperty5 { get; set; }
37+
string TestProperty0 { get; set; }
38+
internal string TestProperty4 { get; set; }
39+
protected internal string TestProperty3 { get; set; }
40+
protected string TestProperty2 { get; set; }
41+
private string TestProperty1 { get { return """"; } set { } }
42+
}
43+
";
44+
45+
await new CSharpTest
46+
{
47+
TestCode = testCode,
48+
ExpectedDiagnostics =
49+
{
50+
Diagnostic().WithLocation(0).WithArguments("protected", "private"),
51+
Diagnostic().WithLocation(1).WithArguments("protected internal", "protected"),
52+
Diagnostic().WithLocation(2).WithArguments("internal", "protected internal"),
53+
Diagnostic().WithLocation(3).WithArguments("public", "internal"),
54+
},
55+
FixedCode = fixedCode,
56+
NumberOfIncrementalIterations = 5,
57+
NumberOfFixAllIterations = 2,
58+
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
59+
}
1060
}
1161
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1300CSharp9UnitTests.cs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
108
using Microsoft.CodeAnalysis.Testing;
119
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
12-
using StyleCop.Analyzers.Test.Verifiers;
1310
using Xunit;
1411
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1512
StyleCop.Analyzers.NamingRules.SA1300ElementMustBeginWithUpperCaseLetter,
@@ -40,15 +37,7 @@ public R(int a, int b)
4037
}
4138
";
4239

43-
var test = new CSharpTest()
44-
{
45-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
46-
TestCode = testCode,
47-
FixedCode = fixedCode,
48-
};
49-
var expectedDiagnostics = this.GetExpectedResultTestPositionalRecord1();
50-
test.TestState.ExpectedDiagnostics.AddRange(expectedDiagnostics);
51-
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
40+
await VerifyCSharpFixAsync(testCode, this.GetExpectedResultTestPositionalRecord1(), fixedCode, CancellationToken.None).ConfigureAwait(false);
5241
}
5342

5443
[Fact]
@@ -74,12 +63,7 @@ public R(int a, int b)
7463
}
7564
";
7665

77-
await new CSharpTest()
78-
{
79-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
80-
TestCode = testCode,
81-
FixedCode = fixedCode,
82-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
66+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
8367
}
8468

8569
protected virtual DiagnosticResult[] GetExpectedResultTestPositionalRecord1()

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/NamingRules/SA1313CSharp9UnitTests.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
11-
using StyleCop.Analyzers.Test.Verifiers;
1210
using Xunit;
1311
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1412
StyleCop.Analyzers.NamingRules.SA1313ParameterNamesMustBeginWithLowerCaseLetter,
@@ -41,12 +39,7 @@ public R(int a, int b)
4139
}
4240
";
4341

44-
await new CSharpTest()
45-
{
46-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
47-
TestCode = testCode,
48-
FixedCode = fixedCode,
49-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
42+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, fixedCode, CancellationToken.None).ConfigureAwait(false);
5043
}
5144
}
5245
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1101CSharp9UnitTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
55
{
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
89
using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules;
9-
using StyleCop.Analyzers.Test.Verifiers;
1010
using Xunit;
1111
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1212
StyleCop.Analyzers.ReadabilityRules.SA1101PrefixLocalCallsWithThis,
@@ -31,11 +31,7 @@ public A UpdateA(A value)
3131
}
3232
}";
3333

34-
await new CSharpTest()
35-
{
36-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
37-
TestCode = testCode,
38-
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
34+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
3935
}
4036
}
4137
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1023CSharp9UnitTests.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
75
{
86
using System.Threading;
97
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
11-
using StyleCop.Analyzers.Test.Verifiers;
1210
using Xunit;
1311
using static StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly;
1412
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
@@ -68,21 +66,17 @@ public async Task TestFunctionPointerTypeInvalidSpacingAsync()
6866
}
6967
";
7068

71-
await new CSharpTest()
69+
DiagnosticResult[] expected =
7270
{
73-
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
74-
TestCode = testCode,
75-
FixedCode = fixedCode,
76-
ExpectedDiagnostics =
77-
{
78-
Diagnostic(DescriptorNotPreceded).WithLocation(0),
79-
Diagnostic(DescriptorNotFollowed).WithLocation(1),
80-
Diagnostic(DescriptorNotPreceded).WithLocation(2),
81-
Diagnostic(DescriptorFollowed).WithLocation(3),
82-
Diagnostic(DescriptorNotPreceded).WithLocation(4),
83-
Diagnostic(DescriptorFollowed).WithLocation(5),
84-
},
85-
}.RunAsync().ConfigureAwait(false);
71+
Diagnostic(DescriptorNotPreceded).WithLocation(0),
72+
Diagnostic(DescriptorNotFollowed).WithLocation(1),
73+
Diagnostic(DescriptorNotPreceded).WithLocation(2),
74+
Diagnostic(DescriptorFollowed).WithLocation(3),
75+
Diagnostic(DescriptorNotPreceded).WithLocation(4),
76+
Diagnostic(DescriptorFollowed).WithLocation(5),
77+
};
78+
79+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
8680
}
8781
}
8882
}

0 commit comments

Comments
 (0)