Revert "Remove references to query model service in query code (#6513)" (#6591)

This reverts commit 674351dc75.
This commit is contained in:
Anthony Dresser
2019-08-05 11:42:54 -07:00
committed by GitHub
parent 65324f8bb3
commit 66adfb6524
12 changed files with 201 additions and 113 deletions

View File

@@ -21,6 +21,7 @@ import {
} from 'sql/workbench/parts/query/browser/queryActions';
import { QueryInput } from 'sql/workbench/parts/query/common/queryInput';
import { QueryEditor } from 'sql/workbench/parts/query/browser/queryEditor';
import { QueryModelService } from 'sql/platform/query/common/queryModelService';
import { ConnectionManagementService } from 'sql/platform/connection/common/connectionManagementService';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
@@ -30,11 +31,6 @@ import { TestStorageService, TestFileService } from 'vs/workbench/test/workbench
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { TestEditorInput } from 'vs/workbench/services/editor/test/browser/editorGroupsService.test';
import { URI } from 'vs/base/common/uri';
import { Schemas } from 'vs/base/common/network';
let none: void;
@@ -48,9 +44,7 @@ suite('SQL QueryAction Tests', () => {
setup(() => {
// Setup a reusable mock QueryInput
const instantiationService = new TestInstantiationService();
const fileInput = new TestEditorInput(URI.from({ scheme: Schemas.untitled }));
testQueryInput = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Strict, undefined, fileInput, undefined, undefined, undefined, instantiationService);
testQueryInput = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Strict);
testQueryInput.setup(x => x.uri).returns(() => testUri);
testQueryInput.setup(x => x.runQuery(undefined)).callback(() => { calledRunQueryOnInput = true; });
@@ -75,7 +69,7 @@ suite('SQL QueryAction Tests', () => {
test('setClass sets child CSS class correctly', (done) => {
// If I create a RunQueryAction
let queryAction: QueryTaskbarAction = new RunQueryAction(undefined, undefined);
let queryAction: QueryTaskbarAction = new RunQueryAction(undefined, undefined, undefined, undefined);
// "class should automatically get set to include the base class and the RunQueryAction class
let className = RunQueryAction.EnabledClass;
@@ -99,7 +93,7 @@ suite('SQL QueryAction Tests', () => {
editor.setup(x => x.input).returns(() => testQueryInput.object);
// If I create a QueryTaskbarAction and I pass a non-connected editor to _getConnectedQueryEditorUri
let queryAction: QueryTaskbarAction = new RunQueryAction(undefined, connectionManagementService.object);
let queryAction: QueryTaskbarAction = new RunQueryAction(undefined, undefined, connectionManagementService.object, undefined);
let connected: boolean = queryAction.isConnected(editor.object);
// I should get an unconnected state
@@ -135,8 +129,14 @@ suite('SQL QueryAction Tests', () => {
connectionManagementService.callBase = true;
connectionManagementService.setup(x => x.isConnected(TypeMoq.It.isAnyString())).returns(() => isConnected);
// ... Mock QueryModelService
let queryModelService = TypeMoq.Mock.ofType(QueryModelService, TypeMoq.MockBehavior.Loose);
queryModelService.setup(x => x.runQuery(TypeMoq.It.isAny(), undefined, TypeMoq.It.isAny(), TypeMoq.It.isAny())).callback(() => {
calledRunQuery = true;
});
// If I call run on RunQueryAction when I am not connected
let queryAction: RunQueryAction = new RunQueryAction(editor.object, connectionManagementService.object);
let queryAction: RunQueryAction = new RunQueryAction(editor.object, queryModelService.object, connectionManagementService.object, undefined);
isConnected = false;
calledRunQueryOnInput = false;
queryAction.run();
@@ -170,9 +170,8 @@ suite('SQL QueryAction Tests', () => {
let countCalledRunQuery: number = 0;
// ... Mock "isSelectionEmpty" in QueryEditor
const instantiationService = new TestInstantiationService();
const fileInput = new TestEditorInput(URI.from({ scheme: Schemas.untitled }));
let queryInput = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Strict, undefined, fileInput, undefined, undefined, undefined, instantiationService);
let queryInput: TypeMoq.Mock<QueryInput> = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Strict);
queryInput = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Strict);
queryInput.setup(x => x.uri).returns(() => testUri);
queryInput.setup(x => x.runQuery(undefined)).callback(() => {
countCalledRunQuery++;
@@ -192,8 +191,11 @@ suite('SQL QueryAction Tests', () => {
connectionManagementService.callBase = true;
connectionManagementService.setup(x => x.isConnected(TypeMoq.It.isAnyString())).returns(() => true);
// ... Mock QueryModelService
let queryModelService = TypeMoq.Mock.ofType(QueryModelService, TypeMoq.MockBehavior.Loose);
// If I call run on RunQueryAction when I have a non empty selection
let queryAction: RunQueryAction = new RunQueryAction(queryEditor.object, connectionManagementService.object);
let queryAction: RunQueryAction = new RunQueryAction(queryEditor.object, queryModelService.object, connectionManagementService.object, undefined);
isSelectionEmpty = false;
queryAction.run();
@@ -232,9 +234,7 @@ suite('SQL QueryAction Tests', () => {
.returns(() => Promise.resolve(none));
// ... Mock "getSelection" in QueryEditor
const instantiationService = new TestInstantiationService();
const fileInput = new TestEditorInput(URI.from({ scheme: Schemas.untitled }));
let queryInput = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Loose, undefined, fileInput, undefined, undefined, undefined, instantiationService);
let queryInput = TypeMoq.Mock.ofType(QueryInput, TypeMoq.MockBehavior.Loose);
queryInput.setup(x => x.uri).returns(() => testUri);
queryInput.setup(x => x.runQuery(TypeMoq.It.isAny())).callback((selection: ISelectionData) => {
runQuerySelection = selection;
@@ -266,7 +266,7 @@ suite('SQL QueryAction Tests', () => {
/// End Setup Test ///
////// If I call run on RunQueryAction while disconnected and with an undefined selection
let queryAction: RunQueryAction = new RunQueryAction(queryEditor.object, connectionManagementService.object);
let queryAction: RunQueryAction = new RunQueryAction(queryEditor.object, undefined, connectionManagementService.object, undefined);
isConnected = false;
selectionToReturnInGetSelection = undefined;
queryAction.run();
@@ -317,6 +317,38 @@ suite('SQL QueryAction Tests', () => {
assert.equal(runQuerySelection.endColumn, selectionToReturnInGetSelection.endColumn, 'endColumn should match');
});
test('CancelQueryAction calls cancelQuery() only if URI is connected', (done) => {
// ... Create assert variables
let isConnected: boolean = undefined;
let calledCancelQuery: boolean = false;
// ... Mock "isConnected" in ConnectionManagementService
let connectionManagementService = TypeMoq.Mock.ofType(ConnectionManagementService, TypeMoq.MockBehavior.Loose, {});
connectionManagementService.setup(x => x.isConnected(TypeMoq.It.isAnyString())).returns(() => isConnected);
// ... Mock QueryModelService
let queryModelService = TypeMoq.Mock.ofType(QueryModelService, TypeMoq.MockBehavior.Loose);
queryModelService.setup(x => x.cancelQuery(TypeMoq.It.isAny())).callback(() => {
calledCancelQuery = true;
});
// If I call run on CancelQueryAction when I am not connected
let queryAction: CancelQueryAction = new CancelQueryAction(editor.object, queryModelService.object, connectionManagementService.object);
isConnected = false;
queryAction.run();
// cancelQuery should not be run
assert.equal(calledCancelQuery, false, 'run should not call cancelQuery');
// If I call run on CancelQueryAction when I am connected
isConnected = true;
queryAction.run();
// cancelQuery should be run
assert.equal(calledCancelQuery, true, 'run should call cancelQuery');
done();
});
// We want to call disconnectEditor regardless of connection to be able to cancel in-progress connections
test('DisconnectDatabaseAction calls disconnectEditor regardless of URI being connected', (done) => {
// ... Create assert variables

View File

@@ -10,6 +10,7 @@ import { Memento } from 'vs/workbench/common/memento';
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { QueryResultsInput } from 'sql/workbench/parts/query/common/queryResultsInput';
import { QueryModelService } from 'sql/platform/query/common/queryModelService';
import { QueryInput } from 'sql/workbench/parts/query/common/queryInput';
import { INewConnectionParams, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
import { ConnectionManagementService } from 'sql/platform/connection/common/connectionManagementService';
@@ -22,8 +23,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { TestStorageService } from 'vs/workbench/test/workbenchTestServices';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import QueryRunner from 'sql/platform/query/common/queryRunner';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
suite('SQL QueryEditor Tests', () => {
let instantiationService: TypeMoq.Mock<InstantiationService>;
@@ -55,7 +54,7 @@ suite('SQL QueryEditor Tests', () => {
return new Promise((resolve) => resolve(mockEditor));
});
instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((input) => {
return new Promise((resolve) => resolve(new RunQueryAction(undefined, undefined)));
return new Promise((resolve) => resolve(new RunQueryAction(undefined, undefined, undefined, undefined)));
});
// Setup hook to capture calls to create the listDatabase action
instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((classDef, editor, action) => {
@@ -65,7 +64,7 @@ suite('SQL QueryEditor Tests', () => {
}
}
// Default
return new RunQueryAction(undefined, undefined);
return new RunQueryAction(undefined, undefined, undefined, undefined);
});
// Mock EditorDescriptorService to give us a mock editor description
@@ -248,6 +247,7 @@ suite('SQL QueryEditor Tests', () => {
suite('Action Tests', () => {
let queryActionInstantiationService: TypeMoq.Mock<InstantiationService>;
let queryConnectionService: TypeMoq.Mock<ConnectionManagementService>;
let queryModelService: TypeMoq.Mock<QueryModelService>;
let queryInput: QueryInput;
setup(() => {
@@ -262,7 +262,6 @@ suite('SQL QueryEditor Tests', () => {
// Mock InstantiationService to give us the actions
queryActionInstantiationService = TypeMoq.Mock.ofType(InstantiationService, TypeMoq.MockBehavior.Loose);
instantiationService.setup(x => x.createInstance(TypeMoq.It.isValue(QueryRunner), TypeMoq.It.isAnyString())).returns(() => new QueryRunner('', undefined, undefined, undefined, undefined, undefined));
queryActionInstantiationService.setup(x => x.createInstance(TypeMoq.It.isAny())).returns((input) => {
return new Promise((resolve) => resolve(mockEditor));
@@ -270,7 +269,7 @@ suite('SQL QueryEditor Tests', () => {
queryActionInstantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((input) => {
// Default
return new RunQueryAction(undefined, undefined);
return new RunQueryAction(undefined, undefined, undefined, undefined);
});
// Setup hook to capture calls to create the listDatabase action
@@ -281,24 +280,27 @@ suite('SQL QueryEditor Tests', () => {
return item;
}
// Default
return new RunQueryAction(undefined, undefined);
return new RunQueryAction(undefined, undefined, undefined, undefined);
});
const mockInstantiationService = new TestInstantiationService();
let fileInput = new UntitledEditorInput(URI.parse('file://testUri'), false, '', '', '', instantiationService.object, undefined, undefined);
queryModelService = TypeMoq.Mock.ofType(QueryModelService, TypeMoq.MockBehavior.Loose, undefined, undefined);
queryModelService.callBase = true;
queryModelService.setup(x => x.disposeQuery(TypeMoq.It.isAny())).returns(() => void 0);
queryInput = new QueryInput(
'',
fileInput,
undefined,
connectionManagementService.object,
undefined,
mockInstantiationService
connectionManagementService.object,
queryModelService.object,
undefined
);
});
test('Taskbar buttons are set correctly upon standard load', () => {
queryConnectionService.setup(x => x.isConnected(TypeMoq.It.isAny())).returns(() => false);
queryModelService.setup(x => x.isRunningQuery(TypeMoq.It.isAny())).returns(() => false);
// If I use the created QueryEditor with no changes since creation
// Buttons should be set as if disconnected
assert.equal(queryInput.state.connected, false, 'query state should be not connected');
@@ -309,14 +311,16 @@ suite('SQL QueryEditor Tests', () => {
test('Taskbar buttons are set correctly upon connect', () => {
let params: INewConnectionParams = { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none };
queryInput.onConnectSuccess(params);
queryModelService.setup(x => x.isRunningQuery(TypeMoq.It.isAny())).returns(() => false);
assert.equal(queryInput.state.connected, true, 'query state should be not connected');
assert.equal(queryInput.state.executing, false, 'query state should be not executing');
assert.equal(queryInput.state.connecting, false, 'query state should be not connecting');
});
test('Test that we attempt to dispose query when the queryInput is disposed', () => {
let queryResultsInput = new QueryResultsInput('testUri', undefined);
let queryResultsInput = new QueryResultsInput('testUri');
queryInput['_results'] = queryResultsInput;
queryInput.close();
queryModelService.verify(x => x.disposeQuery(TypeMoq.It.isAnyString()), TypeMoq.Times.once());
});
});
});