mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
Inital platform relayering (#6385)
* moving test files and inital refactoring * relayer extension host code * fix imports * make insights work * relayer dashboard * relayer notebooks * moveing more code around * formatting * accept angular as browser * fix serializer * add missing files * remove declarations from extensions * fix build errors * more relayering * change urls to relative to help code relayering * remove layering to prep for merge * fix hygiene errors * fix hygiene errors * fix tests
This commit is contained in:
@@ -12,7 +12,7 @@ import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/co
|
||||
import { IConnectionProfile, IConnectionProfileStore } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { deepClone, deepFreeze } from 'vs/base/common/objects';
|
||||
@@ -119,7 +119,7 @@ suite('ConnectionConfig', () => {
|
||||
]);
|
||||
|
||||
setup(() => {
|
||||
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesTestService);
|
||||
capabilitiesService = TypeMoq.Mock.ofType(TestCapabilitiesService);
|
||||
capabilities = [];
|
||||
let connectionProvider: azdata.ConnectionProviderOptions = {
|
||||
options: [
|
||||
|
||||
@@ -0,0 +1,994 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { TestConnectionDialogService } from 'sql/workbench/services/connection/test/common/testConnectionDialogService';
|
||||
import { ConnectionManagementService } from 'sql/platform/connection/common/connectionManagementService';
|
||||
import { ConnectionStatusManager } from 'sql/platform/connection/common/connectionStatusManager';
|
||||
import { ConnectionStore } from 'sql/platform/connection/common/connectionStore';
|
||||
import {
|
||||
INewConnectionParams, ConnectionType,
|
||||
IConnectionCompletionOptions, IConnectionResult,
|
||||
RunQueryOnConnectionMode
|
||||
} from 'sql/platform/connection/common/connectionManagement';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import * as Utils from 'sql/platform/connection/common/utils';
|
||||
import { IHandleFirewallRuleResult } from 'sql/workbench/services/resourceProvider/common/resourceProviderService';
|
||||
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { TestConnectionProvider } from 'sql/platform/connection/test/common/testConnectionProvider';
|
||||
import { TestResourceProvider } from 'sql/workbench/services/resourceProvider/test/common/testResourceProviderService';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { TestAccountManagementService } from 'sql/platform/accounts/test/common/testAccountManagementService';
|
||||
import { TestStorageService, TestEnvironmentService, TestEditorService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
|
||||
suite('SQL ConnectionManagementService tests', () => {
|
||||
|
||||
let capabilitiesService: TestCapabilitiesService;
|
||||
let connectionDialogService: TypeMoq.Mock<TestConnectionDialogService>;
|
||||
let connectionStore: TypeMoq.Mock<ConnectionStore>;
|
||||
let workbenchEditorService: TypeMoq.Mock<TestEditorService>;
|
||||
let connectionStatusManager: ConnectionStatusManager;
|
||||
let mssqlConnectionProvider: TypeMoq.Mock<TestConnectionProvider>;
|
||||
let workspaceConfigurationServiceMock: TypeMoq.Mock<TestConfigurationService>;
|
||||
let resourceProviderStubMock: TypeMoq.Mock<TestResourceProvider>;
|
||||
let accountManagementService: TypeMoq.Mock<TestAccountManagementService>;
|
||||
|
||||
let none: void;
|
||||
|
||||
let connectionProfile: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: 'integrated',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => { return 'connectionId'; },
|
||||
matches: undefined,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
let connectionProfileWithEmptySavedPassword: IConnectionProfile =
|
||||
Object.assign({}, connectionProfile, { password: '', serverName: connectionProfile.serverName + 1 });
|
||||
let connectionProfileWithEmptyUnsavedPassword: IConnectionProfile =
|
||||
Object.assign({}, connectionProfile, { password: '', serverName: connectionProfile.serverName + 2, savePassword: false });
|
||||
|
||||
let connectionManagementService: ConnectionManagementService;
|
||||
let configResult: { [key: string]: any } = {};
|
||||
configResult['defaultEngine'] = 'MSSQL';
|
||||
let handleFirewallRuleResult: IHandleFirewallRuleResult;
|
||||
let resolveHandleFirewallRuleDialog: boolean;
|
||||
let isFirewallRuleAdded: boolean;
|
||||
|
||||
setup(() => {
|
||||
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
connectionDialogService = TypeMoq.Mock.ofType(TestConnectionDialogService);
|
||||
connectionStore = TypeMoq.Mock.ofType(ConnectionStore, TypeMoq.MockBehavior.Loose, new TestStorageService());
|
||||
workbenchEditorService = TypeMoq.Mock.ofType(TestEditorService);
|
||||
connectionStatusManager = new ConnectionStatusManager(capabilitiesService, new NullLogService(), TestEnvironmentService, new TestNotificationService());
|
||||
mssqlConnectionProvider = TypeMoq.Mock.ofType(TestConnectionProvider);
|
||||
let resourceProviderStub = new TestResourceProvider();
|
||||
resourceProviderStubMock = TypeMoq.Mock.ofInstance(resourceProviderStub);
|
||||
accountManagementService = TypeMoq.Mock.ofType(TestAccountManagementService);
|
||||
let root = new ConnectionProfileGroup(ConnectionProfileGroup.RootGroupName, undefined, ConnectionProfileGroup.RootGroupName, undefined, undefined);
|
||||
root.connections = [ConnectionProfile.fromIConnectionProfile(capabilitiesService, connectionProfile)];
|
||||
|
||||
connectionDialogService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), undefined, undefined)).returns(() => Promise.resolve(none));
|
||||
connectionDialogService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), undefined, TypeMoq.It.isAny())).returns(() => Promise.resolve(none));
|
||||
connectionDialogService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), undefined, undefined, TypeMoq.It.isAny())).returns(() => Promise.resolve(none));
|
||||
connectionDialogService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), undefined, undefined, undefined)).returns(() => Promise.resolve(none));
|
||||
connectionDialogService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), undefined)).returns(() => Promise.resolve(none));
|
||||
connectionDialogService.setup(x => x.showDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(none));
|
||||
|
||||
connectionStore.setup(x => x.addRecentConnection(TypeMoq.It.isAny())).returns(() => Promise.resolve());
|
||||
connectionStore.setup(x => x.saveProfile(TypeMoq.It.isAny())).returns(() => Promise.resolve(connectionProfile));
|
||||
workbenchEditorService.setup(x => x.openEditor(undefined, TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
|
||||
connectionStore.setup(x => x.addSavedPassword(TypeMoq.It.is<IConnectionProfile>(
|
||||
c => c.serverName === connectionProfile.serverName))).returns(() => Promise.resolve({ profile: connectionProfile, savedCred: true }));
|
||||
connectionStore.setup(x => x.addSavedPassword(TypeMoq.It.is<IConnectionProfile>(
|
||||
c => c.serverName === connectionProfileWithEmptySavedPassword.serverName))).returns(
|
||||
() => Promise.resolve({ profile: connectionProfileWithEmptySavedPassword, savedCred: true }));
|
||||
connectionStore.setup(x => x.addSavedPassword(TypeMoq.It.is<IConnectionProfile>(
|
||||
c => c.serverName === connectionProfileWithEmptyUnsavedPassword.serverName))).returns(
|
||||
() => Promise.resolve({ profile: connectionProfileWithEmptyUnsavedPassword, savedCred: false }));
|
||||
connectionStore.setup(x => x.isPasswordRequired(TypeMoq.It.isAny())).returns(() => true);
|
||||
connectionStore.setup(x => x.getConnectionProfileGroups(false, undefined)).returns(() => [root]);
|
||||
connectionStore.setup(x => x.savePassword(TypeMoq.It.isAny())).returns(() => Promise.resolve(true));
|
||||
|
||||
mssqlConnectionProvider.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => undefined);
|
||||
|
||||
// Setup resource provider
|
||||
handleFirewallRuleResult = {
|
||||
canHandleFirewallRule: false,
|
||||
ipAddress: '123.123.123.123',
|
||||
resourceProviderId: 'Azure'
|
||||
};
|
||||
resourceProviderStubMock.setup(x => x.handleFirewallRule(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
|
||||
.returns(() => Promise.resolve(handleFirewallRuleResult));
|
||||
|
||||
resolveHandleFirewallRuleDialog = true;
|
||||
isFirewallRuleAdded = true;
|
||||
resourceProviderStubMock.setup(x => x.showFirewallRuleDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
|
||||
.returns(() => {
|
||||
if (resolveHandleFirewallRuleDialog) {
|
||||
return isFirewallRuleAdded ? Promise.resolve(true) : Promise.resolve(false);
|
||||
} else {
|
||||
return Promise.reject(null).then();
|
||||
}
|
||||
});
|
||||
|
||||
// Setup configuration to return a config that can be modified later.
|
||||
workspaceConfigurationServiceMock = TypeMoq.Mock.ofType(TestConfigurationService);
|
||||
workspaceConfigurationServiceMock.setup(x => x.getValue(Constants.sqlConfigSectionName))
|
||||
.returns(() => configResult);
|
||||
|
||||
connectionManagementService = createConnectionManagementService();
|
||||
|
||||
connectionManagementService.registerProvider('MSSQL', mssqlConnectionProvider.object);
|
||||
});
|
||||
|
||||
function createConnectionManagementService(): ConnectionManagementService {
|
||||
let connectionManagementService = new ConnectionManagementService(
|
||||
connectionStore.object,
|
||||
undefined,
|
||||
connectionDialogService.object,
|
||||
undefined, // IServerGroupController
|
||||
undefined, // IInstantiationService
|
||||
workbenchEditorService.object,
|
||||
undefined, // ITelemetryService
|
||||
workspaceConfigurationServiceMock.object,
|
||||
capabilitiesService,
|
||||
undefined, // IQuickInputService
|
||||
new TestNotificationService(),
|
||||
resourceProviderStubMock.object,
|
||||
undefined, // IAngularEventingService
|
||||
accountManagementService.object,
|
||||
new NullLogService(), // ILogService
|
||||
undefined, // IStorageService
|
||||
TestEnvironmentService
|
||||
);
|
||||
return connectionManagementService;
|
||||
}
|
||||
|
||||
function verifyShowConnectionDialog(connectionProfile: IConnectionProfile, connectionType: ConnectionType, uri: string, options: boolean, connectionResult?: IConnectionResult, didShow: boolean = true): void {
|
||||
if (connectionProfile) {
|
||||
connectionDialogService.verify(x => x.showDialog(
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.is<INewConnectionParams>(p => p.connectionType === connectionType && (uri === undefined || p.input.uri === uri)),
|
||||
TypeMoq.It.is<IConnectionProfile>(c => c !== undefined && c.serverName === connectionProfile.serverName),
|
||||
connectionResult ? TypeMoq.It.is<IConnectionResult>(r => r.errorMessage === connectionResult.errorMessage && r.callStack === connectionResult.callStack) : undefined,
|
||||
options ? TypeMoq.It.isAny() : undefined),
|
||||
didShow ? TypeMoq.Times.once() : TypeMoq.Times.never());
|
||||
|
||||
} else {
|
||||
connectionDialogService.verify(x => x.showDialog(
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.is<INewConnectionParams>(p => p.connectionType === connectionType && ((uri === undefined && p.input === undefined) || p.input.uri === uri)),
|
||||
undefined,
|
||||
connectionResult ? TypeMoq.It.is<IConnectionResult>(r => r.errorMessage === connectionResult.errorMessage && r.callStack === connectionResult.callStack) : undefined,
|
||||
options ? TypeMoq.It.isAny() : undefined),
|
||||
didShow ? TypeMoq.Times.once() : TypeMoq.Times.never());
|
||||
}
|
||||
}
|
||||
|
||||
function verifyShowFirewallRuleDialog(connectionProfile: IConnectionProfile, didShow: boolean = true): void {
|
||||
resourceProviderStubMock.verify(x => x.showFirewallRuleDialog(
|
||||
TypeMoq.It.is<IConnectionProfile>(c => c.serverName === connectionProfile.serverName),
|
||||
TypeMoq.It.isAny(),
|
||||
TypeMoq.It.isAny()),
|
||||
didShow ? TypeMoq.Times.once() : TypeMoq.Times.never());
|
||||
}
|
||||
|
||||
function verifyOptions(options?: IConnectionCompletionOptions, fromDialog?: boolean): void {
|
||||
|
||||
if (options) {
|
||||
if (options.saveTheConnection) {
|
||||
connectionStore.verify(x => x.saveProfile(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
}
|
||||
if (options.showDashboard) {
|
||||
workbenchEditorService.verify(x => x.openEditor(undefined, TypeMoq.It.isAny(), TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
}
|
||||
}
|
||||
|
||||
if (fromDialog !== undefined && !fromDialog) {
|
||||
connectionStore.verify(x => x.addSavedPassword(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function connect(uri: string, options?: IConnectionCompletionOptions, fromDialog?: boolean, connection?: IConnectionProfile, error?: string, errorCode?: number, errorCallStack?: string): Promise<IConnectionResult> {
|
||||
let connectionToUse = connection ? connection : connectionProfile;
|
||||
return new Promise<IConnectionResult>((resolve, reject) => {
|
||||
let id = connectionToUse.getOptionsKey();
|
||||
let defaultUri = 'connection://' + (id ? id : connectionToUse.serverName + ':' + connectionToUse.databaseName);
|
||||
connectionManagementService.onConnectionRequestSent(() => {
|
||||
let info: azdata.ConnectionInfoSummary = {
|
||||
connectionId: error ? undefined : 'id',
|
||||
connectionSummary: {
|
||||
databaseName: connectionToUse.databaseName,
|
||||
serverName: connectionToUse.serverName,
|
||||
userName: connectionToUse.userName
|
||||
},
|
||||
errorMessage: error,
|
||||
errorNumber: errorCode,
|
||||
messages: errorCallStack,
|
||||
ownerUri: uri ? uri : defaultUri,
|
||||
serverInfo: undefined
|
||||
};
|
||||
connectionManagementService.onConnectionComplete(0, info);
|
||||
});
|
||||
connectionManagementService.cancelConnectionForUri(uri).then(() => {
|
||||
if (fromDialog) {
|
||||
resolve(connectionManagementService.connectAndSaveProfile(connectionToUse, uri, options));
|
||||
} else {
|
||||
resolve(connectionManagementService.connect(connectionToUse, uri, options));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
test('showConnectionDialog should open the dialog with default type given no parameters', done => {
|
||||
connectionManagementService.showConnectionDialog().then(() => {
|
||||
verifyShowConnectionDialog(undefined, ConnectionType.default, undefined, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('showConnectionDialog should open the dialog with given type given valid input', done => {
|
||||
let params: INewConnectionParams = {
|
||||
connectionType: ConnectionType.editor,
|
||||
input: {
|
||||
onConnectReject: undefined,
|
||||
onConnectStart: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectSuccess: undefined,
|
||||
onConnectCanceled: undefined,
|
||||
uri: 'Editor Uri'
|
||||
},
|
||||
runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery
|
||||
};
|
||||
connectionManagementService.showConnectionDialog(params).then(() => {
|
||||
verifyShowConnectionDialog(undefined, params.connectionType, params.input.uri, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('showConnectionDialog should pass the model to the dialog if there is a model assigned to the uri', done => {
|
||||
let params: INewConnectionParams = {
|
||||
connectionType: ConnectionType.editor,
|
||||
input: {
|
||||
onConnectReject: undefined,
|
||||
onConnectStart: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectSuccess: undefined,
|
||||
onConnectCanceled: undefined,
|
||||
uri: 'Editor Uri'
|
||||
},
|
||||
runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery
|
||||
};
|
||||
|
||||
connect(params.input.uri).then(() => {
|
||||
let saveConnection = connectionManagementService.getConnectionProfile(params.input.uri);
|
||||
|
||||
assert.notEqual(saveConnection, undefined, `profile was not added to the connections`);
|
||||
assert.equal(saveConnection.serverName, connectionProfile.serverName, `Server names are different`);
|
||||
connectionManagementService.showConnectionDialog(params).then(() => {
|
||||
verifyShowConnectionDialog(connectionProfile, params.connectionType, params.input.uri, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
}, err => done(err));
|
||||
});
|
||||
|
||||
test('connect should save profile given options with saveProfile set to true', done => {
|
||||
let uri: string = 'Editor Uri';
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: true,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: false,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
connect(uri, options).then(() => {
|
||||
verifyOptions(options);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('getDefaultProviderId is MSSQL', done => {
|
||||
let defaultProvider = connectionManagementService.getDefaultProviderId();
|
||||
assert.equal(defaultProvider, 'MSSQL', `Default provider is not equal to MSSQL`);
|
||||
done();
|
||||
});
|
||||
|
||||
/* Andresse 10/5/17 commented this test out since it was only working before my changes by the chance of how Promises work
|
||||
If we want to continue to test this, the connection logic needs to be rewritten to actually wait for everything to be done before it resolves */
|
||||
// test('connect should show dashboard given options with showDashboard set to true', done => {
|
||||
// let uri: string = 'Editor Uri';
|
||||
// let options: IConnectionCompletionOptions = {
|
||||
// params: undefined,
|
||||
// saveTheConnection: false,
|
||||
// showDashboard: true,
|
||||
// showConnectionDialogOnError: false
|
||||
// };
|
||||
|
||||
// connect(uri, options).then(() => {
|
||||
// verifyOptions(options);
|
||||
// done();
|
||||
// }).catch(err => {
|
||||
// done(err);
|
||||
// });
|
||||
// });
|
||||
|
||||
test('connect should pass the params in options to onConnectSuccess callback', done => {
|
||||
let uri: string = 'Editor Uri';
|
||||
let paramsInOnConnectSuccess: INewConnectionParams;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: {
|
||||
connectionType: ConnectionType.editor,
|
||||
input: {
|
||||
onConnectSuccess: (params?: INewConnectionParams) => {
|
||||
paramsInOnConnectSuccess = params;
|
||||
},
|
||||
onConnectReject: undefined,
|
||||
onConnectStart: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectCanceled: undefined,
|
||||
uri: uri
|
||||
},
|
||||
querySelection: undefined,
|
||||
runQueryOnCompletion: RunQueryOnConnectionMode.none
|
||||
},
|
||||
saveTheConnection: true,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
connect(uri, options).then(() => {
|
||||
verifyOptions(options);
|
||||
assert.notEqual(paramsInOnConnectSuccess, undefined);
|
||||
assert.equal(paramsInOnConnectSuccess.connectionType, options.params.connectionType);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('connectAndSaveProfile should show not load the password', done => {
|
||||
let uri: string = 'Editor Uri';
|
||||
let options: IConnectionCompletionOptions = undefined;
|
||||
|
||||
connect(uri, options, true).then(() => {
|
||||
verifyOptions(options, true);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('connect with undefined uri and options should connect using the default uri', done => {
|
||||
let uri = undefined;
|
||||
let options: IConnectionCompletionOptions = undefined;
|
||||
|
||||
connect(uri, options).then(() => {
|
||||
assert.equal(connectionManagementService.isProfileConnected(connectionProfile), true);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('failed connection should open the dialog if connection fails', done => {
|
||||
let uri = undefined;
|
||||
let error: string = 'error';
|
||||
let errorCode: number = 111;
|
||||
let errorCallStack: string = 'error call stack';
|
||||
let expectedConnection: boolean = false;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: error,
|
||||
errorCode: errorCode,
|
||||
callStack: errorCallStack
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, false);
|
||||
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('failed connection should not open the dialog if the option is set to false even if connection fails', done => {
|
||||
let uri = undefined;
|
||||
let error: string = 'error when options set to false';
|
||||
let errorCode: number = 111;
|
||||
let errorCallStack: string = 'error call stack';
|
||||
let expectedConnection: boolean = false;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: false,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: error,
|
||||
errorCode: errorCode,
|
||||
callStack: errorCallStack
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, false);
|
||||
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('failed firewall rule should open the firewall rule dialog', done => {
|
||||
handleFirewallRuleResult.canHandleFirewallRule = true;
|
||||
resolveHandleFirewallRuleDialog = true;
|
||||
isFirewallRuleAdded = true;
|
||||
|
||||
let uri = undefined;
|
||||
let error: string = 'error';
|
||||
let errorCode: number = 111;
|
||||
let expectedConnection: boolean = false;
|
||||
let expectedError: string = error;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfile, error, errorCode).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, expectedError);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, true);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('failed firewall rule connection should not open the firewall rule dialog if the option is set to false even if connection fails', done => {
|
||||
handleFirewallRuleResult.canHandleFirewallRule = true;
|
||||
resolveHandleFirewallRuleDialog = true;
|
||||
isFirewallRuleAdded = true;
|
||||
|
||||
let uri = undefined;
|
||||
let error: string = 'error when options set to false';
|
||||
let errorCallStack: string = 'error call stack';
|
||||
let errorCode: number = 111;
|
||||
let expectedConnection: boolean = false;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: false,
|
||||
showFirewallRuleOnError: false
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: error,
|
||||
errorCode: errorCode,
|
||||
callStack: errorCallStack
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, false);
|
||||
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('failed firewall rule connection and failed during open firewall rule should open the firewall rule dialog and connection dialog with error', done => {
|
||||
handleFirewallRuleResult.canHandleFirewallRule = true;
|
||||
resolveHandleFirewallRuleDialog = false;
|
||||
isFirewallRuleAdded = true;
|
||||
|
||||
let uri = undefined;
|
||||
let error: string = 'error when options set to false';
|
||||
let errorCode: number = 111;
|
||||
let errorCallStack: string = 'error call stack';
|
||||
let expectedConnection: boolean = false;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: error,
|
||||
errorCode: errorCode,
|
||||
callStack: errorCallStack
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, true);
|
||||
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, true);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('failed firewall rule connection should open the firewall rule dialog. Then canceled firewall rule dialog should not open connection dialog', done => {
|
||||
handleFirewallRuleResult.canHandleFirewallRule = true;
|
||||
resolveHandleFirewallRuleDialog = true;
|
||||
isFirewallRuleAdded = false;
|
||||
|
||||
let uri = undefined;
|
||||
let error: string = 'error when options set to false';
|
||||
let errorCallStack: string = 'error call stack';
|
||||
let errorCode: number = 111;
|
||||
let expectedConnection: boolean = false;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: error,
|
||||
errorCode: errorCode,
|
||||
callStack: errorCallStack
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfile, error, errorCode, errorCallStack).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, true);
|
||||
verifyShowConnectionDialog(connectionProfile, ConnectionType.default, uri, true, connectionResult, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('connect when password is empty and unsaved should open the dialog', done => {
|
||||
let uri = undefined;
|
||||
let expectedConnection: boolean = false;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: undefined,
|
||||
errorCode: undefined,
|
||||
callStack: undefined
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfileWithEmptyUnsavedPassword).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowConnectionDialog(connectionProfileWithEmptyUnsavedPassword, ConnectionType.default, uri, true, connectionResult);
|
||||
verifyShowFirewallRuleDialog(connectionProfile, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('connect when password is empty and saved should not open the dialog', done => {
|
||||
let uri = undefined;
|
||||
let expectedConnection: boolean = true;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: undefined,
|
||||
errorCode: undefined,
|
||||
callStack: undefined
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfileWithEmptySavedPassword).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowConnectionDialog(connectionProfileWithEmptySavedPassword, ConnectionType.default, uri, true, connectionResult, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('connect from editor when empty password when it is required and saved should not open the dialog', done => {
|
||||
let uri = 'editor 3';
|
||||
let expectedConnection: boolean = true;
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: {
|
||||
connectionType: ConnectionType.editor,
|
||||
input: {
|
||||
onConnectSuccess: undefined,
|
||||
onConnectReject: undefined,
|
||||
onConnectStart: undefined,
|
||||
onDisconnect: undefined,
|
||||
onConnectCanceled: undefined,
|
||||
uri: uri
|
||||
},
|
||||
querySelection: undefined,
|
||||
runQueryOnCompletion: RunQueryOnConnectionMode.none
|
||||
},
|
||||
saveTheConnection: true,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
let connectionResult: IConnectionResult = {
|
||||
connected: expectedConnection,
|
||||
errorMessage: undefined,
|
||||
errorCode: undefined,
|
||||
callStack: undefined
|
||||
};
|
||||
|
||||
connect(uri, options, false, connectionProfileWithEmptySavedPassword).then(result => {
|
||||
assert.equal(result.connected, expectedConnection);
|
||||
assert.equal(result.errorMessage, connectionResult.errorMessage);
|
||||
verifyShowConnectionDialog(connectionProfileWithEmptySavedPassword, ConnectionType.editor, uri, true, connectionResult, false);
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('doChangeLanguageFlavor should throw on unknown provider', done => {
|
||||
// given a provider that will never exist
|
||||
let invalidProvider = 'notaprovider';
|
||||
// when I call doChangeLanguageFlavor
|
||||
// Then I expect it to throw
|
||||
assert.throws(() => connectionManagementService.doChangeLanguageFlavor('file://my.sql', 'sql', invalidProvider));
|
||||
done();
|
||||
});
|
||||
|
||||
test('doChangeLanguageFlavor should send event for known provider', done => {
|
||||
// given a provider that is registered
|
||||
let uri = 'file://my.sql';
|
||||
let language = 'sql';
|
||||
let flavor = 'MSSQL';
|
||||
// when I call doChangeLanguageFlavor
|
||||
try {
|
||||
let called = false;
|
||||
connectionManagementService.onLanguageFlavorChanged((changeParams: azdata.DidChangeLanguageFlavorParams) => {
|
||||
called = true;
|
||||
assert.equal(changeParams.uri, uri);
|
||||
assert.equal(changeParams.language, language);
|
||||
assert.equal(changeParams.flavor, flavor);
|
||||
});
|
||||
connectionManagementService.doChangeLanguageFlavor(uri, language, flavor);
|
||||
assert.ok(called, 'expected onLanguageFlavorChanged event to be sent');
|
||||
done();
|
||||
} catch (error) {
|
||||
done(error);
|
||||
}
|
||||
});
|
||||
|
||||
test('ensureDefaultLanguageFlavor should not send event if uri is connected', done => {
|
||||
let uri: string = 'Editor Uri';
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: undefined,
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: false,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
let connectionManagementService = createConnectionManagementService();
|
||||
let called = false;
|
||||
connectionManagementService.onLanguageFlavorChanged((changeParams: azdata.DidChangeLanguageFlavorParams) => {
|
||||
called = true;
|
||||
});
|
||||
connect(uri, options).then(() => {
|
||||
connectionManagementService.ensureDefaultLanguageFlavor(uri);
|
||||
assert.equal(called, false, 'do not expect flavor change to be called');
|
||||
done();
|
||||
}).catch(err => {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('getConnectionId returns the URI associated with a connection that has had its database filled in', done => {
|
||||
// Set up the connection management service with a connection corresponding to a default database
|
||||
let dbName = 'master';
|
||||
let serverName = 'test_server';
|
||||
let userName = 'test_user';
|
||||
let connectionProfileWithoutDb: IConnectionProfile = Object.assign(connectionProfile,
|
||||
{ serverName: serverName, databaseName: '', userName: userName, getOptionsKey: () => undefined });
|
||||
let connectionProfileWithDb: IConnectionProfile = Object.assign(connectionProfileWithoutDb, { databaseName: dbName });
|
||||
// Save the database with a URI that has the database name filled in, to mirror Carbon's behavior
|
||||
let ownerUri = Utils.generateUri(connectionProfileWithDb);
|
||||
connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
|
||||
try {
|
||||
// If I get the URI for the connection with or without a database from the connection management service
|
||||
let actualUriWithDb = connectionManagementService.getConnectionUri(connectionProfileWithDb);
|
||||
let actualUriWithoutDb = connectionManagementService.getConnectionUri(connectionProfileWithoutDb);
|
||||
|
||||
// Then the retrieved URIs should match the one on the connection
|
||||
let expectedUri = Utils.generateUri(connectionProfileWithoutDb);
|
||||
assert.equal(actualUriWithDb, expectedUri);
|
||||
assert.equal(actualUriWithoutDb, expectedUri);
|
||||
done();
|
||||
} catch (err) {
|
||||
done(err);
|
||||
}
|
||||
}, err => done(err));
|
||||
});
|
||||
|
||||
test('getTabColorForUri returns undefined when there is no connection for the given URI', () => {
|
||||
let connectionManagementService = createConnectionManagementService();
|
||||
let color = connectionManagementService.getTabColorForUri('invalidUri');
|
||||
assert.equal(color, undefined);
|
||||
});
|
||||
|
||||
test('getTabColorForUri returns the group color corresponding to the connection for a URI', done => {
|
||||
// Set up the connection store to give back a group for the expected connection profile
|
||||
configResult['tabColorMode'] = 'border';
|
||||
let expectedColor = 'red';
|
||||
connectionStore.setup(x => x.getGroupFromId(connectionProfile.groupId)).returns(() => <IConnectionProfileGroup>{
|
||||
color: expectedColor
|
||||
});
|
||||
let uri = 'testUri';
|
||||
connect(uri).then(() => {
|
||||
try {
|
||||
let tabColor = connectionManagementService.getTabColorForUri(uri);
|
||||
assert.equal(tabColor, expectedColor);
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}, err => done(err));
|
||||
});
|
||||
|
||||
test('getActiveConnectionCredentials returns the credentials dictionary for a connection profile', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
profile.options = { password: profile.password };
|
||||
profile.id = 'test_id';
|
||||
connectionStatusManager.addConnection(profile, 'test_uri');
|
||||
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||
let credentials = connectionManagementService.getActiveConnectionCredentials(profile.id);
|
||||
assert.equal(credentials['password'], profile.options['password']);
|
||||
});
|
||||
|
||||
test('getConnectionUriFromId returns a URI of an active connection with the given id', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
profile.options = { password: profile.password };
|
||||
profile.id = 'test_id';
|
||||
let uri = 'test_initial_uri';
|
||||
connectionStatusManager.addConnection(profile, uri);
|
||||
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||
|
||||
// If I call getConnectionUriFromId on the given connection
|
||||
let foundUri = connectionManagementService.getConnectionUriFromId(profile.id);
|
||||
|
||||
// Then the returned URI matches the connection's original URI
|
||||
assert.equal(foundUri, uri);
|
||||
});
|
||||
|
||||
test('getConectionUriFromId returns undefined if the given connection is not active', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
profile.options = { password: profile.password };
|
||||
profile.id = 'test_id';
|
||||
connectionStatusManager.addConnection(profile, Utils.generateUri(profile));
|
||||
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||
|
||||
// If I call getConnectionUriFromId with a different URI than the connection's
|
||||
let foundUri = connectionManagementService.getConnectionUriFromId('different_id');
|
||||
|
||||
// Then undefined is returned
|
||||
assert.equal(foundUri, undefined);
|
||||
});
|
||||
|
||||
test('addSavedPassword fills in Azure access tokens for Azure accounts', async () => {
|
||||
// Set up a connection profile that uses Azure
|
||||
let azureConnectionProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, connectionProfile);
|
||||
azureConnectionProfile.authenticationType = 'AzureMFA';
|
||||
let username = 'testuser@microsoft.com';
|
||||
azureConnectionProfile.userName = username;
|
||||
let servername = 'test-database.database.windows.net';
|
||||
azureConnectionProfile.serverName = servername;
|
||||
|
||||
// Set up the account management service to return a token for the given user
|
||||
accountManagementService.setup(x => x.getAccountsForProvider(TypeMoq.It.isAny())).returns(providerId => Promise.resolve<azdata.Account[]>([
|
||||
{
|
||||
key: {
|
||||
accountId: username,
|
||||
providerId: providerId
|
||||
},
|
||||
displayInfo: undefined,
|
||||
isStale: false,
|
||||
properties: undefined
|
||||
}
|
||||
]));
|
||||
let testToken = 'testToken';
|
||||
accountManagementService.setup(x => x.getSecurityToken(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
azurePublicCloud: {
|
||||
token: testToken
|
||||
}
|
||||
}));
|
||||
connectionStore.setup(x => x.addSavedPassword(TypeMoq.It.is(profile => profile.authenticationType === 'AzureMFA'))).returns(profile => Promise.resolve({
|
||||
profile: profile,
|
||||
savedCred: false
|
||||
}));
|
||||
|
||||
// If I call addSavedPassword
|
||||
let profileWithCredentials = await connectionManagementService.addSavedPassword(azureConnectionProfile);
|
||||
|
||||
// Then the returned profile has the account token set
|
||||
assert.equal(profileWithCredentials.userName, username);
|
||||
assert.equal(profileWithCredentials.options['azureAccountToken'], testToken);
|
||||
});
|
||||
|
||||
test('addSavedPassword fills in Azure access token for selected tenant', async () => {
|
||||
// Set up a connection profile that uses Azure
|
||||
let azureConnectionProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, connectionProfile);
|
||||
azureConnectionProfile.authenticationType = 'AzureMFA';
|
||||
let username = 'testuser@microsoft.com';
|
||||
azureConnectionProfile.userName = username;
|
||||
let servername = 'test-database.database.windows.net';
|
||||
azureConnectionProfile.serverName = servername;
|
||||
let azureTenantId = 'testTenant';
|
||||
azureConnectionProfile.azureTenantId = azureTenantId;
|
||||
|
||||
// Set up the account management service to return a token for the given user
|
||||
accountManagementService.setup(x => x.getAccountsForProvider(TypeMoq.It.isAny())).returns(providerId => Promise.resolve<azdata.Account[]>([
|
||||
{
|
||||
key: {
|
||||
accountId: username,
|
||||
providerId: providerId
|
||||
},
|
||||
displayInfo: undefined,
|
||||
isStale: false,
|
||||
properties: undefined
|
||||
}
|
||||
]));
|
||||
let testToken = 'testToken';
|
||||
let returnedTokens = {};
|
||||
returnedTokens['azurePublicCloud'] = { token: 'badToken' };
|
||||
returnedTokens[azureTenantId] = { token: testToken };
|
||||
accountManagementService.setup(x => x.getSecurityToken(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(returnedTokens));
|
||||
connectionStore.setup(x => x.addSavedPassword(TypeMoq.It.is(profile => profile.authenticationType === 'AzureMFA'))).returns(profile => Promise.resolve({
|
||||
profile: profile,
|
||||
savedCred: false
|
||||
}));
|
||||
|
||||
// If I call addSavedPassword
|
||||
let profileWithCredentials = await connectionManagementService.addSavedPassword(azureConnectionProfile);
|
||||
|
||||
// Then the returned profile has the account token set corresponding to the requested tenant
|
||||
assert.equal(profileWithCredentials.userName, username);
|
||||
assert.equal(profileWithCredentials.options['azureAccountToken'], testToken);
|
||||
});
|
||||
|
||||
test('getConnections test', () => {
|
||||
const connectionStatusManagerMock = TypeMoq.Mock.ofType(ConnectionStatusManager, TypeMoq.MockBehavior.Loose);
|
||||
const connectionStoreMock = TypeMoq.Mock.ofType(ConnectionStore, TypeMoq.MockBehavior.Loose, new TestStorageService());
|
||||
|
||||
connectionStatusManagerMock.setup(x => x.getActiveConnectionProfiles(undefined)).returns(() => {
|
||||
return [createConnectionProfile('1'), createConnectionProfile('2')];
|
||||
});
|
||||
connectionStoreMock.setup(x => x.getRecentlyUsedConnections(undefined)).returns(() => {
|
||||
return [createConnectionProfile('1'), createConnectionProfile('3')];
|
||||
});
|
||||
|
||||
const group1 = createConnectionGroup('group1');
|
||||
const group2 = createConnectionGroup('group2');
|
||||
group1.connections = [createConnectionProfile('1'), createConnectionProfile('4')];
|
||||
group1.children = [group2];
|
||||
group2.connections = [createConnectionProfile('5'), createConnectionProfile('6')];
|
||||
connectionStoreMock.setup(x => x.getConnectionProfileGroups(TypeMoq.It.isAny(), undefined)).returns(() => {
|
||||
return [group1];
|
||||
});
|
||||
const connectionManagementService = new ConnectionManagementService(connectionStoreMock.object, connectionStatusManagerMock.object, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
|
||||
|
||||
// dupe connections have been seeded the numbers below already reflected the de-duped results
|
||||
|
||||
const verifyConnections = (actualConnections: ConnectionProfile[], expectedConnectionIds: string[], scenario: string) => {
|
||||
assert.equal(actualConnections.length, expectedConnectionIds.length, 'incorrect number of connections returned, ' + scenario);
|
||||
assert.deepEqual(actualConnections.map(conn => conn.id).sort(), expectedConnectionIds.sort(), 'connections do not match expectation, ' + scenario);
|
||||
};
|
||||
|
||||
// no parameter - default to false
|
||||
let connections = connectionManagementService.getConnections();
|
||||
verifyConnections(connections, ['1', '2', '3', '4', '5', '6'], 'no parameter provided');
|
||||
|
||||
// explicitly set to false
|
||||
connections = connectionManagementService.getConnections(false);
|
||||
verifyConnections(connections, ['1', '2', '3', '4', '5', '6'], 'parameter is false');
|
||||
|
||||
// active connections only
|
||||
connections = connectionManagementService.getConnections(true);
|
||||
verifyConnections(connections, ['1', '2'], 'parameter is true');
|
||||
});
|
||||
});
|
||||
|
||||
function createConnectionProfile(id: string): ConnectionProfile {
|
||||
|
||||
const capabilitiesService = new TestCapabilitiesService();
|
||||
return new ConnectionProfile(capabilitiesService, {
|
||||
connectionName: 'newName',
|
||||
savePassword: false,
|
||||
groupFullName: 'testGroup',
|
||||
serverName: 'testServerName',
|
||||
databaseName: 'testDatabaseName',
|
||||
authenticationType: Constants.integrated,
|
||||
password: 'test',
|
||||
userName: 'testUsername',
|
||||
groupId: undefined,
|
||||
providerName: Constants.mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: id
|
||||
});
|
||||
}
|
||||
|
||||
function createConnectionGroup(id: string): ConnectionProfileGroup {
|
||||
return new ConnectionProfileGroup(id, undefined, id, undefined, undefined);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { IConnectionProfile, IConnectionProfileStore } from 'sql/platform/connection/common/interfaces';
|
||||
import * as azdata from 'azdata';
|
||||
import * as assert from 'assert';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
|
||||
suite('SQL ConnectionProfileInfo tests', () => {
|
||||
let msSQLCapabilities: ConnectionProviderProperties;
|
||||
let capabilitiesService: TestCapabilitiesService;
|
||||
|
||||
let connectionProfile: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: undefined,
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
|
||||
let storedProfile: IConnectionProfileStore = {
|
||||
groupId: 'groupId',
|
||||
id: 'id',
|
||||
options: {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: ''
|
||||
},
|
||||
providerName: mssqlProviderName,
|
||||
savePassword: true
|
||||
};
|
||||
|
||||
setup(() => {
|
||||
let connectionProvider: azdata.ConnectionOption[] = [
|
||||
{
|
||||
name: 'connectionName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.connectionName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'serverName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.serverName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'databaseName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.databaseName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'userName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.userName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'authenticationType',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.authType,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'password',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.password,
|
||||
valueType: ServiceOptionType.string
|
||||
}
|
||||
];
|
||||
msSQLCapabilities = {
|
||||
providerId: mssqlProviderName,
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: connectionProvider
|
||||
};
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
capabilitiesService.capabilities[mssqlProviderName] = { connection: msSQLCapabilities };
|
||||
});
|
||||
|
||||
test('set properties should set the values correctly', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, undefined);
|
||||
assert.equal(conn.serverName, undefined);
|
||||
conn.connectionName = connectionProfile.connectionName;
|
||||
conn.serverName = connectionProfile.serverName;
|
||||
conn.databaseName = connectionProfile.databaseName;
|
||||
conn.authenticationType = connectionProfile.authenticationType;
|
||||
conn.password = connectionProfile.password;
|
||||
conn.userName = connectionProfile.userName;
|
||||
conn.groupId = connectionProfile.groupId;
|
||||
conn.groupFullName = connectionProfile.groupFullName;
|
||||
conn.savePassword = connectionProfile.savePassword;
|
||||
assert.equal(conn.connectionName, connectionProfile.connectionName);
|
||||
assert.equal(conn.serverName, connectionProfile.serverName);
|
||||
assert.equal(conn.databaseName, connectionProfile.databaseName);
|
||||
assert.equal(conn.authenticationType, connectionProfile.authenticationType);
|
||||
assert.equal(conn.password, connectionProfile.password);
|
||||
assert.equal(conn.userName, connectionProfile.userName);
|
||||
assert.equal(conn.groupId, connectionProfile.groupId);
|
||||
assert.equal(conn.groupFullName, connectionProfile.groupFullName);
|
||||
assert.equal(conn.savePassword, connectionProfile.savePassword);
|
||||
});
|
||||
|
||||
test('constructor should initialize the options given a valid model', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
|
||||
assert.equal(conn.connectionName, connectionProfile.connectionName);
|
||||
assert.equal(conn.serverName, connectionProfile.serverName);
|
||||
assert.equal(conn.databaseName, connectionProfile.databaseName);
|
||||
assert.equal(conn.authenticationType, connectionProfile.authenticationType);
|
||||
assert.equal(conn.password, connectionProfile.password);
|
||||
assert.equal(conn.userName, connectionProfile.userName);
|
||||
assert.equal(conn.groupId, connectionProfile.groupId);
|
||||
assert.equal(conn.groupFullName, connectionProfile.groupFullName);
|
||||
assert.equal(conn.savePassword, connectionProfile.savePassword);
|
||||
});
|
||||
|
||||
test('getOptionsKey should create a valid unique id', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
let expectedId = 'providerName:MSSQL|authenticationType:|databaseName:database|serverName:new server|userName:user|databaseDisplayName:database|group:group id';
|
||||
let id = conn.getOptionsKey();
|
||||
assert.equal(id, expectedId);
|
||||
});
|
||||
|
||||
test('createFromStoredProfile should create connection profile from stored profile', () => {
|
||||
let savedProfile = storedProfile;
|
||||
let connectionProfile = ConnectionProfile.createFromStoredProfile(savedProfile, capabilitiesService);
|
||||
assert.equal(savedProfile.groupId, connectionProfile.groupId);
|
||||
assert.deepEqual(savedProfile.providerName, connectionProfile.providerName);
|
||||
assert.deepEqual(savedProfile.savePassword, connectionProfile.savePassword);
|
||||
assert.deepEqual(savedProfile.id, connectionProfile.id);
|
||||
});
|
||||
|
||||
test('createFromStoredProfile should set the id to new guid if not set in stored profile', () => {
|
||||
let savedProfile = Object.assign({}, storedProfile, { id: undefined });
|
||||
let connectionProfile = ConnectionProfile.createFromStoredProfile(savedProfile, capabilitiesService);
|
||||
assert.equal(savedProfile.groupId, connectionProfile.groupId);
|
||||
assert.deepEqual(savedProfile.providerName, connectionProfile.providerName);
|
||||
assert.equal(savedProfile.savePassword, connectionProfile.savePassword);
|
||||
assert.notEqual(connectionProfile.id, undefined);
|
||||
assert.equal(savedProfile.id, undefined);
|
||||
});
|
||||
|
||||
test('withoutPassword should create a new instance without password', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
assert.notEqual(conn.password, '');
|
||||
let withoutPassword = conn.withoutPassword();
|
||||
assert.equal(withoutPassword.password, '');
|
||||
});
|
||||
|
||||
test('unique id should not include password', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
let withoutPassword = conn.withoutPassword();
|
||||
assert.equal(withoutPassword.getOptionsKey(), conn.getOptionsKey());
|
||||
});
|
||||
|
||||
test('cloneWithDatabase should create new profile with new id', () => {
|
||||
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
let newProfile = conn.cloneWithDatabase('new db');
|
||||
assert.notEqual(newProfile.id, conn.id);
|
||||
assert.equal(newProfile.databaseName, 'new db');
|
||||
});
|
||||
|
||||
test('an empty connection profile does not cause issues', () => {
|
||||
assert.doesNotThrow(() => new ConnectionProfile(capabilitiesService, {} as IConnectionProfile));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import * as assert from 'assert';
|
||||
|
||||
suite('SQL ConnectionProfileGroup tests', () => {
|
||||
let root: ConnectionProfileGroup;
|
||||
let Groups1 = 'G1';
|
||||
let Groups11 = 'G11';
|
||||
let Groups2 = 'G2';
|
||||
let group1Node: ConnectionProfileGroup;
|
||||
let group11Node: ConnectionProfileGroup;
|
||||
let group2Node: ConnectionProfileGroup;
|
||||
setup(() => {
|
||||
root = new ConnectionProfileGroup(ConnectionProfileGroup.RootGroupName, undefined, ConnectionProfileGroup.RootGroupName, undefined, undefined);
|
||||
|
||||
group1Node = new ConnectionProfileGroup(Groups1, root, Groups1, undefined, undefined);
|
||||
group2Node = new ConnectionProfileGroup(Groups2, root, Groups2, undefined, undefined);
|
||||
group11Node = new ConnectionProfileGroup(Groups11, root, Groups11, undefined, undefined);
|
||||
root.addGroups([group1Node]);
|
||||
group1Node.addGroups([group11Node]);
|
||||
root.addGroups([group2Node]);
|
||||
});
|
||||
|
||||
test('Root name should be returned as empty string', () => {
|
||||
assert.equal(root.name, '');
|
||||
});
|
||||
|
||||
test('Fullname should return the group full name correctly', () => {
|
||||
assert.equal(group1Node.fullName, 'G1');
|
||||
assert.equal(group2Node.fullName, 'G2');
|
||||
assert.equal(group11Node.fullName, 'G1/G11');
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should return a list With ROOT in it given an empty string', () => {
|
||||
let groupFullName: string = '';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should return a list With ROOT in it given null', () => {
|
||||
let groupFullName: string = undefined;
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should return a list With ROOT in it given /', () => {
|
||||
let groupFullName: string = '/';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should add ROOT as first item if not added already and string starts with /', () => {
|
||||
let groupFullName: string = '/Groups/Group1';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName, 'Groups', 'Group1'];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should add ROOT as first item if not added already', () => {
|
||||
let groupFullName: string = 'Groups/Group1';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName, 'Groups', 'Group1'];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should not add ROOT if already added and string starts with /', () => {
|
||||
let groupFullName: string = '/ROOT/Groups/Group1';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName, 'Groups', 'Group1'];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should not add ROOT if already added', () => {
|
||||
let groupFullName: string = 'ROOT/Groups/Group1';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName, 'Groups', 'Group1'];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('getGroupFullNameParts should not add ROOT if already added and it is not uppercase', () => {
|
||||
let groupFullName: string = 'rOOT/Groups/Group1';
|
||||
let expected: string[] = [ConnectionProfileGroup.RootGroupName, 'Groups', 'Group1'];
|
||||
let actual = ConnectionProfileGroup.getGroupFullNameParts(groupFullName);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('isRoot should return true given empty string', () => {
|
||||
let name: string = '';
|
||||
let expected: boolean = true;
|
||||
let actual = ConnectionProfileGroup.isRoot(name);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('isRoot should return true given null', () => {
|
||||
let name: string = undefined;
|
||||
let expected: boolean = true;
|
||||
let actual = ConnectionProfileGroup.isRoot(name);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('isRoot should return true given /', () => {
|
||||
let name: string = '/';
|
||||
let expected: boolean = true;
|
||||
let actual = ConnectionProfileGroup.isRoot(name);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('isRoot should return true given root', () => {
|
||||
let name: string = 'root';
|
||||
let expected: boolean = true;
|
||||
let actual = ConnectionProfileGroup.isRoot(name);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('sameGroupName should return true given root', () => {
|
||||
let name1: string = '/';
|
||||
let name2: string = '';
|
||||
let expected: boolean = true;
|
||||
let actual = ConnectionProfileGroup.sameGroupName(name1, name2);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('sameGroupName should return true given same group names', () => {
|
||||
let name1: string = '/group1';
|
||||
let name2: string = '/Group1';
|
||||
let expected: boolean = true;
|
||||
let actual = ConnectionProfileGroup.sameGroupName(name1, name2);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test('sameGroupName should return false given two different groups', () => {
|
||||
let name1: string = '/';
|
||||
let name2: string = '/Group1';
|
||||
let expected: boolean = false;
|
||||
let actual = ConnectionProfileGroup.sameGroupName(name1, name2);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,258 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as azdata from 'azdata';
|
||||
import { ConnectionStatusManager } from 'sql/platform/connection/common/connectionStatusManager';
|
||||
import * as Utils from 'sql/platform/connection/common/utils';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { TestEnvironmentService } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
import { NullLogService } from 'vs/platform/log/common/log';
|
||||
|
||||
let connections: ConnectionStatusManager;
|
||||
let capabilitiesService: TestCapabilitiesService;
|
||||
let connectionProfileObject: ConnectionProfile;
|
||||
let connectionProfile: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection1',
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
let editorConnectionProfile: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection2',
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
let connectionProfileWithoutDbName: IConnectionProfile = {
|
||||
connectionName: 'new name',
|
||||
serverName: 'new server',
|
||||
databaseName: '',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: 'group id',
|
||||
getOptionsKey: () => 'connection1',
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
|
||||
let connection1Id: string;
|
||||
let connection2Id: string;
|
||||
let connection3Id: string;
|
||||
|
||||
suite('SQL ConnectionStatusManager tests', () => {
|
||||
setup(() => {
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
connectionProfileObject = new ConnectionProfile(capabilitiesService, connectionProfile);
|
||||
connections = new ConnectionStatusManager(capabilitiesService, new NullLogService(), TestEnvironmentService, new TestNotificationService());
|
||||
connection1Id = Utils.generateUri(connectionProfile);
|
||||
connection2Id = 'connection2Id';
|
||||
connection3Id = 'connection3Id';
|
||||
connections.addConnection(connectionProfile, connection1Id);
|
||||
connections.addConnection(editorConnectionProfile, connection2Id);
|
||||
connections.addConnection(connectionProfileWithoutDbName, connection3Id);
|
||||
});
|
||||
|
||||
test('findConnection should return undefined given invalid id', () => {
|
||||
let id: string = 'invalid id';
|
||||
let expected = undefined;
|
||||
let actual = connections.findConnection(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('findConnection should return connection given valid id', () => {
|
||||
let id: string = connection1Id;
|
||||
let expected = connectionProfileObject;
|
||||
let actual = connections.findConnection(id);
|
||||
assert.equal(connectionProfileObject.matches(actual.connectionProfile), true);
|
||||
});
|
||||
|
||||
test('getConnectionProfile should return undefined given invalid id', () => {
|
||||
let id: string = 'invalid id';
|
||||
let expected = undefined;
|
||||
let actual = connections.getConnectionProfile(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('getConnectionProfile should return connection given valid id', () => {
|
||||
let id: string = connection1Id;
|
||||
let expected = connectionProfileObject;
|
||||
let actual = connections.getConnectionProfile(id);
|
||||
assert.equal(connectionProfileObject.matches(actual), true);
|
||||
});
|
||||
|
||||
test('hasConnection should return false given invalid id', () => {
|
||||
let id: string = 'invalid id';
|
||||
let expected = false;
|
||||
let actual = connections.hasConnection(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('hasConnection should return true given valid id', () => {
|
||||
let id: string = connection1Id;
|
||||
let expected = true;
|
||||
let actual = connections.hasConnection(id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('addConnection should set connecting to true', () => {
|
||||
let expected = true;
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
ownerUri: connection1Id,
|
||||
connectionId: connection1Id,
|
||||
messages: undefined,
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
serverInfo: undefined,
|
||||
connectionSummary: undefined
|
||||
};
|
||||
connections.onConnectionComplete(summary);
|
||||
let actual = connections.addConnection(connectionProfile, connection1Id).connecting;
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('onConnectionComplete should set connecting to false', () => {
|
||||
let expected = false;
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
ownerUri: connection1Id,
|
||||
connectionId: connection1Id,
|
||||
messages: undefined,
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
serverInfo: undefined,
|
||||
connectionSummary: undefined
|
||||
};
|
||||
connections.onConnectionComplete(summary);
|
||||
let actual = connections.findConnection(connection1Id).connecting;
|
||||
assert.equal(actual, expected);
|
||||
actual = connections.isConnecting(connection1Id);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
test('updateConnection should update the connection info', () => {
|
||||
let expected = connectionProfile.groupId + '1';
|
||||
let expectedConnectionId = 'new id';
|
||||
connections.addConnection(connectionProfile, connection1Id);
|
||||
|
||||
let updatedConnection = Object.assign({}, connectionProfile, { groupId: expected, getOptionsKey: () => connectionProfile.getOptionsKey() + expected, id: expectedConnectionId });
|
||||
let actualId = connections.updateConnectionProfile(updatedConnection, connection1Id);
|
||||
|
||||
let newId = Utils.generateUri(updatedConnection);
|
||||
let actual = connections.getConnectionProfile(newId).groupId;
|
||||
let actualConnectionId = connections.getConnectionProfile(newId).id;
|
||||
assert.equal(actual, expected);
|
||||
assert.equal(actualId, newId);
|
||||
assert.equal(actualConnectionId, expectedConnectionId);
|
||||
});
|
||||
|
||||
test('updateDatabaseName should update the database name in connection', () => {
|
||||
let dbName: string = 'db name';
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
connectionSummary: {
|
||||
databaseName: dbName,
|
||||
serverName: undefined,
|
||||
userName: undefined
|
||||
}
|
||||
, ownerUri: connection3Id,
|
||||
connectionId: 'connection id',
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
messages: undefined,
|
||||
serverInfo: undefined
|
||||
};
|
||||
|
||||
//The original connection didn't have database name
|
||||
let connectionStatus = connections.findConnection(connection3Id);
|
||||
connectionStatus.connectionProfile.databaseName = '';
|
||||
|
||||
//Verify database name changed after connection is complete
|
||||
connections.updateDatabaseName(summary);
|
||||
connectionStatus = connections.findConnection(connection3Id);
|
||||
assert.equal(connectionStatus.connectionProfile.databaseName, dbName);
|
||||
});
|
||||
|
||||
test('getOriginalOwnerUri should return the original uri given uri with db name', () => {
|
||||
let dbName: string = 'db name';
|
||||
let summary: azdata.ConnectionInfoSummary = {
|
||||
connectionSummary: {
|
||||
databaseName: dbName,
|
||||
serverName: undefined,
|
||||
userName: undefined
|
||||
}
|
||||
, ownerUri: connection3Id,
|
||||
connectionId: 'connection id',
|
||||
errorMessage: undefined,
|
||||
errorNumber: undefined,
|
||||
messages: undefined,
|
||||
serverInfo: undefined
|
||||
};
|
||||
|
||||
//The original connection didn't have database name
|
||||
let connectionStatus = connections.findConnection(connection3Id);
|
||||
connectionStatus.connectionProfile.databaseName = '';
|
||||
|
||||
//Verify database name changed after connection is complete
|
||||
connections.updateDatabaseName(summary);
|
||||
connectionStatus = connections.findConnection(connection3Id);
|
||||
let ownerUriWithDbName = Utils.generateUriWithPrefix(connectionStatus.connectionProfile, 'connection://');
|
||||
|
||||
//The uri assigned to connection without db name should be the original one
|
||||
let connectionWitDbStatus = connections.getOriginalOwnerUri(ownerUriWithDbName);
|
||||
assert.equal(connectionWitDbStatus, connection3Id);
|
||||
});
|
||||
|
||||
test('getOriginalOwnerUri should return given uri if the original uri is the same as the given uri', () => {
|
||||
|
||||
let connectionStatus = connections.getOriginalOwnerUri(connection2Id);
|
||||
assert.equal(connectionStatus, connection2Id);
|
||||
});
|
||||
|
||||
test('getActiveConnectionProfiles should return a list of all the unique connections that the status manager knows about', () => {
|
||||
// Add duplicate connections
|
||||
let newConnection = Object.assign({}, connectionProfile);
|
||||
newConnection.id = 'test_id';
|
||||
newConnection.serverName = 'new_server_name';
|
||||
newConnection.options['databaseDisplayName'] = newConnection.databaseName;
|
||||
connections.addConnection(newConnection, 'test_uri_1');
|
||||
connections.addConnection(newConnection, 'test_uri_2');
|
||||
|
||||
// Get the connections and verify that the duplicate is only returned once
|
||||
let activeConnections = connections.getActiveConnectionProfiles();
|
||||
assert.equal(activeConnections.length, 4);
|
||||
assert.equal(activeConnections.filter(connection => connection.matches(newConnection)).length, 1, 'Did not find newConnection in active connections');
|
||||
});
|
||||
});
|
||||
@@ -13,7 +13,7 @@ import { TestConfigurationService } from 'sql/platform/connection/test/common/te
|
||||
import { TestCredentialsService } from 'sql/platform/credentials/test/common/testCredentialsService';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { deepClone, deepFreeze } from 'vs/base/common/objects';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { TestStorageService } from 'vs/workbench/test/workbenchTestServices';
|
||||
@@ -37,7 +37,7 @@ suite('ConnectionStore', () => {
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
});
|
||||
let capabilitiesService: CapabilitiesTestService;
|
||||
let capabilitiesService: TestCapabilitiesService;
|
||||
let maxRecent = 5;
|
||||
let msSQLCapabilities: ConnectionProviderProperties;
|
||||
let provider2Capabilities: ConnectionProviderProperties;
|
||||
@@ -46,7 +46,7 @@ suite('ConnectionStore', () => {
|
||||
setup(() => {
|
||||
// setup configuration to return maxRecent for the #MRU items
|
||||
|
||||
capabilitiesService = new CapabilitiesTestService();
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
let connectionProvider: azdata.ConnectionOption[] = [
|
||||
{
|
||||
name: 'connectionName',
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ProviderConnectionInfo } from 'sql/platform/connection/common/providerConnectionInfo';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import * as azdata from 'azdata';
|
||||
import * as assert from 'assert';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { TestCapabilitiesService } from 'sql/platform/capabilities/test/common/testCapabilitiesService';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
|
||||
suite('SQL ProviderConnectionInfo tests', () => {
|
||||
let msSQLCapabilities: any;
|
||||
let capabilitiesService: TestCapabilitiesService;
|
||||
|
||||
let connectionProfile: IConnectionProfile = {
|
||||
connectionName: 'name',
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
savePassword: true,
|
||||
groupFullName: 'g2/g2-2',
|
||||
groupId: undefined,
|
||||
getOptionsKey: undefined,
|
||||
matches: undefined,
|
||||
providerName: mssqlProviderName,
|
||||
options: undefined,
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
};
|
||||
|
||||
setup(() => {
|
||||
let capabilities: azdata.DataProtocolServerCapabilities[] = [];
|
||||
let connectionProvider: azdata.ConnectionOption[] = [
|
||||
{
|
||||
name: 'connectionName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.connectionName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'serverName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.serverName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'databaseName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.databaseName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'userName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.userName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'authenticationType',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.authType,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'password',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.password,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'encrypt',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: false,
|
||||
isRequired: false,
|
||||
specialValueType: undefined,
|
||||
valueType: ServiceOptionType.string
|
||||
}
|
||||
];
|
||||
msSQLCapabilities = {
|
||||
providerId: mssqlProviderName,
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: connectionProvider,
|
||||
};
|
||||
capabilities.push(msSQLCapabilities);
|
||||
capabilitiesService = new TestCapabilitiesService();
|
||||
capabilitiesService.capabilities[mssqlProviderName] = { connection: msSQLCapabilities };
|
||||
});
|
||||
|
||||
test('constructor should accept undefined parameters', () => {
|
||||
let conn = new ProviderConnectionInfo(undefined, undefined);
|
||||
assert.equal(conn.serverName, undefined);
|
||||
});
|
||||
|
||||
test('set properties should set the values correctly', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, mssqlProviderName);
|
||||
assert.equal(conn.serverName, undefined);
|
||||
conn.connectionName = connectionProfile.connectionName;
|
||||
conn.serverName = connectionProfile.serverName;
|
||||
conn.databaseName = connectionProfile.databaseName;
|
||||
conn.authenticationType = connectionProfile.authenticationType;
|
||||
conn.password = connectionProfile.password;
|
||||
conn.userName = connectionProfile.userName;
|
||||
assert.equal(conn.connectionName, connectionProfile.connectionName);
|
||||
assert.equal(conn.serverName, connectionProfile.serverName);
|
||||
assert.equal(conn.databaseName, connectionProfile.databaseName);
|
||||
assert.equal(conn.authenticationType, connectionProfile.authenticationType);
|
||||
assert.equal(conn.password, connectionProfile.password);
|
||||
assert.equal(conn.userName, connectionProfile.userName);
|
||||
});
|
||||
|
||||
test('set properties should store the values in the options', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, mssqlProviderName);
|
||||
assert.equal(conn.serverName, undefined);
|
||||
conn.serverName = connectionProfile.serverName;
|
||||
conn.databaseName = connectionProfile.databaseName;
|
||||
conn.authenticationType = connectionProfile.authenticationType;
|
||||
conn.password = connectionProfile.password;
|
||||
conn.userName = connectionProfile.userName;
|
||||
assert.equal(conn.getOptionValue('serverName'), connectionProfile.serverName);
|
||||
assert.equal(conn.getOptionValue('databaseName'), connectionProfile.databaseName);
|
||||
assert.equal(conn.getOptionValue('authenticationType'), connectionProfile.authenticationType);
|
||||
assert.equal(conn.getOptionValue('password'), connectionProfile.password);
|
||||
assert.equal(conn.getOptionValue('userName'), connectionProfile.userName);
|
||||
});
|
||||
|
||||
test('constructor should initialize the options given a valid model', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
|
||||
|
||||
assert.equal(conn.connectionName, connectionProfile.connectionName);
|
||||
assert.equal(conn.serverName, connectionProfile.serverName);
|
||||
assert.equal(conn.databaseName, connectionProfile.databaseName);
|
||||
assert.equal(conn.authenticationType, connectionProfile.authenticationType);
|
||||
assert.equal(conn.password, connectionProfile.password);
|
||||
assert.equal(conn.userName, connectionProfile.userName);
|
||||
});
|
||||
|
||||
test('clone should create a new instance that equals the old one', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
|
||||
|
||||
let conn2 = conn.clone();
|
||||
assert.equal(conn.connectionName, conn2.connectionName);
|
||||
assert.equal(conn.serverName, conn2.serverName);
|
||||
assert.equal(conn.databaseName, conn2.databaseName);
|
||||
assert.equal(conn.authenticationType, conn2.authenticationType);
|
||||
assert.equal(conn.password, conn2.password);
|
||||
assert.equal(conn.userName, conn2.userName);
|
||||
});
|
||||
|
||||
test('Changing the cloned object should not change the original one', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
|
||||
|
||||
let conn2 = conn.clone();
|
||||
conn2.serverName = conn.serverName + '1';
|
||||
assert.notEqual(conn.serverName, conn2.serverName);
|
||||
});
|
||||
|
||||
test('constructor should initialize the options given a valid model with options', () => {
|
||||
let options = {};
|
||||
options['encrypt'] = 'test value';
|
||||
let conn2 = Object.assign({}, connectionProfile, { options: options });
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, conn2);
|
||||
|
||||
assert.equal(conn.connectionName, conn2.connectionName);
|
||||
assert.equal(conn.serverName, conn2.serverName);
|
||||
assert.equal(conn.databaseName, conn2.databaseName);
|
||||
assert.equal(conn.authenticationType, conn2.authenticationType);
|
||||
assert.equal(conn.password, conn2.password);
|
||||
assert.equal(conn.userName, conn2.userName);
|
||||
assert.equal(conn.options['encrypt'], 'test value');
|
||||
});
|
||||
|
||||
test('getOptionsKey should create a valid unique id', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
|
||||
let expectedId = 'providerName:MSSQL|authenticationType:|databaseName:database|serverName:new server|userName:user';
|
||||
let id = conn.getOptionsKey();
|
||||
assert.equal(id, expectedId);
|
||||
});
|
||||
|
||||
test('getOptionsKey should create different id for different server names', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
|
||||
let conn2 = new ProviderConnectionInfo(capabilitiesService, Object.assign({}, connectionProfile, { serverName: connectionProfile.serverName + '1' }));
|
||||
|
||||
assert.notEqual(conn.getOptionsKey(), conn2.getOptionsKey());
|
||||
});
|
||||
|
||||
test('titleParts should return server, database and auth type as first items', () => {
|
||||
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
|
||||
let titleParts = conn.titleParts;
|
||||
assert.equal(titleParts.length, 4);
|
||||
assert.equal(titleParts[0], connectionProfile.serverName);
|
||||
assert.equal(titleParts[1], connectionProfile.databaseName);
|
||||
assert.equal(titleParts[2], connectionProfile.authenticationType);
|
||||
assert.equal(titleParts[3], connectionProfile.userName);
|
||||
});
|
||||
|
||||
test('getProviderFromOptionsKey should return the provider name from the options key successfully', () => {
|
||||
let optionsKey = `providerName:${mssqlProviderName}|authenticationType:|databaseName:database|serverName:new server|userName:user`;
|
||||
let actual = ProviderConnectionInfo.getProviderFromOptionsKey(optionsKey);
|
||||
|
||||
assert.equal(mssqlProviderName, actual);
|
||||
});
|
||||
|
||||
test('getProviderFromOptionsKey should return empty string give null', () => {
|
||||
let optionsKey = undefined;
|
||||
let expectedProviderId: string = '';
|
||||
let actual = ProviderConnectionInfo.getProviderFromOptionsKey(optionsKey);
|
||||
|
||||
assert.equal(expectedProviderId, actual);
|
||||
});
|
||||
|
||||
test('getProviderFromOptionsKey should return empty string give key without provider name', () => {
|
||||
let optionsKey = 'providerName2:MSSQL|authenticationType:|databaseName:database|serverName:new server|userName:user';
|
||||
let expectedProviderId: string = '';
|
||||
let actual = ProviderConnectionInfo.getProviderFromOptionsKey(optionsKey);
|
||||
|
||||
assert.equal(expectedProviderId, actual);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,297 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IConnectionManagementService, IConnectableInput, IConnectionCompletionOptions, IConnectionCallbacks, IConnectionResult, INewConnectionParams }
|
||||
from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
import * as azdata from 'azdata';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
|
||||
// Test stubs for commonly used objects
|
||||
|
||||
export class TestConnectionManagementService implements IConnectionManagementService {
|
||||
_serviceBrand: any;
|
||||
onAddConnectionProfile = undefined;
|
||||
onDeleteConnectionProfile = undefined;
|
||||
onConnectionChanged = undefined;
|
||||
onLanguageFlavorChanged = undefined;
|
||||
|
||||
public get onConnect(): Event<any> {
|
||||
let conEvent = new Emitter<any>();
|
||||
return conEvent.event;
|
||||
}
|
||||
|
||||
public get onDisconnect(): Event<any> {
|
||||
let conEvent = new Emitter<any>();
|
||||
return conEvent.event;
|
||||
}
|
||||
|
||||
registerProvider(providerId: string, provider: azdata.ConnectionProvider): void {
|
||||
|
||||
}
|
||||
|
||||
registerIconProvider(providerId: string, provider: azdata.IconProvider): void {
|
||||
|
||||
}
|
||||
|
||||
showConnectionDialog(params?: INewConnectionParams, options?: IConnectionCompletionOptions, model?: IConnectionProfile, connectionResult?: IConnectionResult): Promise<void> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
showCreateServerGroupDialog(): Promise<void> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
showEditServerGroupDialog(group: ConnectionProfileGroup): Promise<void> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
onConnectionComplete(handle: number, connectionInfoSummary: azdata.ConnectionInfoSummary): void {
|
||||
|
||||
}
|
||||
|
||||
onIntelliSenseCacheComplete(handle: number, connectionUri: string): void {
|
||||
|
||||
}
|
||||
|
||||
public onConnectionChangedNotification(handle: number, changedConnInfo: azdata.ChangedConnectionInfo): void {
|
||||
|
||||
}
|
||||
|
||||
getCurrentConnectionSummary(): azdata.ConnectionSummary {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionGroups(providers?: string[]): ConnectionProfileGroup[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
getActiveConnections(providers?: string[]): ConnectionProfile[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getRecentConnections(providers?: string[]): ConnectionProfile[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public clearRecentConnectionsList(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
public clearRecentConnection(connectionProfile: ConnectionProfile): void {
|
||||
return;
|
||||
}
|
||||
|
||||
getUnsavedConnections(): ConnectionProfile[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
changeGroupIdForConnectionGroup(source: IConnectionProfileGroup, target: IConnectionProfileGroup): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
changeGroupIdForConnection(source: ConnectionProfile, targetGroupId: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
deleteConnection(connection: ConnectionProfile): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
deleteConnectionGroup(group: ConnectionProfileGroup): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
getAdvancedProperties(): azdata.ConnectionOption[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
getConnectionUri(connectionProfile: ConnectionProfile): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getFormattedUri(uri: string, connectionProfile: ConnectionProfile): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionUriFromId(connectionId: string): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
isConnected(fileUri: string, connectionProfile?: ConnectionProfile): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isRecent(connectionProfile: ConnectionProfile): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isProfileConnected(connectionProfile: IConnectionProfile): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isProfileConnecting(connectionProfile: IConnectionProfile): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
findExistingConnection(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection'): ConnectionProfile {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
connect(connection: IConnectionProfile, uri: string, options?: IConnectionCompletionOptions, callbacks?: IConnectionCallbacks): Promise<IConnectionResult> {
|
||||
return new Promise<IConnectionResult>((resolve, reject) => {
|
||||
resolve({ connected: true, errorMessage: undefined, errorCode: undefined, callStack: undefined });
|
||||
});
|
||||
}
|
||||
|
||||
connectAndSaveProfile(connection: IConnectionProfile, uri: string, options?: IConnectionCompletionOptions, callbacks?: IConnectionCallbacks): Promise<IConnectionResult> {
|
||||
return new Promise<IConnectionResult>(() => true);
|
||||
}
|
||||
|
||||
disconnectEditor(owner: IConnectableInput): Promise<boolean> {
|
||||
return new Promise<boolean>(() => true);
|
||||
}
|
||||
|
||||
disconnect(connection: IConnectionProfile);
|
||||
disconnect(uri: string);
|
||||
disconnect(input: any): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
getConnectionProfile(fileUri: string): IConnectionProfile {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionInfo(fileUri: string): ConnectionManagementInfo {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
addSavedPassword(connectionProfile: IConnectionProfile): Promise<IConnectionProfile> {
|
||||
return new Promise<IConnectionProfile>(() => connectionProfile);
|
||||
}
|
||||
|
||||
public listDatabases(connectionUri: string): Thenable<azdata.ListDatabasesResult> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
cancelConnection(connection: IConnectionProfile): Thenable<boolean> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
cancelEditorConnection(owner: IConnectableInput): Thenable<boolean> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
showDashboard(connection: ConnectionProfile): Promise<boolean> {
|
||||
return new Promise(() => true);
|
||||
}
|
||||
|
||||
closeDashboard(uri: string): void {
|
||||
}
|
||||
|
||||
changeDatabase(connectionUri: string, databaseName: string): Thenable<boolean> {
|
||||
return new Promise(() => true);
|
||||
}
|
||||
|
||||
editGroup(group: ConnectionProfileGroup): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
getProviderIdFromUri(ownerUri: string): string {
|
||||
return undefined;
|
||||
}
|
||||
hasRegisteredServers(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
getCapabilities(providerName: string): azdata.DataProtocolServerCapabilities {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
canChangeConnectionConfig(profile: ConnectionProfile, newGroupID: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
doChangeLanguageFlavor(uri: string, language: string, flavor: string): void {
|
||||
|
||||
}
|
||||
ensureDefaultLanguageFlavor(uri: string): void {
|
||||
|
||||
}
|
||||
|
||||
public getProviderNames(): string[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
connectIfNotConnected(connection: IConnectionProfile, purpose?: 'dashboard' | 'insights' | 'connection', saveConnection: boolean = false): Promise<string> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
rebuildIntelliSenseCache(uri: string): Thenable<void> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getTabColorForUri(uri: string): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
removeConnectionProfileCredentials(profile: IConnectionProfile): IConnectionProfile {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getActiveConnectionCredentials(profileId: string): { [name: string]: string } {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getServerInfo(profileId: string): azdata.ServerInfo {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionString(connectionId: string): Thenable<string> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
buildConnectionInfo(connectionString: string, provider?: string): Thenable<azdata.ConnectionInfo> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
providerRegistered(providerId: string): boolean {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionProfileById(profileId: string): IConnectionProfile {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getProviderProperties(providerName: string): ConnectionProviderProperties {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionIconId(connectionId: string): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getDefaultProviderId(): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnections(activeConnectionsOnly?: boolean): ConnectionProfile[] {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
|
||||
|
||||
export class TestConnectionProvider implements azdata.ConnectionProvider {
|
||||
public readonly providerId = mssqlProviderName;
|
||||
|
||||
connect(connectionUri: string, connectionInfo: azdata.ConnectionInfo): Thenable<boolean> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
disconnect(connectionUri: string): Thenable<boolean> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
cancelConnect(connectionUri: string): Thenable<boolean> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
listDatabases(connectionUri: string): Thenable<azdata.ListDatabasesResult> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
changeDatabase(connectionUri: string, newDatabase: string): Thenable<boolean> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getConnectionString(connectionUri: string): Thenable<string> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
rebuildIntelliSenseCache(connectionUri: string): Thenable<void> {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
registerOnConnectionComplete(handler: (connSummary: azdata.ConnectionInfoSummary) => any) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
registerOnIntelliSenseCacheComplete(handler: (connectionUri: string) => any) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
registerOnConnectionChanged(handler: (changedConnInfo: azdata.ChangedConnectionInfo) => any) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user