mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Prevent ArgumentNullException in refresh request (#963)
This commit is contained in:
@@ -243,7 +243,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
|
||||
string uri = refreshParams.SessionId;
|
||||
ObjectExplorerSession session = null;
|
||||
if (!sessionMap.TryGetValue(uri, out session))
|
||||
if (string.IsNullOrEmpty(uri) || !sessionMap.TryGetValue(uri, out session))
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, $"Cannot expand object explorer node. Couldn't find session for uri. {uri} ");
|
||||
await serviceHost.SendEvent(ExpandCompleteNotification.Type, new ExpandResponse
|
||||
|
||||
@@ -207,6 +207,26 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
|
||||
}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RefreshNodeGivenNullSessionShouldReturnEmptyList()
|
||||
{
|
||||
RefreshParams expandParams = new RefreshParams()
|
||||
{
|
||||
SessionId = null,
|
||||
NodePath = "Any path"
|
||||
};
|
||||
|
||||
// when expanding
|
||||
// then expect the nodes are server children
|
||||
await RunAndVerify<bool, ExpandResponse>(
|
||||
test: (requestContext) => CallServiceRefresh(expandParams, requestContext),
|
||||
verify: (actual =>
|
||||
{
|
||||
Assert.Equal(actual.SessionId, expandParams.SessionId);
|
||||
Assert.Null(actual.Nodes);
|
||||
}));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CloseSessionGivenInvalidSessionShouldReturnEmptyList()
|
||||
{
|
||||
@@ -385,7 +405,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
|
||||
serviceHostMock.AddEventHandling(CreateSessionCompleteNotification.Type, (et, p) => result = p);
|
||||
|
||||
await service.HandleCreateSessionRequest(connectionDetails, context);
|
||||
Task task = service.CreateSessionTask;
|
||||
Task task = service.CreateSessionTask;
|
||||
if (task != null)
|
||||
{
|
||||
await task;
|
||||
|
||||
Reference in New Issue
Block a user