|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using FluentAssertions; |
| 4 | +using Microsoft.Extensions.DependencyInjection; |
| 5 | +using NSubstitute; |
| 6 | +using OmniSharp.Extensions.JsonRpc; |
| 7 | +using OmniSharp.Extensions.JsonRpc.Testing; |
| 8 | +using OmniSharp.Extensions.LanguageProtocol.Testing; |
| 9 | +using OmniSharp.Extensions.LanguageServer.Protocol; |
| 10 | +using OmniSharp.Extensions.LanguageServer.Protocol.Document; |
| 11 | +using Xunit; |
| 12 | +using Xunit.Abstractions; |
| 13 | + |
| 14 | +namespace Lsp.Tests.Integration |
| 15 | +{ |
| 16 | + public class HandlersManagerIntegrationTests : LanguageProtocolTestBase |
| 17 | + { |
| 18 | + public HandlersManagerIntegrationTests(ITestOutputHelper testOutputHelper) : base(new JsonRpcTestOptions().ConfigureForXUnit(testOutputHelper)) |
| 19 | + { |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public async Task Should_Return_Default_Handlers() |
| 24 | + { |
| 25 | + var (client, server) = await Initialize(options => {}, options => {}); |
| 26 | + |
| 27 | + var handlersManager = server.GetRequiredService<IHandlersManager>(); |
| 28 | + handlersManager.Descriptors.Should().HaveCount(8); |
| 29 | + handlersManager.GetHandlers().Should().HaveCount(5); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public async Task Should_Return_Additional_Handlers() |
| 34 | + { |
| 35 | + var (client, server) = await Initialize(options => {}, options => {}); |
| 36 | + |
| 37 | + server.Register(o => o.AddHandler(Substitute.For(new Type[] { typeof (ICompletionHandler), typeof(ICompletionResolveHandler) }, Array.Empty<object>()) as IJsonRpcHandler)); |
| 38 | + var handlersManager = server.GetRequiredService<IHandlersManager>(); |
| 39 | + handlersManager.Descriptors.Should().HaveCount(10); |
| 40 | + handlersManager.GetHandlers().Should().HaveCount(6); |
| 41 | + } |
| 42 | + |
| 43 | + [Fact] |
| 44 | + public async Task Link_Should_Fail_If_No_Handler_Is_Defined() |
| 45 | + { |
| 46 | + var (client, server) = await Initialize(options => {}, options => {}); |
| 47 | + |
| 48 | + var handlersManager = server.GetRequiredService<IHandlersManager>(); |
| 49 | + |
| 50 | + Action a = () => handlersManager.AddLink(TextDocumentNames.Completion, "my/completion"); |
| 51 | + a.Should().Throw<ArgumentException>().Which.Message.Should().Contain("Descriptors must be registered before links can be created"); |
| 52 | + } |
| 53 | + |
| 54 | + [Fact] |
| 55 | + public async Task Link_Should_Fail_If_Link_Is_On_The_Wrong_Side() |
| 56 | + { |
| 57 | + var (client, server) = await Initialize(options => {}, options => {}); |
| 58 | + |
| 59 | + server.Register(o => o.AddHandler(Substitute.For(new Type[] { typeof (ICompletionHandler), typeof(ICompletionResolveHandler) }, Array.Empty<object>()) as IJsonRpcHandler)); |
| 60 | + var handlersManager = server.GetRequiredService<IHandlersManager>(); |
| 61 | + |
| 62 | + Action a = () => handlersManager.AddLink("my/completion", TextDocumentNames.Completion); |
| 63 | + a.Should().Throw<ArgumentException>().Which.Message.Should().Contain($"Did you mean to link '{TextDocumentNames.Completion}' to 'my/completion' instead"); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments