コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public async Task EmptyCode_ReturnsNoErrors()
        {
            var test = @"";

            await EasyVerify <EasyEndpointAnalyzerAnalyzer> .VerifyAnalyzerAsync(test);
        }