Skip to content

Commit 39167aa

Browse files
committed
Additional test for #60
(distinction between null and missing "params" property on request message)
1 parent 04188ee commit 39167aa

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/Lsp.Tests/LspRequestRouterTests.cs

+26-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,34 @@ public async Task ShouldHandle_Request_WithNullParameters()
160160
var collection = new HandlerCollection { shutdownHandler };
161161
var mediator = new LspRequestRouter(collection, _testLoggerFactory, _handlerMatcherCollection, new Serializer());
162162

163-
object @params = null;
163+
JToken @params = JValue.CreateNull(); // If the "params" property present but null, this will be JTokenType.Null.
164164

165165
var id = Guid.NewGuid().ToString();
166-
var request = new Request(id, GeneralNames.Shutdown, JValue.CreateNull());
166+
var request = new Request(id, GeneralNames.Shutdown, @params);
167+
168+
await mediator.RouteRequest(mediator.GetDescriptor(request), request);
169+
170+
Assert.True(wasShutDown, "WasShutDown");
171+
}
172+
173+
[Fact]
174+
public async Task ShouldHandle_Request_WithMissingParameters()
175+
{
176+
bool wasShutDown = false;
177+
178+
ShutdownHandler shutdownHandler = new ShutdownHandler();
179+
shutdownHandler.Shutdown += shutdownRequested =>
180+
{
181+
wasShutDown = true;
182+
};
183+
184+
var collection = new HandlerCollection { shutdownHandler };
185+
var mediator = new LspRequestRouter(collection, _testLoggerFactory, _handlerMatcherCollection, new Serializer());
186+
187+
JToken @params = null; // If the "params" property was missing entirely, this will be null.
188+
189+
var id = Guid.NewGuid().ToString();
190+
var request = new Request(id, GeneralNames.Shutdown, @params);
167191

168192
await mediator.RouteRequest(mediator.GetDescriptor(request), request);
169193

0 commit comments

Comments
 (0)