Пример #1
0
        public void Should_Handle_Simple_Json_Data()
        {
            // Given
            var handlerMatcher = new ResolveCommandMatcher(_logger);
            var resolveHandler = Substitute.For <ICompletionResolveHandler>();

            resolveHandler.CanResolve(Arg.Any <CompletionItem>()).Returns(true);

            // When
            var result = handlerMatcher.FindHandler(new CompletionItem()
            {
                Data = new Uri("file:///c%3A/Users/mb/src/gh/Cake.Json/src/Cake.Json/Namespaces.cs")
            },
                                                    new List <HandlerDescriptor> {
                new HandlerDescriptor(DocumentNames.CompletionResolve,
                                      "Key",
                                      resolveHandler,
                                      resolveHandler.GetType(),
                                      typeof(CompletionItem),
                                      null,
                                      null,
                                      () => { }),
            })
                         .ToArray();

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Handler == resolveHandler);
        }
Пример #2
0
        public void Should_Return_Empty_Descriptor()
        {
            // Given
            var handlerDescriptors = Enumerable.Empty <ILspHandlerDescriptor>();
            var handlerMatcher     = new ResolveCommandMatcher(_logger);

            // When
            var result = handlerMatcher.FindHandler(1, handlerDescriptors);

            // Then
            result.Should().BeEmpty();
        }
Пример #3
0
        public void Should_Deal_WithHandlers_That_Not_Also_Resolvers2()
        {
            // Given
            var handlerMatcher = new ResolveCommandMatcher(_logger);
            var resolveHandler = Substitute.For <ICompletionResolveHandler>();

            resolveHandler.CanResolve(Arg.Any <CompletionItem>()).Returns(true);
            var resolveHandler2 = Substitute.For(new Type[] {
                typeof(ICompletionHandler),
                typeof(ICompletionResolveHandler)
            }, new object[0]);

            (resolveHandler2 as ICompletionResolveHandler).CanResolve(Arg.Any <CompletionItem>()).Returns(false);

            // When
            var result = handlerMatcher.FindHandler(new CompletionItem()
            {
                Data = new JObject()
            },
                                                    new List <HandlerDescriptor> {
                new HandlerDescriptor(DocumentNames.CompletionResolve,
                                      "Key",
                                      resolveHandler,
                                      resolveHandler.GetType(),
                                      typeof(CompletionItem),
                                      null,
                                      null,
                                      () => { }),
                new HandlerDescriptor(DocumentNames.CompletionResolve,
                                      "Key2",
                                      resolveHandler2 as IJsonRpcHandler,
                                      typeof(ICompletionResolveHandler),
                                      typeof(CompletionItem),
                                      null,
                                      null,
                                      () => { }),
            })
                         .ToArray();

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Handler == resolveHandler);
        }
Пример #4
0
        public void Should_Return_CodeLensResolve_Descriptor()
        {
            // Given
            var handlerMatcher  = new ResolveCommandMatcher(_logger);
            var resolveHandler  = Substitute.For <ICodeLensResolveHandler>();
            var resolveHandler2 = Substitute.For <ICodeLensResolveHandler>();

            resolveHandler.CanResolve(Arg.Any <CodeLens>()).Returns(false);
            resolveHandler2.CanResolve(Arg.Any <CodeLens>()).Returns(true);

            // When
            var result = handlerMatcher.FindHandler(new CodeLens()
            {
                Data = JToken.FromObject(new { handlerType = typeof(ICodeLensResolveHandler).FullName, data = new { a = 1 } })
            },
                                                    new List <HandlerDescriptor> {
                new HandlerDescriptor(DocumentNames.CodeLensResolve,
                                      "Key",
                                      resolveHandler,
                                      resolveHandler.GetType(),
                                      typeof(CodeLens),
                                      null,
                                      null,
                                      () => { }),
                new HandlerDescriptor(DocumentNames.CodeLensResolve,
                                      "Key2",
                                      resolveHandler2,
                                      typeof(ICodeLensResolveHandler),
                                      typeof(CodeLens),
                                      null,
                                      null,
                                      () => { }),
            })
                         .ToArray();

            // Then
            result.Should().NotBeNullOrEmpty();
            result.Should().Contain(x => x.Handler == resolveHandler2);
        }