|  | 
| 16 | 16 | using OmniSharp.Extensions.LanguageServer.Protocol.Serialization; | 
| 17 | 17 | using OmniSharp.Extensions.LanguageServer.Server; | 
| 18 | 18 | using OmniSharp.Extensions.LanguageServer.Server.Abstractions; | 
|  | 19 | +using OmniSharp.Extensions.LanguageServer.Server.Handlers; | 
| 19 | 20 | using Xunit; | 
| 20 | 21 | using Xunit.Abstractions; | 
| 21 | 22 | using Xunit.Sdk; | 
| @@ -163,5 +164,53 @@ public async Task ShouldRouteTo_CorrectRequestWhenGivenNullParams() | 
| 163 | 164 | 
 | 
| 164 | 165 |             await handler.Received(1).Handle(Arg.Any<object>(), Arg.Any<CancellationToken>()); | 
| 165 | 166 |         } | 
|  | 167 | + | 
|  | 168 | +        [Fact] | 
|  | 169 | +        public async Task ShouldHandle_Request_WithNullParameters() | 
|  | 170 | +        { | 
|  | 171 | +            bool wasShutDown = false; | 
|  | 172 | + | 
|  | 173 | +            ShutdownHandler shutdownHandler = new ShutdownHandler(); | 
|  | 174 | +            shutdownHandler.Shutdown += shutdownRequested => | 
|  | 175 | +            { | 
|  | 176 | +                wasShutDown = true; | 
|  | 177 | +            }; | 
|  | 178 | + | 
|  | 179 | +            var collection = new HandlerCollection { shutdownHandler }; | 
|  | 180 | +            var mediator = new LspRequestRouter(collection, _testLoggerFactory, _handlerMatcherCollection, new Serializer()); | 
|  | 181 | + | 
|  | 182 | +            JToken @params = JValue.CreateNull(); // If the "params" property present but null, this will be JTokenType.Null. | 
|  | 183 | + | 
|  | 184 | +            var id = Guid.NewGuid().ToString(); | 
|  | 185 | +            var request = new Request(id, GeneralNames.Shutdown, @params); | 
|  | 186 | + | 
|  | 187 | +            await mediator.RouteRequest(mediator.GetDescriptor(request), request); | 
|  | 188 | + | 
|  | 189 | +            Assert.True(wasShutDown, "WasShutDown"); | 
|  | 190 | +        } | 
|  | 191 | + | 
|  | 192 | +        [Fact] | 
|  | 193 | +        public async Task ShouldHandle_Request_WithMissingParameters() | 
|  | 194 | +        { | 
|  | 195 | +            bool wasShutDown = false; | 
|  | 196 | + | 
|  | 197 | +            ShutdownHandler shutdownHandler = new ShutdownHandler(); | 
|  | 198 | +            shutdownHandler.Shutdown += shutdownRequested => | 
|  | 199 | +            { | 
|  | 200 | +                wasShutDown = true; | 
|  | 201 | +            }; | 
|  | 202 | + | 
|  | 203 | +            var collection = new HandlerCollection { shutdownHandler }; | 
|  | 204 | +            var mediator = new LspRequestRouter(collection, _testLoggerFactory, _handlerMatcherCollection, new Serializer()); | 
|  | 205 | + | 
|  | 206 | +            JToken @params = null; // If the "params" property was missing entirely, this will be null. | 
|  | 207 | + | 
|  | 208 | +            var id = Guid.NewGuid().ToString(); | 
|  | 209 | +            var request = new Request(id, GeneralNames.Shutdown, @params); | 
|  | 210 | + | 
|  | 211 | +            await mediator.RouteRequest(mediator.GetDescriptor(request), request); | 
|  | 212 | + | 
|  | 213 | +            Assert.True(wasShutDown, "WasShutDown"); | 
|  | 214 | +        } | 
| 166 | 215 |     } | 
| 167 | 216 | } | 
0 commit comments