public void Should_Update_CodeLens_Removing_HandlerType() { // Given var handlerMatcher = new ResolveCommandMatcher(_logger); var resolveHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); (resolveHandler as ICodeLensResolveHandler).CanResolve(Arg.Any <CodeLens>()).Returns(true); var descriptor = new HandlerDescriptor( DocumentNames.CodeLensResolve, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLens), null, null, () => { }); var item = new CodeLens() { Data = JObject.FromObject(new { data = new { hello = "world" } }) }; item.Data[ResolveCommandMatcher.PrivateHandlerTypeName] = resolveHandler.GetType().FullName; // When var response = handlerMatcher.Process(descriptor, item); // Then response.Should().Be(item); item.Data?[ResolveCommandMatcher.PrivateHandlerTypeName].Should().BeNull(); item.Data["hello"].Value <string>().Should().Be("world"); }
public void Should_Not_Throw_Given_Another_Descriptor() { // Given var resolveHandler = Substitute.For <ICodeLensHandler>(); var handlerDescriptor = new HandlerDescriptor( DocumentNames.CodeLens, "Key", resolveHandler, resolveHandler.GetType(), typeof(CodeLensParams), null, null, () => { }); var handlerMatcher = new ResolveCommandMatcher(_logger); // When Action a = () => handlerMatcher.Process(handlerDescriptor, new CodeLensParams(), new CodeLensContainer()); a.ShouldNotThrow(); }
public void Should_Update_CodeLensContainer_With_HandlerType() { // Given var handlerMatcher = new ResolveCommandMatcher(_logger); var resolveHandler = Substitute.For(new Type[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); (resolveHandler as ICodeLensResolveHandler).CanResolve(Arg.Any <CodeLens>()).Returns(true); var descriptor = new HandlerDescriptor( DocumentNames.CodeLens, "Key", resolveHandler as IJsonRpcHandler, resolveHandler.GetType(), typeof(CodeLensParams), null, null, () => { }); var item = new CodeLens() { Data = JObject.FromObject(new { hello = "world" }) }; var list = new CodeLensContainer(new[] { item }); (list is IEnumerable <ICanBeResolved>).Should().BeTrue(); // When var response = handlerMatcher.Process(descriptor, new CodeLensParams(), list); // Then response.Should().Be(list); (response as CodeLensContainer).Should().Contain(item); var responseItem = (response as CodeLensContainer).First(); responseItem.Data[ResolveCommandMatcher.PrivateHandlerTypeName].Value <string>().Should().NotBeNullOrEmpty(); responseItem.Data[ResolveCommandMatcher.PrivateHandlerKey].Value <string>().Should().NotBeNullOrEmpty(); responseItem.Data["data"]["hello"].Value <string>().Should().Be("world"); }