Capabilities Cache (#831)

* init

* finished compile erros

* fixed all merge conflicts

* fix dialog problems

* formatting

* fix opening dialog on first open

* fix various problems with connectiondialog

* formatting

* fix tests
This commit is contained in:
Anthony Dresser
2018-03-08 17:16:40 -08:00
committed by GitHub
parent 45b1ae1fb1
commit 8b2ea4f0a0
26 changed files with 302 additions and 414 deletions

View File

@@ -11,9 +11,11 @@ import { IConnectionProfile, IConnectionProfileStore } from 'sql/parts/connectio
import * as sqlops from 'sqlops';
import * as assert from 'assert';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
suite('SQL ConnectionProfileInfo tests', () => {
let msSQLCapabilities: sqlops.DataProtocolServerCapabilities;
let capabilitiesService: CapabilitiesTestService;
let connectionProfile: IConnectionProfile = {
serverName: 'new server',
@@ -121,10 +123,12 @@ suite('SQL ConnectionProfileInfo tests', () => {
features: undefined
};
capabilities.push(msSQLCapabilities);
capabilitiesService = new CapabilitiesTestService();
capabilitiesService.capabilities['MSSQL'] = msSQLCapabilities;
});
test('set properties should set the values correctly', () => {
let conn = new ConnectionProfile(msSQLCapabilities, undefined);
let conn = new ConnectionProfile(capabilitiesService, undefined);
assert.equal(conn.serverName, undefined);
conn.serverName = connectionProfile.serverName;
conn.databaseName = connectionProfile.databaseName;
@@ -145,7 +149,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
});
test('constructor should initialize the options given a valid model', () => {
let conn = new ConnectionProfile(msSQLCapabilities, connectionProfile);
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
assert.equal(conn.serverName, connectionProfile.serverName);
assert.equal(conn.databaseName, connectionProfile.databaseName);
@@ -158,7 +162,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
});
test('getOptionsKey should create a valid unique id', () => {
let conn = new ConnectionProfile(msSQLCapabilities, connectionProfile);
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);
@@ -166,7 +170,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
test('createFromStoredProfile should create connection profile from stored profile', () => {
let savedProfile = storedProfile;
let connectionProfile = ConnectionProfile.createFromStoredProfile(savedProfile, msSQLCapabilities);
let connectionProfile = ConnectionProfile.createFromStoredProfile(savedProfile, capabilitiesService);
assert.equal(savedProfile.groupId, connectionProfile.groupId);
assert.deepEqual(savedProfile.providerName, connectionProfile.providerName);
assert.deepEqual(savedProfile.savePassword, connectionProfile.savePassword);
@@ -175,7 +179,7 @@ suite('SQL ConnectionProfileInfo tests', () => {
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, msSQLCapabilities);
let connectionProfile = ConnectionProfile.createFromStoredProfile(savedProfile, capabilitiesService);
assert.equal(savedProfile.groupId, connectionProfile.groupId);
assert.deepEqual(savedProfile.providerName, connectionProfile.providerName);
assert.equal(savedProfile.savePassword, connectionProfile.savePassword);
@@ -184,20 +188,20 @@ suite('SQL ConnectionProfileInfo tests', () => {
});
test('withoutPassword should create a new instance without password', () => {
let conn = new ConnectionProfile(msSQLCapabilities, connectionProfile);
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(msSQLCapabilities, connectionProfile);
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(msSQLCapabilities, connectionProfile);
let conn = new ConnectionProfile(capabilitiesService, connectionProfile);
let newProfile = conn.cloneWithDatabase('new db');
assert.notEqual(newProfile.id, conn.id);
assert.equal(newProfile.databaseName, 'new db');

View File

@@ -72,8 +72,7 @@ let connection3Id: string;
suite('SQL ConnectionStatusManager tests', () => {
setup(() => {
capabilitiesService = new CapabilitiesTestService();
connectionProfileObject = new ConnectionProfile(capabilitiesService.getCapabilities().find(x => x.providerName === 'MSSQL')
, connectionProfile);
connectionProfileObject = new ConnectionProfile(capabilitiesService, connectionProfile);
connections = new ConnectionStatusManager(capabilitiesService);
connection1Id = Utils.generateUri(connectionProfile);
connection2Id = 'connection2Id';
@@ -94,7 +93,7 @@ suite('SQL ConnectionStatusManager tests', () => {
let id: string = connection1Id;
let expected = connectionProfileObject;
let actual = connections.findConnection(id);
assert.deepEqual(actual.connectionProfile, expected);
assert.equal(connectionProfileObject.matches(actual.connectionProfile), true);
});
test('getConnectionProfile should return undefined given invalid id', () => {
@@ -108,7 +107,7 @@ suite('SQL ConnectionStatusManager tests', () => {
let id: string = connection1Id;
let expected = connectionProfileObject;
let actual = connections.getConnectionProfile(id);
assert.deepEqual(actual, expected);
assert.equal(connectionProfileObject.matches(actual), true);
});
test('hasConnection should return false given invalid id', () => {

View File

@@ -20,6 +20,7 @@ import { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile
import { Emitter } from 'vs/base/common/event';
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import { CapabilitiesTestService } from '../../stubs/capabilitiesTestService';
suite('SQL ConnectionStore tests', () => {
let defaultNamedProfile: IConnectionProfile;
@@ -29,13 +30,11 @@ suite('SQL ConnectionStore tests', () => {
let connectionConfig: TypeMoq.Mock<ConnectionConfig>;
let workspaceConfigurationServiceMock: TypeMoq.Mock<WorkspaceConfigurationTestService>;
let storageServiceMock: TypeMoq.Mock<StorageTestService>;
let capabilitiesService: TypeMoq.Mock<CapabilitiesService>;
let capabilitiesService: CapabilitiesTestService;
let mementoArray: any = [];
let maxRecent = 5;
let msSQLCapabilities: sqlops.DataProtocolServerCapabilities;
let defaultNamedConnectionProfile: ConnectionProfile;
let onProviderRegistered = new Emitter<sqlops.DataProtocolServerCapabilities>();
setup(() => {
defaultNamedProfile = Object.assign({}, {
@@ -96,8 +95,8 @@ suite('SQL ConnectionStore tests', () => {
}
};
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesService, TypeMoq.MockBehavior.Loose, extensionManagementServiceMock, {});
let capabilities: sqlops.DataProtocolServerCapabilities[] = [];
capabilitiesService = new CapabilitiesTestService();
let capabilities: { [id: string]: sqlops.DataProtocolServerCapabilities } = {};
let connectionProvider: sqlops.ConnectionProviderOptions = {
options: [
{
@@ -170,10 +169,8 @@ suite('SQL ConnectionStore tests', () => {
adminServicesProvider: undefined,
features: undefined
};
capabilities.push(msSQLCapabilities);
capabilitiesService.setup(x => x.getCapabilities()).returns(() => capabilities);
capabilitiesService.setup(x => x.onProviderRegisteredEvent).returns(() => onProviderRegistered.event);
connectionConfig.setup(x => x.getCapabilities('MSSQL')).returns(() => msSQLCapabilities);
capabilities['MSSQL'] = msSQLCapabilities;
capabilitiesService.capabilities['MSSQL'] = msSQLCapabilities;
let groups: IConnectionProfileGroup[] = [
{
id: 'root',
@@ -192,7 +189,7 @@ suite('SQL ConnectionStore tests', () => {
];
connectionConfig.setup(x => x.getAllGroups()).returns(() => groups);
defaultNamedConnectionProfile = new ConnectionProfile(msSQLCapabilities, defaultNamedProfile);
defaultNamedConnectionProfile = new ConnectionProfile(capabilitiesService, defaultNamedProfile);
});
test('addActiveConnection should limit recent connection saves to the MaxRecentConnections amount', (done) => {
@@ -206,11 +203,11 @@ suite('SQL ConnectionStore tests', () => {
// When saving 4 connections
// Expect all of them to be saved even if size is limited to 3
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
let promise = Promise.resolve();
for (let i = 0; i < numCreds; i++) {
let cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
let connectionProfile = new ConnectionProfile(msSQLCapabilities, cred);
let connectionProfile = new ConnectionProfile(capabilitiesService, cred);
promise = promise.then(() => {
return connectionStore.addActiveConnection(connectionProfile);
}).then(() => {
@@ -243,12 +240,12 @@ suite('SQL ConnectionStore tests', () => {
// Given we save the same connection twice
// Then expect the only 1 instance of that connection to be listed in the MRU
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
connectionStore.clearActiveConnections();
connectionStore.clearRecentlyUsed();
let promise = Promise.resolve();
let cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + 1 });
let connectionProfile = new ConnectionProfile(msSQLCapabilities, cred);
let connectionProfile = new ConnectionProfile(capabilitiesService, cred);
promise = promise.then(() => {
return connectionStore.addActiveConnection(defaultNamedConnectionProfile);
}).then(() => {
@@ -278,7 +275,7 @@ suite('SQL ConnectionStore tests', () => {
// Given we save 1 connection with password and multiple other connections without
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
connectionStore.clearActiveConnections();
connectionStore.clearRecentlyUsed();
let integratedCred = Object.assign({}, defaultNamedProfile, {
@@ -291,7 +288,7 @@ suite('SQL ConnectionStore tests', () => {
serverName: defaultNamedProfile.serverName + 'NoPwd',
password: ''
});
let connectionProfile = new ConnectionProfile(msSQLCapabilities, defaultNamedProfile);
let connectionProfile = new ConnectionProfile(capabilitiesService, defaultNamedProfile);
let expectedCredCount = 0;
let promise = Promise.resolve();
@@ -309,7 +306,7 @@ suite('SQL ConnectionStore tests', () => {
}).then(() => {
// When add integrated auth connection
expectedCredCount++;
let integratedCredConnectionProfile = new ConnectionProfile(msSQLCapabilities, integratedCred);
let integratedCredConnectionProfile = new ConnectionProfile(capabilitiesService, integratedCred);
return connectionStore.addActiveConnection(integratedCredConnectionProfile);
}).then(() => {
let current = connectionStore.getRecentlyUsedConnections();
@@ -319,7 +316,7 @@ suite('SQL ConnectionStore tests', () => {
}).then(() => {
// When add connection without password
expectedCredCount++;
let noPwdCredConnectionProfile = new ConnectionProfile(msSQLCapabilities, noPwdCred);
let noPwdCredConnectionProfile = new ConnectionProfile(capabilitiesService, noPwdCred);
return connectionStore.addActiveConnection(noPwdCredConnectionProfile);
}).then(() => {
let current = connectionStore.getRecentlyUsedConnections();
@@ -333,7 +330,7 @@ suite('SQL ConnectionStore tests', () => {
connectionConfig.setup(x => x.getConnections(TypeMoq.It.isAny())).returns(() => []);
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
// When we clear the connections list and get the list of available connection items
connectionStore.clearActiveConnections();
@@ -351,7 +348,7 @@ suite('SQL ConnectionStore tests', () => {
test('isPasswordRequired should return true for MSSQL SqlLogin', () => {
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
let expected: boolean = true;
let actual = connectionStore.isPasswordRequired(defaultNamedProfile);
@@ -361,8 +358,8 @@ suite('SQL ConnectionStore tests', () => {
test('isPasswordRequired should return true for MSSQL SqlLogin for connection profile object', () => {
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
let connectionProfile = new ConnectionProfile(msSQLCapabilities, defaultNamedProfile);
credentialStore.object, capabilitiesService, connectionConfig.object);
let connectionProfile = new ConnectionProfile(capabilitiesService, defaultNamedProfile);
let expected: boolean = true;
let actual = connectionStore.isPasswordRequired(connectionProfile);
@@ -387,10 +384,11 @@ suite('SQL ConnectionStore tests', () => {
adminServicesProvider: undefined,
features: undefined
};
connectionConfig.setup(x => x.getCapabilities(providerName)).returns(() => providerCapabilities);
capabilitiesService.capabilities[providerName] = providerCapabilities;
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
let connectionProfile: IConnectionProfile = Object.assign({}, defaultNamedProfile, { providerName: providerName });
let expected: boolean = false;
let actual = connectionStore.isPasswordRequired(connectionProfile);
@@ -407,7 +405,7 @@ suite('SQL ConnectionStore tests', () => {
credentialStore.setup(x => x.saveCredential(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(true));
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
connectionStore.saveProfile(connectionProfile).then(profile => {
// add connection should be called with a profile without password
@@ -424,7 +422,7 @@ suite('SQL ConnectionStore tests', () => {
test('addConnectionToMemento should not add duplicate items', () => {
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
let mementoKey = 'RECENT_CONNECTIONS2';
connectionStore.clearFromMemento(mementoKey);
let connectionProfile: IConnectionProfile = Object.assign({}, defaultNamedProfile);
@@ -466,7 +464,7 @@ suite('SQL ConnectionStore tests', () => {
test('getGroupFromId returns undefined when there is no group with the given ID', () => {
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
let group = connectionStore.getGroupFromId('invalidId');
assert.equal(group, undefined, 'Returned group was not undefined when there was no group with the given ID');
});
@@ -482,7 +480,7 @@ suite('SQL ConnectionStore tests', () => {
let newConnectionConfig = TypeMoq.Mock.ofType(ConnectionConfig);
newConnectionConfig.setup(x => x.getAllGroups()).returns(() => groups);
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, newConnectionConfig.object);
credentialStore.object, capabilitiesService, newConnectionConfig.object);
// If I look up the parent group using its ID, then I get back the correct group
let actualGroup = connectionStore.getGroupFromId(parentGroupId);
@@ -495,14 +493,14 @@ suite('SQL ConnectionStore tests', () => {
test('getProfileWithoutPassword can return the profile without credentials in the password property or options dictionary', () => {
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
credentialStore.object, capabilitiesService.object, connectionConfig.object);
credentialStore.object, capabilitiesService, connectionConfig.object);
let profile = Object.assign({}, defaultNamedProfile);
profile.options['password'] = profile.password;
profile.id = 'testId';
let expectedProfile = Object.assign({}, profile);
expectedProfile.password = '';
expectedProfile.options['password'] = '';
expectedProfile = ConnectionProfile.convertToConnectionProfile(msSQLCapabilities, expectedProfile).toIConnectionProfile();
expectedProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, expectedProfile).toIConnectionProfile();
let profileWithoutCredentials = connectionStore.getProfileWithoutPassword(profile);
assert.deepEqual(profileWithoutCredentials.toIConnectionProfile(), expectedProfile);
});

View File

@@ -33,6 +33,7 @@ import Severity from 'vs/base/common/severity';
import { ObjectExplorerActionsContext, ManageConnectionAction } from 'sql/parts/registeredServer/viewlet/objectExplorerActions';
import { IConnectionResult, IConnectionParams } from 'sql/parts/connection/common/connectionManagement';
import { TreeSelectionHandler } from 'sql/parts/registeredServer/viewlet/treeSelectionHandler';
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
suite('SQL Connection Tree Action tests', () => {
let errorMessageService: TypeMoq.Mock<ErrorMessageServiceStub>;
@@ -42,6 +43,7 @@ suite('SQL Connection Tree Action tests', () => {
errorCode: undefined,
callStack: undefined
};
let capabilitiesService = new CapabilitiesTestService();
setup(() => {
errorMessageService = TypeMoq.Mock.ofType(ErrorMessageServiceStub, TypeMoq.MockBehavior.Loose);
let nothing: void;
@@ -91,7 +93,7 @@ suite('SQL Connection Tree Action tests', () => {
let manageConnectionAction: ManageConnectionAction = new ManageConnectionAction(ManageConnectionAction.ID,
ManageConnectionAction.LABEL, connectionManagementService.object, instantiationService.object, objectExplorerService.object);
let connection: ConnectionProfile = new ConnectionProfile(undefined, {
let connection: ConnectionProfile = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -126,7 +128,7 @@ suite('SQL Connection Tree Action tests', () => {
let manageConnectionAction: ManageConnectionAction = new ManageConnectionAction(ManageConnectionAction.ID,
ManageConnectionAction.LABEL, connectionManagementService.object, instantiationService.object, objectExplorerService.object);
let connection: ConnectionProfile = new ConnectionProfile(undefined, {
let connection: ConnectionProfile = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -158,7 +160,7 @@ suite('SQL Connection Tree Action tests', () => {
let objectExplorerService = createObjectExplorerService(connectionManagementService.object);
let changeConnectionAction: DisconnectConnectionAction = new DisconnectConnectionAction(DisconnectConnectionAction.ID, DisconnectConnectionAction.LABEL, connectionManagementService.object, objectExplorerService.object, errorMessageService.object);
let connection: ConnectionProfile = new ConnectionProfile(undefined, {
let connection: ConnectionProfile = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -265,7 +267,7 @@ suite('SQL Connection Tree Action tests', () => {
test('DeleteConnectionAction - test delete connection', (done) => {
let connectionManagementService = createConnectionManagementService(true);
let connection: ConnectionProfile = new ConnectionProfile(undefined, {
let connection: ConnectionProfile = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -311,7 +313,7 @@ suite('SQL Connection Tree Action tests', () => {
let isConnectedReturnValue: boolean = false;
let connectionManagementService = createConnectionManagementService(isConnectedReturnValue);
let connection: ConnectionProfile = new ConnectionProfile(undefined, {
let connection: ConnectionProfile = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -348,7 +350,9 @@ suite('SQL Connection Tree Action tests', () => {
features: undefined
};
var connection = new ConnectionProfile(sqlProvider, {
capabilitiesService.capabilities['MSSQL'] = sqlProvider;
var connection = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -437,7 +441,9 @@ suite('SQL Connection Tree Action tests', () => {
features: undefined
};
var connection = new ConnectionProfile(sqlProvider, {
capabilitiesService.capabilities['MSSQL'] = sqlProvider;
var connection = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',

View File

@@ -18,7 +18,9 @@ import * as TypeMoq from 'typemoq';
import * as assert from 'assert';
import { ServerTreeView } from 'sql/parts/registeredServer/viewlet/serverTreeView';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import Event from 'vs/base/common/event';
import Event, { Emitter } from 'vs/base/common/event';
import { CapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
suite('SQL Object Explorer Service tests', () => {
var sqlOEProvider: TypeMoq.Mock<ObjectExplorerProviderTestService>;
@@ -122,6 +124,7 @@ suite('SQL Object Explorer Service tests', () => {
sqlOEProvider = TypeMoq.Mock.ofType(ObjectExplorerProviderTestService, TypeMoq.MockBehavior.Loose);
sqlOEProvider.callBase = true;
let onCapabilitiesRegistered = new Emitter<string>();
let sqlProvider = {
protocolVersion: '1',
@@ -206,7 +209,10 @@ suite('SQL Object Explorer Service tests', () => {
features: undefined
};
connection = new ConnectionProfile(sqlProvider, {
let capabilitiesService = new CapabilitiesTestService();
capabilitiesService.capabilities['MSSQL'] = sqlProvider;
connection = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName',
@@ -224,7 +230,7 @@ suite('SQL Object Explorer Service tests', () => {
});
conProfGroup = new ConnectionProfileGroup('testGroup', undefined, 'testGroup', undefined, undefined);
connectionToFail = new ConnectionProfile(sqlProvider, {
connectionToFail = new ConnectionProfile(capabilitiesService, {
savePassword: false,
groupFullName: 'testGroup',
serverName: 'testServerName2',
@@ -251,7 +257,13 @@ suite('SQL Object Explorer Service tests', () => {
connectionManagementService.setup(x => x.getCapabilities('MSSQL')).returns(() => undefined);
objectExplorerService = new ObjectExplorerService(connectionManagementService.object, undefined);
let extensionManagementServiceMock = {
getInstalled: () => {
return Promise.resolve([]);
}
};
objectExplorerService = new ObjectExplorerService(connectionManagementService.object, undefined, capabilitiesService);
objectExplorerService.registerProvider('MSSQL', sqlOEProvider.object);
sqlOEProvider.setup(x => x.createNewSession(TypeMoq.It.is<sqlops.ConnectionInfo>(x => x.options['serverName'] === connection.serverName))).returns(() => new Promise<any>((resolve) => {
resolve(response);

View File

@@ -11,9 +11,12 @@ import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
import * as sqlops from 'sqlops';
import * as assert from 'assert';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
suite('SQL ProviderConnectionInfo tests', () => {
let msSQLCapabilities: sqlops.DataProtocolServerCapabilities;
let capabilitiesService: CapabilitiesTestService;
let connectionProfile: IConnectionProfile = {
serverName: 'new server',
@@ -119,6 +122,8 @@ suite('SQL ProviderConnectionInfo tests', () => {
features: undefined
};
capabilities.push(msSQLCapabilities);
capabilitiesService = new CapabilitiesTestService();
capabilitiesService.capabilities['MSSQL'] = msSQLCapabilities;
});
test('constructor should accept undefined parameters', () => {
@@ -127,7 +132,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
});
test('set properties should set the values correctly', () => {
let conn = new ProviderConnectionInfo(msSQLCapabilities, undefined);
let conn = new ProviderConnectionInfo(capabilitiesService, 'MSSQL');
assert.equal(conn.serverName, undefined);
conn.serverName = connectionProfile.serverName;
conn.databaseName = connectionProfile.databaseName;
@@ -142,7 +147,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
});
test('set properties should store the values in the options', () => {
let conn = new ProviderConnectionInfo(msSQLCapabilities, undefined);
let conn = new ProviderConnectionInfo(capabilitiesService, 'MSSQL');
assert.equal(conn.serverName, undefined);
conn.serverName = connectionProfile.serverName;
conn.databaseName = connectionProfile.databaseName;
@@ -157,7 +162,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
});
test('constructor should initialize the options given a valid model', () => {
let conn = new ProviderConnectionInfo(msSQLCapabilities, connectionProfile);
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
assert.equal(conn.serverName, connectionProfile.serverName);
assert.equal(conn.databaseName, connectionProfile.databaseName);
@@ -167,7 +172,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
});
test('clone should create a new instance that equals the old one', () => {
let conn = new ProviderConnectionInfo(msSQLCapabilities, connectionProfile);
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
let conn2 = conn.clone();
assert.equal(conn.serverName, conn2.serverName);
@@ -178,7 +183,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
});
test('Changing the cloned object should not change the original one', () => {
let conn = new ProviderConnectionInfo(msSQLCapabilities, connectionProfile);
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
let conn2 = conn.clone();
conn2.serverName = conn.serverName + '1';
@@ -189,7 +194,7 @@ suite('SQL ProviderConnectionInfo tests', () => {
let options = {};
options['encrypt'] = 'test value';
let conn2 = Object.assign({}, connectionProfile, { options: options });
let conn = new ProviderConnectionInfo(msSQLCapabilities, conn2);
let conn = new ProviderConnectionInfo(capabilitiesService, conn2);
assert.equal(conn.serverName, conn2.serverName);
assert.equal(conn.databaseName, conn2.databaseName);
@@ -200,21 +205,21 @@ suite('SQL ProviderConnectionInfo tests', () => {
});
test('getOptionsKey should create a valid unique id', () => {
let conn = new ProviderConnectionInfo(msSQLCapabilities, connectionProfile);
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(msSQLCapabilities, connectionProfile);
let conn2 = new ProviderConnectionInfo(msSQLCapabilities, Object.assign({}, connectionProfile, { serverName: connectionProfile.serverName + '1' }));
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(msSQLCapabilities, connectionProfile);
let conn = new ProviderConnectionInfo(capabilitiesService, connectionProfile);
let titleParts = conn.titleParts;
assert.equal(titleParts.length, 4);
assert.equal(titleParts[0], connectionProfile.serverName);

View File

@@ -6,11 +6,11 @@
'use strict';
import * as sqlops from 'sqlops';
import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import Event from 'vs/base/common/event';
import { Action } from 'vs/base/common/actions';
import { ICapabilitiesService, clientCapabilities } from 'sql/services/capabilities/capabilitiesService';
import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHostTypes';
import Event, { Emitter } from 'vs/base/common/event';
import { Action } from 'vs/base/common/actions';
export class CapabilitiesTestService implements ICapabilitiesService {
@@ -18,8 +18,7 @@ export class CapabilitiesTestService implements ICapabilitiesService {
private _providers: sqlops.CapabilitiesProvider[] = [];
private _capabilities: sqlops.DataProtocolServerCapabilities[] = [];
public capabilities: { [id: string]: sqlops.DataProtocolServerCapabilities } = {};
constructor() {
@@ -95,15 +94,19 @@ export class CapabilitiesTestService implements ICapabilitiesService {
adminServicesProvider: undefined,
features: undefined
};
this._capabilities.push(msSQLCapabilities);
this.capabilities['MSSQL'] = msSQLCapabilities;
}
/**
* Retrieve a list of registered server capabilities
*/
public getCapabilities(): sqlops.DataProtocolServerCapabilities[] {
return this._capabilities;
public getCapabilities(provider: string): sqlops.DataProtocolServerCapabilities {
return this.capabilities[provider];
}
public get providers(): string[] {
return Object.keys(this.capabilities);
}
/**
@@ -125,5 +128,8 @@ export class CapabilitiesTestService implements ICapabilitiesService {
public onCapabilitiesReady(): Promise<void> {
return Promise.resolve(null);
}
private _onCapabilitiesRegistered = new Emitter<string>();
public readonly onCapabilitiesRegistered = this._onCapabilitiesRegistered.event;
}