public async Task WithElvisOperatorCreatesDiagnostic(string methodName, DiagnosticId diagnosticId) { var source = $@" using System; using System.Linq; class TypeSymbol {{ public System.Collections.Generic.IList<int> AllInterfaces; }} class TypeName {{ void Foo() {{ var typeSymbol = new TypeSymbol(); var y = typeSymbol?.AllInterfaces.{methodName}(i => i == 1); }} }}"; var expected = new DiagnosticResult { Id = diagnosticId.ToDiagnosticId(), Message = diagnosticId == DiagnosticId.ChangeAnyToAll ? ChangeAnyToAllAnalyzer.MessageAny : ChangeAnyToAllAnalyzer.MessageAll, Severity = DiagnosticSeverity.Hidden, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 13, 43) } }; await VerifyCSharpDiagnosticAsync(source, expected); }
public async Task AnyAndAllWithLinqCreatesDiagnostic(string code, int column, DiagnosticId diagnosticId) { var source = code.WrapInCSharpMethod(usings: "\nusing System.Linq;"); var expected = new DiagnosticResult(diagnosticId.ToDiagnosticId(), DiagnosticSeverity.Hidden) .WithLocation(13, column) .WithMessage(diagnosticId == DiagnosticId.ChangeAnyToAll ? ChangeAnyToAllAnalyzer.MessageAny : ChangeAnyToAllAnalyzer.MessageAll); await VerifyCSharpDiagnosticAsync(source, expected); }
private static DiagnosticResult CreateNameofDiagnosticResult(string nameofArgument, int diagnosticLine, int diagnosticColumn, DiagnosticId id = DiagnosticId.NameOf) { return(new DiagnosticResult { Id = id.ToDiagnosticId(), Message = $"Use 'nameof({nameofArgument})' instead of specifying the program element name.", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", diagnosticLine, diagnosticColumn) } }); }
public async Task NegationWithCoalesceExpressionCreatesDiagnostic(string methodName, DiagnosticId diagnosticId) { var source = $@" var ints = new [] {{ 1 }}; var query = !ints?.{methodName}(i => i == 1) ?? true;"; var expected = new DiagnosticResult(diagnosticId.ToDiagnosticId(), DiagnosticSeverity.Hidden) .WithLocation(13, 20) .WithMessage(diagnosticId == DiagnosticId.ChangeAnyToAll ? ChangeAnyToAllAnalyzer.MessageAny : ChangeAnyToAllAnalyzer.MessageAll); await VerifyCSharpDiagnosticAsync(source.WrapInCSharpMethod(usings: "\nusing System.Linq;"), expected); }
public async Task ExpressionBodiedMemberCreatesDiagnostic(string methodName, DiagnosticId diagnosticId) { var source = $@" using System; using System.Linq; class TypeName {{ private System.Collections.Generic.IList<int> xs; bool Foo() => xs.{methodName}(i => i == 1); }}"; var expected = new DiagnosticResult(diagnosticId.ToDiagnosticId(), DiagnosticSeverity.Hidden) .WithLocation(7, 22) .WithMessage(diagnosticId == DiagnosticId.ChangeAnyToAll ? ChangeAnyToAllAnalyzer.MessageAny : ChangeAnyToAllAnalyzer.MessageAll); await VerifyCSharpDiagnosticAsync(source, expected); }
public static string ForDiagnostic(DiagnosticId diagnosticId) => $"https://code-cracker.github.io/diagnostics/{diagnosticId.ToDiagnosticId()}.html";
private static DiagnosticResult CreateNameofDiagnosticResult(string nameofArgument, int diagnosticLine, int diagnosticColumn, DiagnosticId id = DiagnosticId.NameOf) { return(new DiagnosticResult(id.ToDiagnosticId(), DiagnosticSeverity.Warning) .WithLocation(diagnosticLine, diagnosticColumn) .WithMessage($"Use 'nameof({nameofArgument})' instead of specifying the program element name.")); }