Last active
May 3, 2020 21:55
-
-
Save aalmada/74290278b45475b84405e494b79ea380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RefEnumerationVariableAnalyzerTests : CodeFixVerifier | |
{ | |
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer() | |
=> new RefEnumerationVariableAnalyzer(); | |
protected override CodeFixProvider GetCSharpCodeFixProvider() | |
=> new RefEnumerationVariableCodeFixProvider(); | |
[Theory] | |
[InlineData("TestData/HLQ004/NoDiagnostic/NoRef.cs")] | |
[InlineData("TestData/HLQ004/NoDiagnostic/Ref.cs")] | |
[InlineData("TestData/HLQ004/NoDiagnostic/RefReadOnly.cs")] | |
public void Verify_NoDiagnostics(string path) | |
{ | |
var paths = new[] | |
{ | |
path, | |
"TestData/TestType.cs", | |
"TestData/Enumerable.cs", | |
"TestData/HLQ004/RefEnumerables.cs", | |
}; | |
var sources = paths.Select(path => File.ReadAllText(path)).ToArray(); | |
VerifyCSharpDiagnostic(sources); | |
} | |
[Theory] | |
[InlineData("TestData/HLQ004/Diagnostic/Ref.cs", "ref", "TestData/HLQ004/Diagnostic/Ref.Fix.cs", 7, 22)] | |
[InlineData("TestData/HLQ004/Diagnostic/RefReadOnly.cs", "ref readonly", "TestData/HLQ004/Diagnostic/RefReadOnly.Fix.cs", 9, 22)] | |
public void Verify_Diagnostics(string path, string message, string fix, int line, int column) | |
{ | |
var paths = new[] | |
{ | |
path, | |
"TestData/TestType.cs", | |
"TestData/Enumerable.cs", | |
"TestData/HLQ004/RefEnumerables.cs", | |
}; | |
var sources = paths.Select(path => File.ReadAllText(path)).ToArray(); | |
var expected = new DiagnosticResult | |
{ | |
Id = "HLQ004", | |
Message = $"The enumerator returns a reference to the item. Add '{message}' to the item type.", | |
Severity = DiagnosticSeverity.Warning, | |
Locations = new[] { | |
new DiagnosticResultLocation("Test0.cs", line, column) | |
}, | |
}; | |
VerifyCSharpDiagnostic(sources, expected); | |
VerifyCSharpFix(sources, File.ReadAllText(fix)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment