public async Task CanFix() { var test = @" using Easy.Endpoints; using System.Threading.Tasks; namespace ConsoleApplication1 { public class GetTestEndpoint : IEndpoint { public int HandleAsync() { return 1; } } }"; var fix = @" using Easy.Endpoints; using System.Threading.Tasks; namespace ConsoleApplication1 { public class GetTestEndpoint : IEndpoint { public int Handle() { return 1; } } }"; var expected = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.SyncForHandleAsync) .WithLocation(8, 24); await EasyVerify <EasyEndpointAnalyzerAnalyzer, EasyEndpointAnalyzerCodeFixProvider> .VerifyCodeFixAsync(test, expected, fix); }
public async Task MultipleValidMethod_ReturnsWarningForEach() { var test = @" using Easy.Endpoints; namespace ConsoleApplication1 { public class GetTestEndpoint : IEndpoint { public void Handle() { } public void Handle(int id) { } } }"; var expected1 = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.Multiple) .WithLocation(8, 13) .WithArguments("GetTestEndpoint", 2); var expected2 = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.Multiple) .WithLocation(12, 13) .WithArguments("GetTestEndpoint", 2); await EasyVerify <EasyEndpointAnalyzerAnalyzer> .VerifyAnalyzerAsync(test, expected1, expected2); }
public async Task CanFix() { var test = @" using Easy.Endpoints; using System.Threading.Tasks; namespace ConsoleApplication1 { internal class GetTestEndpoint : IEndpoint { public ValueTask<int> Handle() { return ValueTask.FromResult(1); } } }"; var fix = @" using Easy.Endpoints; using System.Threading.Tasks; namespace ConsoleApplication1 { internal class GetTestEndpoint : IEndpoint { public ValueTask<int> HandleAsync() { return ValueTask.FromResult(1); } } }"; var expected = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.AsyncForHandle) .WithLocation(8, 35); await EasyVerify <EasyEndpointAnalyzerAnalyzer, EasyEndpointAnalyzerCodeFixProvider> .VerifyCodeFixAsync(test, expected, fix); }
public async Task WhenHandleAsync_Returns_Void_ReturnsWarning() { var test = @" using Easy.Endpoints; using System.Threading.Tasks; namespace ConsoleApplication1 { public class GetTestEndpoint : IEndpoint { public void HandleAsync() { } } }"; var expected = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.SyncForHandleAsync) .WithLocation(8, 25); await EasyVerify <EasyEndpointAnalyzerAnalyzer> .VerifyAnalyzerAsync(test, expected); }
public async Task NoValidMethod_ReturnsNoHandlerMethod() { var test = @" using Easy.Endpoints; namespace ConsoleApplication1 { public class GetTestEndpoint : IEndpoint { public void Nope() { } } }"; var expected = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.Empty) .WithLocation(6, 22) .WithArguments("GetTestEndpoint"); await EasyVerify <EasyEndpointAnalyzerAnalyzer> .VerifyAnalyzerAsync(test, expected); }
public async Task WhenHandle_Returns_ValueTask_T_ReturnsWarning() { var test = @" using Easy.Endpoints; using System.Threading.Tasks; namespace ConsoleApplication1 { public class GetTestEndpoint : IEndpoint { public ValueTask<int> Handle() { return ValueTask.FromResult(1); } } }"; var expected = EasyVerify <EasyEndpointAnalyzerAnalyzer> .Diagnostic(EasyEndpointWarnings.AsyncForHandle) .WithLocation(8, 35); await EasyVerify <EasyEndpointAnalyzerAnalyzer> .VerifyAnalyzerAsync(test, expected); }
public async Task EmptyCode_ReturnsNoErrors() { var test = @""; await EasyVerify <EasyEndpointAnalyzerAnalyzer> .VerifyAnalyzerAsync(test); }