mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -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 { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile';
|
||||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||||
import { WorkspaceConfigurationTestService } from 'sqltest/stubs/workspaceConfigurationTestService';
|
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 * as Constants from 'sql/parts/connection/common/constants';
|
||||||
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
|
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/parts/connection/common/connectionProfileGroup';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import * as assert from 'assert';
|
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 * as sqlops from 'sqlops';
|
||||||
import { Emitter } from 'vs/base/common/event';
|
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', () => {
|
suite('SQL ConnectionConfig tests', () => {
|
||||||
/*
|
let capabilitiesService: TypeMoq.Mock<ICapabilitiesService>;
|
||||||
let capabilitiesService: TypeMoq.Mock<CapabilitiesService>;
|
|
||||||
let workspaceConfigurationServiceMock: TypeMoq.Mock<WorkspaceConfigurationTestService>;
|
let workspaceConfigurationServiceMock: TypeMoq.Mock<WorkspaceConfigurationTestService>;
|
||||||
let configEditingServiceMock: TypeMoq.Mock<ConfigurationEditingService>;
|
let configEditingServiceMock: TypeMoq.Mock<ConfigurationEditingService>;
|
||||||
let msSQLCapabilities: sqlops.DataProtocolServerCapabilities;
|
let msSQLCapabilities: ProviderFeatures;
|
||||||
let capabilities: sqlops.DataProtocolServerCapabilities[];
|
let capabilities: ProviderFeatures[];
|
||||||
let onProviderRegistered = new Emitter<sqlops.DataProtocolServerCapabilities>();
|
let onCapabilitiesRegistered = new Emitter<ProviderFeatures>();
|
||||||
|
|
||||||
let configValueToConcat: TConfigurationValue<IConnectionProfileGroup[]> = {
|
let configValueToConcat = {
|
||||||
workspace: [{
|
workspace: [{
|
||||||
name: 'g1',
|
name: 'g1',
|
||||||
id: 'g1',
|
id: 'g1',
|
||||||
@@ -83,10 +85,10 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
],
|
],
|
||||||
value: [],
|
value: [],
|
||||||
default: [],
|
default: [],
|
||||||
folder: []
|
workspaceFolder: []
|
||||||
};
|
};
|
||||||
|
|
||||||
let configValueToMerge: TConfigurationValue<IConnectionProfileGroup[]> = {
|
let configValueToMerge = {
|
||||||
workspace: [
|
workspace: [
|
||||||
{
|
{
|
||||||
name: 'g1',
|
name: 'g1',
|
||||||
@@ -134,10 +136,10 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
}],
|
}],
|
||||||
value: [],
|
value: [],
|
||||||
default: [],
|
default: [],
|
||||||
folder: []
|
workspaceFolder: []
|
||||||
};
|
};
|
||||||
|
|
||||||
let connections: TConfigurationValue<IConnectionProfileStore[]> = {
|
let connections = {
|
||||||
workspace: [{
|
workspace: [{
|
||||||
options: {
|
options: {
|
||||||
serverName: 'server1',
|
serverName: 'server1',
|
||||||
@@ -182,10 +184,10 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
],
|
],
|
||||||
value: [],
|
value: [],
|
||||||
default: [],
|
default: [],
|
||||||
folder: []
|
workspaceFolder: []
|
||||||
};
|
};
|
||||||
setup(() => {
|
setup(() => {
|
||||||
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesService);
|
capabilitiesService = TypeMoq.Mock.ofType(CapabilitiesTestService);
|
||||||
capabilities = [];
|
capabilities = [];
|
||||||
let connectionProvider: sqlops.ConnectionProviderOptions = {
|
let connectionProvider: sqlops.ConnectionProviderOptions = {
|
||||||
options: [
|
options: [
|
||||||
@@ -198,8 +200,8 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
isIdentity: true,
|
isIdentity: true,
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
specialValueType: 0,
|
specialValueType: ConnectionOptionSpecialType.serverName,
|
||||||
valueType: 0
|
valueType: ServiceOptionType.string
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'databaseName',
|
name: 'databaseName',
|
||||||
@@ -210,8 +212,8 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
isIdentity: true,
|
isIdentity: true,
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
specialValueType: 1,
|
specialValueType: ConnectionOptionSpecialType.databaseName,
|
||||||
valueType: 0
|
valueType: ServiceOptionType.string
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'userName',
|
name: 'userName',
|
||||||
@@ -222,8 +224,8 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
isIdentity: true,
|
isIdentity: true,
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
specialValueType: 3,
|
specialValueType: ConnectionOptionSpecialType.userName,
|
||||||
valueType: 0
|
valueType: ServiceOptionType.string
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'authenticationType',
|
name: 'authenticationType',
|
||||||
@@ -234,8 +236,8 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
isIdentity: true,
|
isIdentity: true,
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
specialValueType: 2,
|
specialValueType: ConnectionOptionSpecialType.authType,
|
||||||
valueType: 0
|
valueType: ServiceOptionType.string
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'password',
|
name: 'password',
|
||||||
@@ -246,27 +248,26 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
isIdentity: true,
|
isIdentity: true,
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
specialValueType: 4,
|
specialValueType: ConnectionOptionSpecialType.password,
|
||||||
valueType: 0
|
valueType: ServiceOptionType.string
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
msSQLCapabilities = {
|
msSQLCapabilities = {
|
||||||
protocolVersion: '1',
|
connection: {
|
||||||
providerName: 'MSSQL',
|
providerId: 'MSSQL',
|
||||||
providerDisplayName: 'MSSQL',
|
displayName: 'MSSQL',
|
||||||
connectionProvider: connectionProvider,
|
connectionOptions: connectionProvider.options
|
||||||
adminServicesProvider: undefined,
|
}
|
||||||
features: undefined
|
|
||||||
};
|
};
|
||||||
capabilities.push(msSQLCapabilities);
|
capabilities.push(msSQLCapabilities);
|
||||||
|
|
||||||
capabilitiesService.setup(x => x.getCapabilities()).returns(() => capabilities);
|
capabilitiesService.setup(x => x.getCapabilities('MSSQL')).returns(() => msSQLCapabilities);
|
||||||
capabilitiesService.setup(x => x.onProviderRegisteredEvent).returns(() => onProviderRegistered.event);
|
(capabilitiesService.object as any).onCapabilitiesRegistered = onCapabilitiesRegistered.event;
|
||||||
|
|
||||||
workspaceConfigurationServiceMock = TypeMoq.Mock.ofType(WorkspaceConfigurationTestService);
|
workspaceConfigurationServiceMock = TypeMoq.Mock.ofType(WorkspaceConfigurationTestService);
|
||||||
workspaceConfigurationServiceMock.setup(x => x.reloadConfiguration())
|
workspaceConfigurationServiceMock.setup(x => x.reloadConfiguration())
|
||||||
.returns(() => TPromise.as<{}>({}));
|
.returns(() => TPromise.as(null));
|
||||||
|
|
||||||
configEditingServiceMock = TypeMoq.Mock.ofType(ConfigurationEditingService);
|
configEditingServiceMock = TypeMoq.Mock.ofType(ConfigurationEditingService);
|
||||||
let nothing: void;
|
let nothing: void;
|
||||||
@@ -305,7 +306,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('allGroups should return groups from user and workspace settings', () => {
|
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))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.returns(() => configValueToConcat);
|
||||||
|
|
||||||
@@ -355,7 +356,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
description: 'g1-2'
|
description: 'g1-2'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||||
Constants.connectionGroupsArrayName))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToMerge);
|
.returns(() => configValueToMerge);
|
||||||
|
|
||||||
@@ -382,19 +383,20 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: undefined
|
id: undefined,
|
||||||
|
connectionName: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length + 1;
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||||
Constants.connectionGroupsArrayName))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.returns(() => configValueToConcat);
|
||||||
|
|
||||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||||
config.addConnection(connectionProfile).then(savedConnectionProfile => {
|
config.addConnection(connectionProfile).then(savedConnectionProfile => {
|
||||||
@@ -403,8 +405,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
assert.notEqual(savedConnectionProfile.id, undefined);
|
assert.notEqual(savedConnectionProfile.id, undefined);
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert.fail();
|
done(error);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -424,19 +425,20 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: undefined
|
id: undefined,
|
||||||
|
connectionName: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length;
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||||
Constants.connectionGroupsArrayName))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.returns(() => configValueToConcat);
|
||||||
|
|
||||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||||
connectionProfile.options['databaseDisplayName'] = profileFromConfig.options['databaseName'];
|
connectionProfile.options['databaseDisplayName'] = profileFromConfig.options['databaseName'];
|
||||||
|
|
||||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||||
@@ -446,8 +448,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
assert.equal(savedConnectionProfile.id, profileFromConfig.id);
|
assert.equal(savedConnectionProfile.id, profileFromConfig.id);
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert.fail();
|
done(error);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -466,21 +467,22 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: undefined
|
id: undefined,
|
||||||
|
connectionName: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length + 1;
|
let expectedNumberOfConnections = connections.user.length + 1;
|
||||||
let expectedNumberOfGroups = configValueToConcat.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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
|
|
||||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||||
Constants.connectionGroupsArrayName))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.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);
|
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||||
config.addConnection(connectionProfile).then(success => {
|
config.addConnection(connectionProfile).then(success => {
|
||||||
configEditingServiceMock.verify(y => y.writeConfiguration(ConfigurationTarget.USER,
|
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());
|
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileGroup[]).length === expectedNumberOfGroups)), TypeMoq.Times.once());
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert.fail();
|
done(error);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getConnections should return connections from user and workspace settings given getWorkspaceConnections set to true', () => {
|
test('getConnections should return connections from user and workspace settings given getWorkspaceConnections set to true', () => {
|
||||||
let getWorkspaceConnections: boolean = 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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
|
|
||||||
@@ -509,7 +510,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
test('getConnections should return connections from user settings given getWorkspaceConnections set to false', () => {
|
test('getConnections should return connections from user settings given getWorkspaceConnections set to false', () => {
|
||||||
let getWorkspaceConnections: boolean = 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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
|
|
||||||
@@ -520,7 +521,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
|
|
||||||
test('getConnections should return connections with a valid id', () => {
|
test('getConnections should return connections with a valid id', () => {
|
||||||
let getWorkspaceConnections: boolean = false;
|
let getWorkspaceConnections: boolean = false;
|
||||||
let connectionsWithNoId: TConfigurationValue<IConnectionProfileStore[]> = {
|
let connectionsWithNoId = {
|
||||||
user: connections.user.map(c => {
|
user: connections.user.map(c => {
|
||||||
c.id = undefined;
|
c.id = undefined;
|
||||||
return c;
|
return c;
|
||||||
@@ -531,9 +532,9 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
return c;
|
return c;
|
||||||
}),
|
}),
|
||||||
value: connections.value,
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connectionsWithNoId);
|
.returns(() => connectionsWithNoId);
|
||||||
|
|
||||||
@@ -555,7 +556,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
|
|
||||||
test('getConnections update the capabilities in each profile when the provider capabilities is registered', () => {
|
test('getConnections update the capabilities in each profile when the provider capabilities is registered', () => {
|
||||||
let oldOptionName: string = 'oldOptionName';
|
let oldOptionName: string = 'oldOptionName';
|
||||||
let optionsMetadataFromConfig = capabilities[0].connectionProvider.options.concat({
|
let optionsMetadataFromConfig = capabilities[0].connection.connectionOptions.concat({
|
||||||
name: oldOptionName,
|
name: oldOptionName,
|
||||||
displayName: undefined,
|
displayName: undefined,
|
||||||
description: undefined,
|
description: undefined,
|
||||||
@@ -564,21 +565,17 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
isIdentity: true,
|
isIdentity: true,
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
specialValueType: 0,
|
specialValueType: undefined,
|
||||||
valueType: 0
|
valueType: ServiceOptionType.string
|
||||||
});
|
});
|
||||||
|
|
||||||
let capabilitiesFromConfig: sqlops.DataProtocolServerCapabilities[] = [];
|
let capabilitiesFromConfig: ProviderFeatures[] = [];
|
||||||
let connectionProvider: sqlops.ConnectionProviderOptions = {
|
let msSQLCapabilities2: ProviderFeatures = {
|
||||||
options: optionsMetadataFromConfig
|
connection: {
|
||||||
};
|
providerId: 'MSSQL',
|
||||||
let msSQLCapabilities2 = {
|
displayName: 'MSSQL',
|
||||||
protocolVersion: '1',
|
connectionOptions: optionsMetadataFromConfig
|
||||||
providerName: 'MSSQL',
|
}
|
||||||
providerDisplayName: 'MSSQL',
|
|
||||||
connectionProvider: connectionProvider,
|
|
||||||
adminServicesProvider: undefined,
|
|
||||||
features: undefined
|
|
||||||
};
|
};
|
||||||
capabilitiesFromConfig.push(msSQLCapabilities2);
|
capabilitiesFromConfig.push(msSQLCapabilities2);
|
||||||
let connectionUsingOldMetadata = connections.user.map(c => {
|
let connectionUsingOldMetadata = connections.user.map(c => {
|
||||||
@@ -586,21 +583,21 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
let configValue = Object.assign({}, connections, { user: connectionUsingOldMetadata });
|
let configValue = Object.assign({}, connections, { user: connectionUsingOldMetadata });
|
||||||
let capabilitiesService2: TypeMoq.Mock<CapabilitiesService> = TypeMoq.Mock.ofType(CapabilitiesService);
|
let capabilitiesService2: TypeMoq.Mock<ICapabilitiesService> = TypeMoq.Mock.ofType(CapabilitiesTestService);
|
||||||
capabilitiesService2.setup(x => x.getCapabilities()).returns(() => []);
|
capabilitiesService2.setup(x => x.getCapabilities('MSSQL')).returns(() => msSQLCapabilities2);
|
||||||
capabilitiesService2.setup(x => x.onProviderRegisteredEvent).returns(() => onProviderRegistered.event);
|
(capabilitiesService2.object as any).onCapabilitiesRegistered = onCapabilitiesRegistered.event;
|
||||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||||
Constants.connectionsArrayName))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => configValue);
|
.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);
|
let allConnections = config.getConnections(false);
|
||||||
allConnections.forEach(element => {
|
allConnections.forEach(element => {
|
||||||
assert.notEqual(element.serverName, undefined);
|
assert.notEqual(element.serverName, undefined);
|
||||||
assert.notEqual(element.getOptionsKey().indexOf('oldOptionValue|'), -1);
|
assert.notEqual(element.getOptionsKey().indexOf('oldOptionValue|'), -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
onProviderRegistered.fire(msSQLCapabilities);
|
onCapabilitiesRegistered.fire(msSQLCapabilities);
|
||||||
allConnections.forEach(element => {
|
allConnections.forEach(element => {
|
||||||
assert.notEqual(element.serverName, undefined);
|
assert.notEqual(element.serverName, undefined);
|
||||||
assert.equal(element.getOptionsKey().indexOf('oldOptionValue|'), -1);
|
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', () => {
|
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 groups: IConnectionProfileGroup[] = configValueToConcat.user;
|
||||||
let expectedLength = configValueToConcat.user.length + 2;
|
let expectedLength = configValueToConcat.user.length + 2;
|
||||||
let newGroups: string = 'ROOT/g1/g1-1';
|
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', () => {
|
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 groups: IConnectionProfileGroup[] = configValueToConcat.user;
|
||||||
let expectedLength = configValueToConcat.user.length + 1;
|
let expectedLength = configValueToConcat.user.length + 1;
|
||||||
let newGroups: string = 'ROOT/g2/g2-5';
|
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', () => {
|
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 groups: IConnectionProfileGroup[] = configValueToConcat.user;
|
||||||
let expectedLength = configValueToConcat.user.length;
|
let expectedLength = configValueToConcat.user.length;
|
||||||
let newGroups: string = 'ROOT/g2/g2-1';
|
let newGroups: string = 'ROOT/g2/g2-1';
|
||||||
@@ -664,15 +661,16 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: undefined
|
id: undefined,
|
||||||
|
connectionName: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length - 1;
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
|
|
||||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||||
|
|
||||||
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
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());
|
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileStore[]).length === expectedNumberOfConnections)), TypeMoq.Times.once());
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert.fail();
|
done(error);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -701,9 +698,10 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
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';
|
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||||
|
|
||||||
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
|
let connectionProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
|
||||||
@@ -713,11 +711,11 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length - 1;
|
let expectedNumberOfConnections = connections.user.length - 1;
|
||||||
let expectedNumberOfGroups = configValueToConcat.user.length - 2;
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
|
|
||||||
workspaceConfigurationServiceMock.setup(x => x.lookup<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
workspaceConfigurationServiceMock.setup(x => x.inspect<IConnectionProfileStore[] | IConnectionProfileGroup[] | sqlops.DataProtocolServerCapabilities[]>(
|
||||||
Constants.connectionGroupsArrayName))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.returns(() => configValueToConcat);
|
||||||
|
|
||||||
@@ -730,8 +728,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileGroup[]).length === expectedNumberOfGroups)), TypeMoq.Times.once());
|
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileGroup[]).length === expectedNumberOfGroups)), TypeMoq.Times.once());
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert.fail();
|
done(error);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -750,23 +747,23 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: undefined
|
id: undefined,
|
||||||
|
connectionName: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length;
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.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);
|
let config = new ConnectionConfig(configEditingServiceMock.object, workspaceConfigurationServiceMock.object, capabilitiesService.object);
|
||||||
config.deleteConnection(connectionProfile).then(() => {
|
config.deleteConnection(connectionProfile).then(() => {
|
||||||
configEditingServiceMock.verify(y => y.writeConfiguration(ConfigurationTarget.USER,
|
configEditingServiceMock.verify(y => y.writeConfiguration(ConfigurationTarget.USER,
|
||||||
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileStore[]).length === expectedNumberOfConnections)), TypeMoq.Times.once());
|
TypeMoq.It.is<IConfigurationValue>(c => (c.value as IConnectionProfileStore[]).length === expectedNumberOfConnections)), TypeMoq.Times.once());
|
||||||
done();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
assert.fail();
|
done(error);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -780,7 +777,7 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
configEditingServiceMock.setup(x => x.writeConfiguration(ConfigurationTarget.USER, TypeMoq.It.isAny())).callback((x: any, val: any) => {
|
configEditingServiceMock.setup(x => x.writeConfiguration(ConfigurationTarget.USER, TypeMoq.It.isAny())).callback((x: any, val: any) => {
|
||||||
calledValue = val.value as IConnectionProfileStore[];
|
calledValue = val.value as IConnectionProfileStore[];
|
||||||
}).returns(() => TPromise.as<void>(nothing));
|
}).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))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.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) => {
|
configEditingServiceMock.setup(x => x.writeConfiguration(ConfigurationTarget.USER, TypeMoq.It.isAny())).callback((x: any, val: any) => {
|
||||||
calledValue = val.value as IConnectionProfileStore[];
|
calledValue = val.value as IConnectionProfileStore[];
|
||||||
}).returns(() => TPromise.as<void>(nothing));
|
}).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))
|
Constants.connectionGroupsArrayName))
|
||||||
.returns(() => configValueToConcat);
|
.returns(() => configValueToConcat);
|
||||||
|
|
||||||
@@ -842,15 +839,16 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
options: {},
|
options: {},
|
||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: 'test'
|
id: 'test',
|
||||||
|
connectionName: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
let expectedNumberOfConnections = connections.user.length;
|
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))
|
Constants.connectionsArrayName))
|
||||||
.returns(() => connections);
|
.returns(() => connections);
|
||||||
|
|
||||||
let connectionProfile = new ConnectionProfile(msSQLCapabilities, newProfile);
|
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||||
let newId = 'newid';
|
let newId = 'newid';
|
||||||
let calledValue: any;
|
let calledValue: any;
|
||||||
let nothing: void;
|
let nothing: void;
|
||||||
@@ -927,10 +925,33 @@ suite('SQL ConnectionConfig tests', () => {
|
|||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
test('fixConnectionIds should replace duplicate ids with new ones', (done) => {
|
test('addConnection should not move the connection when editing', async () => {
|
||||||
done();
|
// 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