Prevent ArgumentNullException in refresh request (#963)

This commit is contained in:
Soheil Alizadeh
2020-06-15 10:54:31 +04:30
committed by GitHub
parent 28e479f239
commit 31659e1126
2 changed files with 29 additions and 9 deletions

View File

@@ -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

View File

@@ -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;