mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
* added wip rename query * added first rename test * added missing query handling and two new tests * removed ServiceDispose * added change to owneruri. * made fields private, used accessor methods * added readonly flag back * added didSave to sqltools.servicelayer * fix for docsavecallbacks * removed tryremove * test disconnect in queryExecutionService * removed debug message working query. * added comment to handlerenamerequest * added uri replacement function * removed duplicate removemap function * added minor fixes * changed connectionOwnerUri to getter setter * removed handledidsave and added setters * removed additional save parts * fixed space issues * more fixes for spaces * restored spaces * fixed workspaceservice * Update TextDocument.cs * changed renameRequest into notification WIP * restored textdocument * restored textdocument.cs * added rightwards arrow * renamed rename to ChangeConnectionUri * added more renames * rename changeconnectionuri to changeuri * renamed file names * Revert "renamed file names" This reverts commit 55228e65025b5179b15ae9a0adc095d95538723d. * Revert "rename changeconnectionuri to changeuri" This reverts commit 23f3813f609e3947f103e057f7c0919184075bdc. * removed logging message and other small changes * renamed class and method
74 lines
3.3 KiB
C#
74 lines
3.3 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
|
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|
{
|
|
public class ConnectionUriChangedTests
|
|
{
|
|
[Test]
|
|
public async Task ChangeUriForExecutedQuery()
|
|
{
|
|
// If:
|
|
// ... I request a query (doesn't matter what kind)
|
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
|
var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
|
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
|
await queryService.WorkTask;
|
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
|
|
|
const string newOwnerUri = "newTestFile";
|
|
Query query;
|
|
queryService.ActiveQueries.TryGetValue(Constants.OwnerUri, out query);
|
|
|
|
// ... And then I change the uri for the query
|
|
var changeUriParams = new ConnectionUriChangedParams {
|
|
OriginalOwnerUri = Constants.OwnerUri,
|
|
NewOwnerUri = newOwnerUri
|
|
};
|
|
|
|
|
|
await queryService.HandleConnectionUriChangedNotification(changeUriParams, new TestEventContext());
|
|
|
|
// Then:
|
|
// ... And the active queries should have the new query.
|
|
Assert.That(queryService.ActiveQueries.TryGetValue(newOwnerUri, out query), "Query with newOwnerUri not found.");
|
|
Assert.That(Equals(query.ConnectionOwnerURI, newOwnerUri), "OwnerUri was not changed!");
|
|
}
|
|
|
|
[Test]
|
|
public void ChangeUriForMissingQuery()
|
|
{
|
|
// If:
|
|
// ... I attempt to change the uri a query that doesn't exist
|
|
var workspaceService = new Mock<WorkspaceService<SqlToolsSettings>>();
|
|
var queryService = Common.GetPrimedExecutionService(null, false, false, false, workspaceService.Object);
|
|
const string newOwnerUri = "newTestFile";
|
|
var changeUriParams = new ConnectionUriChangedParams {
|
|
OriginalOwnerUri = Constants.OwnerUri,
|
|
NewOwnerUri = newOwnerUri
|
|
};
|
|
|
|
Assert.ThrowsAsync<Exception>(async () => await queryService.HandleConnectionUriChangedNotification(changeUriParams, new TestEventContext()));
|
|
|
|
Query query;
|
|
Assert.False(queryService.ActiveQueries.TryGetValue(Constants.OwnerUri, out query), "Query was removed from Active Queries");
|
|
}
|
|
}
|
|
}
|