|
| 1 | +using OmniSharp.Extensions.LanguageServer.Client.Handlers; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Xunit; |
| 4 | +using Xunit.Abstractions; |
| 5 | + |
| 6 | +namespace OmniSharp.Extensions.LanguageServerProtocol.Client.Tests |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Tests for <see cref="IHandler"/> and friends. |
| 10 | + /// </summary> |
| 11 | + public class HandlerTests |
| 12 | + : TestBase |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Create a new <see cref="IHandler"/> test suite. |
| 16 | + /// </summary> |
| 17 | + /// <param name="testOutput"> |
| 18 | + /// Output for the current test. |
| 19 | + /// </param> |
| 20 | + public HandlerTests(ITestOutputHelper testOutput) |
| 21 | + : base(testOutput) |
| 22 | + { |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Verify that <see cref="DelegateEmptyNotificationHandler"/> specifies the correct payload type. |
| 27 | + /// </summary> |
| 28 | + [Fact(DisplayName = "DelegateEmptyNotificationHandler specifies correct payload type")] |
| 29 | + public void DelegateEmptyNotificationHandler_PayloadType() |
| 30 | + { |
| 31 | + IHandler handler = new DelegateEmptyNotificationHandler( |
| 32 | + method: "test", |
| 33 | + handler: () => |
| 34 | + { |
| 35 | + // Nothing to do. |
| 36 | + } |
| 37 | + ); |
| 38 | + |
| 39 | + Assert.Null(handler.PayloadType); |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Verify that <see cref="DelegateNotificationHandler"/> specifies the correct payload type. |
| 44 | + /// </summary> |
| 45 | + [Fact(DisplayName = "DelegateNotificationHandler specifies correct payload type")] |
| 46 | + public void DelegateNotificationHandler_PayloadType() |
| 47 | + { |
| 48 | + IHandler handler = new DelegateNotificationHandler<string>( |
| 49 | + method: "test", |
| 50 | + handler: notification => |
| 51 | + { |
| 52 | + // Nothing to do. |
| 53 | + } |
| 54 | + ); |
| 55 | + |
| 56 | + Assert.Equal(typeof(string), handler.PayloadType); |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Verify that <see cref="DelegateRequestHandler{TRequest}"/> specifies the correct payload type (<c>null</c>). |
| 61 | + /// </summary> |
| 62 | + [Fact(DisplayName = "DelegateRequestHandler specifies correct payload type")] |
| 63 | + public void DelegateRequestHandler_PayloadType() |
| 64 | + { |
| 65 | + IHandler handler = new DelegateRequestHandler<string>( |
| 66 | + method: "test", |
| 67 | + handler: (request, cancellationToken) => |
| 68 | + { |
| 69 | + // Nothing to do. |
| 70 | + |
| 71 | + return Task.CompletedTask; |
| 72 | + } |
| 73 | + ); |
| 74 | + |
| 75 | + Assert.Equal(typeof(string), handler.PayloadType); |
| 76 | + } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Verify that <see cref="DelegateRequestResponseHandler{TRequest, TResponse}"/> specifies the correct payload type (<c>null</c>). |
| 80 | + /// </summary> |
| 81 | + [Fact(DisplayName = "DelegateRequestResponseHandler specifies correct payload type")] |
| 82 | + public void DelegateRequestResponseHandler_PayloadType() |
| 83 | + { |
| 84 | + IHandler handler = new DelegateRequestResponseHandler<string, string>( |
| 85 | + method: "test", |
| 86 | + handler: (request, cancellationToken) => |
| 87 | + { |
| 88 | + // Nothing to do. |
| 89 | + |
| 90 | + return Task.FromResult<string>("hello"); |
| 91 | + } |
| 92 | + ); |
| 93 | + |
| 94 | + Assert.Equal(typeof(string), handler.PayloadType); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments