public async Task ShouldRouteToCorrect_Notification_WithManyHandlers() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake")); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>()).Returns(Task.CompletedTask); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>()).Returns(Task.CompletedTask); var collection = new HandlerCollection { textDocumentSyncHandler, textDocumentSyncHandler2 }; var mediator = new LspRequestRouter(collection, _testLoggerFactory); var @params = new DidSaveTextDocumentParams() { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cake")) }; var request = new Notification("textDocument/didSave", JObject.Parse(JsonConvert.SerializeObject(@params))); await mediator.RouteNotification(mediator.GetDescriptor(request), request); await textDocumentSyncHandler.Received(0).Handle(Arg.Any <DidSaveTextDocumentParams>()); await textDocumentSyncHandler2.Received(1).Handle(Arg.Any <DidSaveTextDocumentParams>()); }
public async Task ShouldRouteToCorrect_Notification() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>()).Returns(Task.CompletedTask); var collection = new HandlerCollection { textDocumentSyncHandler }; var handlerMatcherCollection = new HandlerMatcherCollection { new TextDocumentMatcher(_testLoggerFactory.CreateLogger <TextDocumentMatcher>(), collection.TextDocumentSyncHandlers) }; var mediator = new LspRequestRouter(collection, _testLoggerFactory, handlerMatcherCollection, new Serializer()); var @params = new DidSaveTextDocumentParams() { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Notification(DocumentNames.DidSave, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings))); await mediator.RouteNotification(mediator.GetDescriptor(request), request); await textDocumentSyncHandler.Received(1).Handle(Arg.Any <DidSaveTextDocumentParams>()); }