示例#1
0
        public void Should_Contain_AllDefinedMethods_OnLanguageServer_WithDifferentKeys(Type requestHandler, Type type2, string key, string key2, int count)
        {
            var handler = new HandlerCollection();
            var sub     = (IJsonRpcHandler)Substitute.For(new Type[] { requestHandler, type2 }, new object[0]);

            if (sub is IRegistration <TextDocumentRegistrationOptions> reg)
            {
                reg.GetRegistrationOptions()
                .Returns(new TextDocumentRegistrationOptions()
                {
                    DocumentSelector = new DocumentSelector()
                });
            }
            var sub2 = (IJsonRpcHandler)Substitute.For(new Type[] { requestHandler, type2 }, new object[0]);

            if (sub2 is IRegistration <TextDocumentRegistrationOptions> reg2)
            {
                reg2.GetRegistrationOptions()
                .Returns(new TextDocumentRegistrationOptions()
                {
                    DocumentSelector = new DocumentSelector()
                });
            }
            handler.Add(sub);
            handler.Add(sub2);
            handler._handlers.Should().Contain(x => x.Method == key);
            handler._handlers.Should().Contain(x => x.Method == key2);
            handler._handlers.Count.Should().Be(count);
        }
示例#2
0
        public void Should_AllowSpecificHandlers_ToBeAdded(string method, Type handlerType)
        {
            var handler = new HandlerCollection();
            var sub     = (IJsonRpcHandler)Substitute.For(new Type[] { handlerType }, new object[0]);
            var sub2    = (IJsonRpcHandler)Substitute.For(new Type[] { handlerType }, new object[0]);

            handler.Add(method, sub);
            handler.Add(method, sub2);
            handler._handlers.Should().Contain(x => x.Method == method);
            handler._handlers.Should().Contain(x => x.Method == method);
            handler._handlers.Count.Should().Be(1);
        }
示例#3
0
        public void Should_Contain_AllDefinedMethods_ForDifferentKeys(string key, int count)
        {
            var handler = new HandlerCollection();
            var sub     = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"));

            var sub2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"));

            handler.Add(sub);
            handler.Add(sub2);
            handler._handlers.Should().Contain(x => x.Method == key);
            handler._handlers.Count.Should().Be(count);
        }
示例#4
0
        public void Should_Contain_AllDefinedTextDocumentSyncMethods(string key, int count)
        {
            var handler = new HandlerCollection();
            var sub     = (IJsonRpcHandler)TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.something"));

            handler.Add(sub);
            handler._handlers.Should().Contain(x => x.Method == key);
            handler._handlers.Count.Should().Be(count);
        }
示例#5
0
        public void Should_Contain_AllDefinedMethods(Type requestHandler, string key, int count)
        {
            var handler = new HandlerCollection();
            var sub     = (IJsonRpcHandler)Substitute.For(new Type[] { requestHandler }, new object[0]);

            handler.Add(sub);
            handler._handlers.Should().Contain(x => x.Method == key);
            handler._handlers.Count.Should().Be(count);
        }
        public void Should_DealWithClassesThatImplementMultipleHandlers_WithoutConflictingRegistrations(string method, IJsonRpcHandler sub)
        {
            var handler = new HandlerCollection();

            handler.Add(sub);

            var descriptor = handler._handlers.First(x => x.Method == method);

            descriptor.Key.Should().Be("default");
        }
示例#7
0
        public void Should_Contain_AllDefinedLanguageServerMethods(string key, int count)
        {
            var handler = new HandlerCollection();

            handler.Add(
                Substitute.For <IInitializeHandler>(),
                Substitute.For <IInitializedHandler>(),
                Substitute.For <IExitHandler>(),
                Substitute.For <IShutdownHandler>()
                );
            handler._handlers.Should().Contain(x => x.Method == key);
            handler._handlers.Count.Should().Be(count);
        }
示例#8
0
        public void Should_Contain_AllConcreteDefinedMethods()
        {
            var handler = new HandlerCollection();

            handler.Add(
                Substitute.For <IExitHandler>(),
                Substitute.For <IInitializeHandler>(),
                Substitute.For <IInitializedHandler>(),
                Substitute.For <IShutdownHandler>()
                );

            handler._handlers.Should().Contain(x => x.Method == "exit");
            handler._handlers.Should().Contain(x => x.Method == "shutdown");
            handler._handlers.Count.Should().Be(4);
        }
示例#9
0
        public void Should_DealWithClassesThatImplementMultipleHandlers_BySettingKeyAccordingly()
        {
            var codeLensHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]);

            ((ICodeLensHandler)codeLensHandler).GetRegistrationOptions()
            .Returns(new CodeLensRegistrationOptions()
            {
                DocumentSelector = new DocumentSelector(DocumentFilter.ForLanguage("foo"))
            });

            var handler = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue);

            handler.Add(codeLensHandler as IJsonRpcHandler);

            var descriptor = handler._handlers.Select(x => x.Key);

            descriptor.Should().BeEquivalentTo(new [] { "[foo]", "[foo]" });
        }
示例#10
0
        public void Should_Contain_AllDefinedLanguageServerMethods_GivenDuplicates(string key, int count)
        {
            var handler = new HandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue);

            handler.Add(
                Substitute.For <IInitializeHandler>(),
                Substitute.For <IInitializedHandler>(),
                Substitute.For <IExitHandler>(),
                Substitute.For <IShutdownHandler>(),
                Substitute.For <IInitializeHandler>(),
                Substitute.For <IInitializedHandler>(),
                Substitute.For <IExitHandler>(),
                Substitute.For <IShutdownHandler>(),
                Substitute.For <IInitializeHandler>(),
                Substitute.For <IInitializedHandler>(),
                Substitute.For <IExitHandler>(),
                Substitute.For <IShutdownHandler>()
                );
            handler._handlers.Should().Contain(x => x.Method == key);
            handler._handlers.Count.Should().Be(count);
        }