Skip to content

Commit e44a57a

Browse files
committed
Updated Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit and fixed remaining issues
1 parent f5fef3b commit e44a57a

6 files changed

Lines changed: 35 additions & 11 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/NamingRules/SA1313CSharp8UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp8.NamingRules
55
{
6+
using Microsoft.CodeAnalysis.Testing;
67
using StyleCop.Analyzers.Test.CSharp7.NamingRules;
78

89
public class SA1313CSharp8UnitTests : SA1313CSharp7UnitTests
910
{
11+
protected override DiagnosticResult[] GetInvalidMethodOverrideShouldNotProduceDiagnosticAsyncDiagnostics()
12+
{
13+
return new DiagnosticResult[]
14+
{
15+
DiagnosticResult.CompilerError("CS0534").WithLocation(9, 18).WithMessage("'TestClass' does not implement inherited abstract member 'BaseClass.TestMethod(int, int)'"),
16+
DiagnosticResult.CompilerError("CS0246").WithLocation(11, 49).WithMessage("The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)"),
17+
DiagnosticResult.CompilerError("CS1001").WithLocation(11, 51).WithMessage("Identifier expected"),
18+
DiagnosticResult.CompilerError("CS1003").WithLocation(11, 51).WithMessage("Syntax error, ',' expected"),
19+
};
20+
}
1021
}
1122
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/MaintainabilityRules/DebugMessagesUnitTestsBase.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public async Task TestConstantMessage_Field_PassExpressionAsync()
4444
[Fact]
4545
public async Task TestConstantMessage_Field_PassWrongTypeAsync()
4646
{
47-
LinePosition linePosition = new LinePosition(3, 27);
47+
var startLinePosition = new LinePosition(3, 27);
48+
var endLinePosition = new LinePosition(3, 28);
4849
DiagnosticResult[] expected =
4950
{
50-
DiagnosticResult.CompilerError("CS0029").WithSpan(new FileLinePositionSpan("Test0.cs", linePosition, linePosition)).WithMessage("Cannot implicitly convert type 'int' to 'string'"),
51+
DiagnosticResult.CompilerError("CS0029").WithSpan(new FileLinePositionSpan("Test0.cs", startLinePosition, endLinePosition)).WithMessage("Cannot implicitly convert type 'int' to 'string'"),
5152
};
5253

5354
await this.TestConstantMessage_Field_PassExecuterAsync("3", expected).ConfigureAwait(false);
@@ -68,10 +69,11 @@ public async Task TestConstantMessage_Local_PassExpressionAsync()
6869
[Fact]
6970
public async Task TestConstantMessage_Local_PassWrongTypeAsync()
7071
{
71-
LinePosition linePosition = new LinePosition(5, 31);
72+
var startLinePosition = new LinePosition(5, 31);
73+
var endLinePosition = new LinePosition(5, 32);
7274
DiagnosticResult[] expected =
7375
{
74-
DiagnosticResult.CompilerError("CS0029").WithSpan(new FileLinePositionSpan("Test0.cs", linePosition, linePosition)).WithMessage("Cannot implicitly convert type 'int' to 'string'"),
76+
DiagnosticResult.CompilerError("CS0029").WithSpan(new FileLinePositionSpan("Test0.cs", startLinePosition, endLinePosition)).WithMessage("Cannot implicitly convert type 'int' to 'string'"),
7577
};
7678

7779
await this.TestConstantMessage_Local_PassExecuterAsync("3", expected).ConfigureAwait(false);
@@ -92,10 +94,11 @@ public async Task TestConstantMessage_Inline_PassExpressionAsync()
9294
[Fact]
9395
public async Task TestConstantMessage_Inline_PassWrongTypeAsync()
9496
{
95-
LinePosition linePosition = new LinePosition(5, 15 + this.MethodName.Length + this.InitialArguments.Sum(i => i.Length + ", ".Length));
97+
var startLinePosition = new LinePosition(5, 15 + this.MethodName.Length + this.InitialArguments.Sum(i => i.Length + ", ".Length));
98+
var endLinePosition = new LinePosition(startLinePosition.Line, startLinePosition.Character + 1);
9699
DiagnosticResult[] expected =
97100
{
98-
DiagnosticResult.CompilerError("CS1503").WithSpan(new FileLinePositionSpan("Test0.cs", linePosition, linePosition)).WithMessage($"Argument {1 + this.InitialArguments.Count()}: cannot convert from 'int' to 'string'"),
101+
DiagnosticResult.CompilerError("CS1503").WithSpan(new FileLinePositionSpan("Test0.cs", startLinePosition, endLinePosition)).WithMessage($"Argument {1 + this.InitialArguments.Count()}: cannot convert from 'int' to 'string'"),
99102
};
100103

101104
await this.TestConstantMessage_Inline_PassExecuterAsync("3", expected).ConfigureAwait(false);

StyleCop.Analyzers/StyleCop.Analyzers.Test/NamingRules/SA1313UnitTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,16 +560,21 @@ public override void TestMethod(int p1, X int P2)
560560
}
561561
}
562562
";
563-
DiagnosticResult[] expected =
563+
DiagnosticResult[] expected = this.GetInvalidMethodOverrideShouldNotProduceDiagnosticAsyncDiagnostics();
564+
565+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
566+
}
567+
568+
protected virtual DiagnosticResult[] GetInvalidMethodOverrideShouldNotProduceDiagnosticAsyncDiagnostics()
569+
{
570+
return new DiagnosticResult[]
564571
{
565572
DiagnosticResult.CompilerError("CS0534").WithLocation(9, 18).WithMessage("'TestClass' does not implement inherited abstract member 'BaseClass.TestMethod(int, int)'"),
566573
DiagnosticResult.CompilerError("CS0115").WithLocation(11, 30).WithMessage("'TestClass.TestMethod(int, X, int)': no suitable method found to override"),
567574
DiagnosticResult.CompilerError("CS0246").WithLocation(11, 49).WithMessage("The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)"),
568575
DiagnosticResult.CompilerError("CS1001").WithLocation(11, 51).WithMessage("Identifier expected"),
569576
DiagnosticResult.CompilerError("CS1003").WithLocation(11, 51).WithMessage("Syntax error, ',' expected"),
570577
};
571-
572-
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
573578
}
574579
}
575580
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/StyleCop.Analyzers.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.CodeAnalysis" Version="1.2.1" />
21-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.0-beta1.19212.1" />
21+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.0.0-beta1.19216.2" />
2222
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="15.6.36" />
2323
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
2424
<PackageReference Include="xunit" Version="2.3.1" />

StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/DiagnosticVerifierTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int PropertyName
104104
{
105105
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
106106
}).ConfigureAwait(false);
107-
Assert.StartsWith($"Context: Diagnostics of test state{Environment.NewLine}Expected:\nA project diagnostic with No location\nActual:\n", ex.Message);
107+
Assert.StartsWith($"Context: Diagnostics of test state{Environment.NewLine}Expected:{Environment.NewLine}A project diagnostic with No location{Environment.NewLine}Actual:{Environment.NewLine}", ex.Message);
108108
}
109109

110110
[Fact]

StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/StyleCopCodeFixVerifier`2.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace StyleCop.Analyzers.Test.Verifiers
55
{
66
using System;
77
using System.Collections.Generic;
8+
using System.Reflection;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using global::LightJson;
@@ -112,6 +113,7 @@ public CSharpTest(LanguageVersion? languageVersion)
112113
.WithChangedOption(FormattingOptions.UseTabs, this.Language, this.UseTabs));
113114

114115
this.TestState.AdditionalReferences.Add(GenericAnalyzerTest.CSharpSymbolsReference);
116+
this.TestState.AdditionalReferences.Add(Netstandard20Reference);
115117
this.TestState.AdditionalFilesFactories.Add(GenerateSettingsFile);
116118
this.CodeFixValidationMode = CodeFixValidationMode.None;
117119

@@ -229,6 +231,9 @@ public CSharpTest(LanguageVersion? languageVersion)
229231
/// </value>
230232
public List<string> ExplicitlyEnabledDiagnostics { get; } = new List<string>();
231233

234+
private static Assembly Netstandard20Reference
235+
=> Assembly.Load("netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51");
236+
232237
protected override CompilationOptions CreateCompilationOptions()
233238
{
234239
var compilationOptions = base.CreateCompilationOptions();

0 commit comments

Comments
 (0)