mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 11:01:37 -05:00
Bring back Connection Config tests (#2795)
This commit is contained in:
@@ -12,25 +12,27 @@ import { IConnectionProfile, IConnectionProfileStore } from 'sql/parts/connectio
|
||||
import { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { WorkspaceConfigurationTestService } from 'sqltest/stubs/workspaceConfigurationTestService';
|
||||
import { IConfigurationValue as TConfigurationValue, ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
|
||||
import { IConfigurationValue, ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
|
||||
import * as Constants from 'sql/parts/connection/common/constants';
|
||||
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import * as assert from 'assert';
|
||||
import { CapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
||||
import { ProviderFeatures, ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
||||
import * as sqlops from 'sqlops';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { StorageService, InMemoryLocalStorage } from 'vs/platform/storage/common/storageService';
|
||||
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
|
||||
|
||||
suite('SQL ConnectionConfig tests', () => {
|
||||
/*
|
||||
let capabilitiesService: TypeMoq.Mock<CapabilitiesService>;
|
||||
let capabilitiesService: TypeMoq.Mock<ICapabilitiesService>;
|
||||
let workspaceConfigurationServiceMock: TypeMoq.Mock<WorkspaceConfigurationTestService>;
|
||||
let configEditingServiceMock: TypeMoq.Mock<ConfigurationEditingService>;
|
||||
let msSQLCapabilities: sqlops.DataProtocolServerCapabilities;
|
||||
let capabilities: sqlops.DataProtocolServerCapabilities[];
|
||||
let onProviderRegistered = new Emitter<sqlops.DataProtocolServerCapabilities>();
|
||||
let msSQLCapabilities: ProviderFeatures;
|
||||
let capabilities: ProviderFeatures[];
|
||||
let onCapabilitiesRegistered = new Emitter<ProviderFeatures>();
|
||||
|
||||
let configValueToConcat: TConfigurationValue<IConnectionProfileGroup[]> = {
|
||||
let configValueToConcat = {
|
||||
workspace: [{
|
||||
name: 'g1',
|
||||
id: 'g1',
|
||||
@@ -83,10 +85,10 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
],
|
||||
value: [],
|
||||
default: [],
|
||||
folder: []
|
||||
workspaceFolder: []
|
||||
};
|
||||
|
||||
let configValueToMerge: TConfigurationValue<IConnectionProfileGroup[]> = {
|
||||
let configValueToMerge = {
|
||||
workspace: [
|
||||
{
|
||||
name: 'g1',
|
||||
@@ -134,10 +136,10 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
}],
|
||||
value: [],
|
||||
default: [],
|
||||
folder: []
|
||||
workspaceFolder: []
|
||||
};
|
||||
|
||||
let connections: TConfigurationValue<IConnectionProfileStore[]> = {
|
||||
let connections = {
|
||||
workspace: [{
|
||||
options: {
|
||||
serverName: 'server1',
|
||||
@@ -182,10 +184,10 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
],
|
||||
value: [],
|
||||
default: [],
|
||||
folder: []
|
||||
workspaceFolder: []
|
||||
};
|
||||
setup(() => {
|
||||
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesService);
|
||||
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesTestService);
|
||||
capabilities = [];
|
||||
let connectionProvider: sqlops.ConnectionProviderOptions = {
|
||||
options: [
|
||||
@@ -198,8 +200,8 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: 0,
|
||||
valueType: 0
|
||||
specialValueType: ConnectionOptionSpecialType.serverName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'databaseName',
|
||||
@@ -210,8 +212,8 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: 1,
|
||||
valueType: 0
|
||||
specialValueType: ConnectionOptionSpecialType.databaseName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'userName',
|
||||
@@ -222,8 +224,8 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: 3,
|
||||
valueType: 0
|
||||
specialValueType: ConnectionOptionSpecialType.userName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'authenticationType',
|
||||
@@ -234,8 +236,8 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: 2,
|
||||
valueType: 0
|
||||
specialValueType: ConnectionOptionSpecialType.authType,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'password',
|
||||
@@ -246,27 +248,26 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: 4,
|
||||
valueType: 0
|
||||
specialValueType: ConnectionOptionSpecialType.password,
|
||||
valueType: ServiceOptionType.string
|
||||
}
|
||||
]
|
||||
};
|
||||
msSQLCapabilities = {
|
||||
protocolVersion: '1',
|
||||
providerName: 'MSSQL',
|
||||
providerDisplayName: 'MSSQL',
|
||||
connectionProvider: connectionProvider,
|
||||
adminServicesProvider: undefined,
|
||||
features: undefined
|
||||
connection: {
|
||||
providerId: 'MSSQL',
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: connectionProvider.options
|
||||
}
|
||||
};
|
||||
capabilities.push(msSQLCapabilities);
|
||||
|
||||
capabilitiesService.setup(x => x.getCapabilities()).returns(() => capabilities);
|
||||
capabilitiesService.setup(x => x.onProviderRegisteredEvent).returns(() => onProviderRegistered.event);
|
||||
capabilitiesService.setup(x => x.getCapabilities('MSSQL')).returns(() => msSQLCapabilities);
|
||||
(capabilitiesService.object as any).onCapabilitiesRegistered = onCapabilitiesRegistered.event;
|
||||
|
||||
workspaceConfigurationServiceMock = TypeMoq.Mock.ofType(WorkspaceConfigurationTestService);
|
||||
workspaceConfigurationServiceMock.setup(x => x.reloadConfiguration())
|
||||
.returns(() => TPromise.as<{}>({}));
|
||||
.returns(() => TPromise.as(null));
|
||||
|
||||
configEditingServiceMock = TypeMoq.Mock.ofType(ConfigurationEditingService);
|
||||
let nothing: void;
|
||||
@@ -305,7 +306,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
}
|
||||
|
||||
test('allGroups should return groups from user and workspace settings', () => {
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfile[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
@@ -355,7 +356,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
description: 'g1-2'
|
||||
}];
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToMerge);
|
||||
|
||||
@@ -382,19 +383,20 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
id: undefined,
|
||||
connectionName: undefined
|
||||
};
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length + 1;
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||
config.addConnection(connectionProfile).then(savedConnectionProfile => {
|
||||
@@ -403,8 +405,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
assert.notEqual(savedConnectionProfile.id, undefined);
|
||||
done();
|
||||
}).catch(error => {
|
||||
assert.fail();
|
||||
done();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -424,19 +425,20 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
id: undefined,
|
||||
connectionName: undefined
|
||||
};
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length;
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = profileFromConfig.options['databaseName'];
|
||||
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||
@@ -446,8 +448,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
assert.equal(savedConnectionProfile.id, profileFromConfig.id);
|
||||
done();
|
||||
}).catch(error => {
|
||||
assert.fail();
|
||||
done();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -466,21 +467,22 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
id: undefined,
|
||||
connectionName: undefined
|
||||
};
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length + 1;
|
||||
let expectedNumberOfGroups = configValueToConcat.user.length + 1;
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||
config.addConnection(connectionProfile).then(success => {
|
||||
configEditingServiceMock.verify(y => y.writeConfiguration(ConfigurationTarget.USER,
|
||||
@@ -489,15 +491,14 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileGroup[]).length === expectedNumberOfGroups)), TypeMoq.Times.once());
|
||||
done();
|
||||
}).catch(error => {
|
||||
assert.fail();
|
||||
done();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
test('getConnections should return connections from user and workspace settings given getWorkspaceConnections set to true', () => {
|
||||
let getWorkspaceConnections: boolean = true;
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
@@ -509,7 +510,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
test('getConnections should return connections from user settings given getWorkspaceConnections set to false', () => {
|
||||
let getWorkspaceConnections: boolean = false;
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
@@ -520,7 +521,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
|
||||
test('getConnections should return connections with a valid id', () => {
|
||||
let getWorkspaceConnections: boolean = false;
|
||||
let connectionsWithNoId: TConfigurationValue<IConnectionProfileStore[]> = {
|
||||
let connectionsWithNoId = {
|
||||
user: connections.user.map(c => {
|
||||
c.id = undefined;
|
||||
return c;
|
||||
@@ -531,9 +532,9 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
return c;
|
||||
}),
|
||||
value: connections.value,
|
||||
folder: []
|
||||
workspaceFolder: []
|
||||
};
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connectionsWithNoId);
|
||||
|
||||
@@ -555,7 +556,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
|
||||
test('getConnections update the capabilities in each profile when the provider capabilities is registered', () => {
|
||||
let oldOptionName: string = 'oldOptionName';
|
||||
let optionsMetadataFromConfig = capabilities[0].connectionProvider.options.concat({
|
||||
let optionsMetadataFromConfig = capabilities[0].connection.connectionOptions.concat({
|
||||
name: oldOptionName,
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
@@ -564,21 +565,17 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: 0,
|
||||
valueType: 0
|
||||
specialValueType: undefined,
|
||||
valueType: ServiceOptionType.string
|
||||
});
|
||||
|
||||
let capabilitiesFromConfig: sqlops.DataProtocolServerCapabilities[] = [];
|
||||
let connectionProvider: sqlops.ConnectionProviderOptions = {
|
||||
options: optionsMetadataFromConfig
|
||||
};
|
||||
let msSQLCapabilities2 = {
|
||||
protocolVersion: '1',
|
||||
providerName: 'MSSQL',
|
||||
providerDisplayName: 'MSSQL',
|
||||
connectionProvider: connectionProvider,
|
||||
adminServicesProvider: undefined,
|
||||
features: undefined
|
||||
let capabilitiesFromConfig: ProviderFeatures[] = [];
|
||||
let msSQLCapabilities2: ProviderFeatures = {
|
||||
connection: {
|
||||
providerId: 'MSSQL',
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: optionsMetadataFromConfig
|
||||
}
|
||||
};
|
||||
capabilitiesFromConfig.push(msSQLCapabilities2);
|
||||
let connectionUsingOldMetadata = connections.user.map(c => {
|
||||
@@ -586,21 +583,21 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
return c;
|
||||
});
|
||||
let configValue = Object.assign({}, connections, { user: connectionUsingOldMetadata });
|
||||
let capabilitiesService2: TypeMoq.Mock<CapabilitiesService> = TypeMoq.Mock.ofType(CapabilitiesService);
|
||||
capabilitiesService2.setup(x => x.getCapabilities()).returns(() => []);
|
||||
capabilitiesService2.setup(x => x.onProviderRegisteredEvent).returns(() => onProviderRegistered.event);
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
let capabilitiesService2: TypeMoq.Mock<ICapabilitiesService> = TypeMoq.Mock.ofType(CapabilitiesTestService);
|
||||
capabilitiesService2.setup(x => x.getCapabilities('MSSQL')).returns(() => msSQLCapabilities2);
|
||||
(capabilitiesService2.object as any).onCapabilitiesRegistered = onCapabilitiesRegistered.event;
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => configValue);
|
||||
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService2.object, capabilitiesFromConfig);
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService2.object);
|
||||
let allConnections = config.getConnections(false);
|
||||
allConnections.forEach(element => {
|
||||
assert.notEqual(element.serverName, undefined);
|
||||
assert.notEqual(element.getOptionsKey().indexOf('oldOptionValue|'), -1);
|
||||
});
|
||||
|
||||
onProviderRegistered.fire(msSQLCapabilities);
|
||||
onCapabilitiesRegistered.fire(msSQLCapabilities);
|
||||
allConnections.forEach(element => {
|
||||
assert.notEqual(element.serverName, undefined);
|
||||
assert.equal(element.getOptionsKey().indexOf('oldOptionValue|'), -1);
|
||||
@@ -608,7 +605,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
});
|
||||
|
||||
test('saveGroup should save the new groups to tree and return the id of the last group name', () => {
|
||||
let config = new ConnectionConfig(undefined, undefined, undefined, undefined);
|
||||
let config = new ConnectionConfig(undefined, undefined, undefined);
|
||||
let groups: IConnectionProfileGroup[] = configValueToConcat.user;
|
||||
let expectedLength = configValueToConcat.user.length + 2;
|
||||
let newGroups: string = 'ROOT/g1/g1-1';
|
||||
@@ -622,7 +619,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
});
|
||||
|
||||
test('saveGroup should only add the groups that are not in the tree', () => {
|
||||
let config = new ConnectionConfig(undefined, undefined, undefined, undefined);
|
||||
let config = new ConnectionConfig(undefined, undefined, undefined);
|
||||
let groups: IConnectionProfileGroup[] = configValueToConcat.user;
|
||||
let expectedLength = configValueToConcat.user.length + 1;
|
||||
let newGroups: string = 'ROOT/g2/g2-5';
|
||||
@@ -636,7 +633,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
});
|
||||
|
||||
test('saveGroup should not add any new group if tree already has all the groups in the full path', () => {
|
||||
let config = new ConnectionConfig(undefined, undefined, undefined, undefined);
|
||||
let config = new ConnectionConfig(undefined, undefined, undefined);
|
||||
let groups: IConnectionProfileGroup[] = configValueToConcat.user;
|
||||
let expectedLength = configValueToConcat.user.length;
|
||||
let newGroups: string = 'ROOT/g2/g2-1';
|
||||
@@ -664,15 +661,16 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
id: undefined,
|
||||
connectionName: undefined
|
||||
};
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length - 1;
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||
@@ -681,8 +679,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileStore[]).length === expectedNumberOfConnections)), TypeMoq.Times.once());
|
||||
done();
|
||||
}).catch(error => {
|
||||
assert.fail();
|
||||
done();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -701,9 +698,10 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
id: undefined,
|
||||
connectionName: undefined
|
||||
};
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
|
||||
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
|
||||
@@ -713,11 +711,11 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length - 1;
|
||||
let expectedNumberOfGroups = configValueToConcat.user.length - 2;
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
@@ -730,8 +728,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileGroup[]).length === expectedNumberOfGroups)), TypeMoq.Times.once());
|
||||
done();
|
||||
}).catch(error => {
|
||||
assert.fail();
|
||||
done();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -750,23 +747,23 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
id: undefined,
|
||||
connectionName: undefined
|
||||
};
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length;
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||
config.deleteConnection(connectionProfile).then(() => {
|
||||
configEditingServiceMock.verify(y => y.writeConfiguration(ConfigurationTarget.USER,
|
||||
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileStore[]).length === expectedNumberOfConnections)), TypeMoq.Times.once());
|
||||
done();
|
||||
}).catch(error => {
|
||||
assert.fail();
|
||||
done();
|
||||
done(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -780,7 +777,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
configEditingServiceMock.setup(x => x.writeConfiguration(ConfigurationTarget.USER, TypeMoq.It.isAny())).callback((x: any, val: any) => {
|
||||
calledValue = val.value as IConnectionProfileStore[];
|
||||
}).returns(() => TPromise.as<void>(nothing));
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
@@ -808,7 +805,7 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
configEditingServiceMock.setup(x => x.writeConfiguration(ConfigurationTarget.USER, TypeMoq.It.isAny())).callback((x: any, val: any) => {
|
||||
calledValue = val.value as IConnectionProfileStore[];
|
||||
}).returns(() => TPromise.as<void>(nothing));
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
|
||||
@@ -842,15 +839,16 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: 'test'
|
||||
id: 'test',
|
||||
connectionName: undefined
|
||||
};
|
||||
|
||||
let expectedNumberOfConnections = connections.user.length;
|
||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let newId = 'newid';
|
||||
let calledValue: any;
|
||||
let nothing: void;
|
||||
@@ -927,10 +925,33 @@ suite('SQL ConnectionConfig tests', () => {
|
||||
}
|
||||
done();
|
||||
});
|
||||
*/
|
||||
|
||||
test('fixConnectionIds should replace duplicate ids with new ones', (done) => {
|
||||
done();
|
||||
test('addConnection should not move the connection when editing', async () => {
|
||||
// Set up the connection config
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionsArrayName))
|
||||
.returns(() => connections);
|
||||
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||
Constants.connectionGroupsArrayName))
|
||||
.returns(() => configValueToConcat);
|
||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||
|
||||
// Clone a connection and modify an option
|
||||
const connectionIndex = 1;
|
||||
const optionKey = 'testOption';
|
||||
const optionValue = 'testValue';
|
||||
let allConnections = config.getConnections(false);
|
||||
let oldLength = allConnections.length;
|
||||
let connectionToEdit = allConnections[connectionIndex].clone();
|
||||
connectionToEdit.options[optionKey] = optionValue;
|
||||
await config.addConnection(connectionToEdit);
|
||||
|
||||
// Get the connection and verify that it is in the same place and has been updated
|
||||
let newConnections = config.getConnections(false);
|
||||
assert.equal(newConnections.length, oldLength);
|
||||
let editedConnection = newConnections[connectionIndex];
|
||||
assert.equal(editedConnection.getOptionsKey(), connectionToEdit.getOptionsKey());
|
||||
assert.equal(editedConnection.options[optionKey], optionValue);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user