public void RA019_DA_VBRenameMisspelledAsync() { var body = @" imports System imports System.Threading.Tasks Module Module1 Async Function exampleasycn() As Task End Function End Module "; var test = body; DiagnosticResult expectedvb = new DiagnosticResult { Id = "Async002", Message = "This method is async but the method name does not end in Async", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.vb", 7, 20) } }; VerifyBasicDiagnostic(test, expectedvb); }
public void AV023_DA_VBDiagnosticSimple() { var body = @" Module Module1 Async Sub example() Await Task.Delay(100) End Sub End Module "; var test = body; DiagnosticResult expected001vb = new DiagnosticResult { Id = "Async001", Message = "This method has the async keyword but it returns void", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.vb", 4, 15) } }; VerifyBasicDiagnostic(test, expected001vb); }
public void RA017_DACF_MultipleMisspellings() { var body = @" private async Task Wait10Asycn() { await Task.Delay(10); } private async Task Wait50Aysnc() { await Task.Delay(50); } private async Task Wait100Ayscn() { await Task.Delay(100); } private async Task Wait200asycn() { await Task.Delay(200); }"; var test = DefaultHeader + body + DefaultFooter; DiagnosticResult expected1 = new DiagnosticResult { Id = "Async002", Message = "This method is async but the method name does not end in Async", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 13, 28) } }; DiagnosticResult expected2 = new DiagnosticResult { Id = "Async002", Message = "This method is async but the method name does not end in Async", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 17, 28) } }; DiagnosticResult expected3 = new DiagnosticResult { Id = "Async002", Message = "This method is async but the method name does not end in Async", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 21, 28) } }; DiagnosticResult expected4 = new DiagnosticResult { Id = "Async002", Message = "This method is async but the method name does not end in Async", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 25, 28) } }; VerifyCSharpDiagnostic(test, expected1, expected2, expected3, expected4); var fixbody = @" private async Task Wait10Async() { await Task.Delay(10); } private async Task Wait50Async() { await Task.Delay(50); } private async Task Wait100Async() { await Task.Delay(100); } private async Task Wait200Async() { await Task.Delay(200); }"; var fixtest = DefaultHeader + fixbody + DefaultFooter; VerifyCSharpFix(test, fixtest); }
// Containing methods have multiple invocations where a token can be passed - 1 diagnostic public void C009_DACF_MultipleNoPassInContainingMethod() { var body = @" public void BigMethod(int a, string b, CancellationToken cancellationToken, double c) { SmallMethod(b, c); SmallMethod(b, c, CancellationToken.None); SmallMethod(b, c); return; } public void SmallMethod(string b, double c = 0.5, CancellationToken cancellationToken = default(CancellationToken)){ return; }"; var test = DefaultHeader + body + DefaultFooter; DiagnosticResult expected1 = new DiagnosticResult { Id = "Async005", Message = "This method can take a CancellationToken", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 16, 13) } }; DiagnosticResult expected2 = new DiagnosticResult { Id = "Async005", Message = "This method can take a CancellationToken", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 18, 13) } }; VerifyCSharpDiagnostic(test, expected1, expected2); var fixbody = @" public void BigMethod(int a, string b, CancellationToken cancellationToken, double c) { SmallMethod(b, c, cancellationToken); SmallMethod(b, c, CancellationToken.None); SmallMethod(b, c, cancellationToken); return; } public void SmallMethod(string b, double c = 0.5, CancellationToken cancellationToken = default(CancellationToken)){ return; }"; var fixtest = DefaultHeader + fixbody + DefaultFooter; VerifyCSharpFix(test, fixtest); }