mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 17:22:59 -05:00
This reverts commit 756f77063a.
This commit is contained in:
@@ -5,20 +5,23 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as azdata from 'azdata';
|
||||
import { ICapabilitiesService, ProviderFeatures } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ConnectionConfig, ISaveGroupResult } from 'sql/platform/connection/common/connectionConfig';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConnectionProfileGroup, IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { IConnectionProfile, IConnectionProfileStore } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import { IConnectionProfileGroup, ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import * as assert from 'assert';
|
||||
import { ProviderFeatures, ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import * as azdata from 'azdata';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { deepClone, deepFreeze } from 'vs/base/common/objects';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { deepFreeze, deepClone } from 'vs/base/common/objects';
|
||||
import { isUndefinedOrNull } from 'vs/base/common/types';
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
|
||||
suite('ConnectionConfig', () => {
|
||||
let capabilitiesService: TypeMoq.Mock<ICapabilitiesService>;
|
||||
@@ -231,9 +234,9 @@ suite('ConnectionConfig', () => {
|
||||
|
||||
test('getAllGroups should merge user and workspace settings correctly', () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(0, 3), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups).slice(0, 3), ConfigurationTarget.USER);
|
||||
// we intentionally overlap these values with the expectation that the function to should return each group once
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups).slice(2, testGroups.length), ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups).slice(2, testGroups.length), ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allGroups = config.getAllGroups();
|
||||
@@ -242,7 +245,7 @@ suite('ConnectionConfig', () => {
|
||||
assert.ok(groupsAreEqual(allGroups, testGroups), 'the groups returned did not match expectation');
|
||||
});
|
||||
|
||||
test('addConnection should add the new profile to user settings', async () => {
|
||||
test('addConnection should add the new profile to user settings if does not exist', async () => {
|
||||
let newProfile: IConnectionProfile = {
|
||||
serverName: 'new server',
|
||||
databaseName: 'database',
|
||||
@@ -262,15 +265,15 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let savedConnectionProfile = await config.addConnection(connectionProfile);
|
||||
|
||||
assert.ok(!!savedConnectionProfile.id);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length + 1);
|
||||
assert.ok(!isUndefinedOrNull(savedConnectionProfile.id));
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length + 1);
|
||||
});
|
||||
|
||||
test('addConnection should not add the new profile to user settings if already exists', async () => {
|
||||
@@ -294,8 +297,8 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = existingConnection.options['databaseName'];
|
||||
@@ -304,7 +307,7 @@ suite('ConnectionConfig', () => {
|
||||
let savedConnectionProfile = await config.addConnection(connectionProfile);
|
||||
|
||||
assert.equal(savedConnectionProfile.id, existingConnection.id);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length);
|
||||
});
|
||||
|
||||
test('addConnection should add the new group to user settings if does not exist', async () => {
|
||||
@@ -327,21 +330,21 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.addConnection(connectionProfile);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length + 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connectionGroups').user.length, testGroups.length + 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length + 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionGroupsArrayName).user.length, testGroups.length + 1);
|
||||
});
|
||||
|
||||
test('getConnections should return connections from user and workspace settings given getWorkspaceConnections set to true', () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(0, 1), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(1, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(0, 1), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(1, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allConnections = config.getConnections(true);
|
||||
@@ -350,8 +353,8 @@ suite('ConnectionConfig', () => {
|
||||
|
||||
test('getConnections should return connections from user settings given getWorkspaceConnections set to false', () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(0, 2), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections).slice(2, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(0, 2), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections).slice(2, testConnections.length), ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allConnections = config.getConnections(false);
|
||||
@@ -368,8 +371,8 @@ suite('ConnectionConfig', () => {
|
||||
return c;
|
||||
});
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', userConnections, ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', workspaceConnections, ConfigurationTarget.WORKSPACE);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, userConnections, ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, workspaceConnections, ConfigurationTarget.WORKSPACE);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
let allConnections = config.getConnections(false);
|
||||
@@ -378,7 +381,7 @@ suite('ConnectionConfig', () => {
|
||||
let userConnection = testConnections.find(u => u.options['serverName'] === connection.serverName);
|
||||
if (userConnection !== undefined) {
|
||||
assert.notEqual(connection.id, connection.getOptionsKey());
|
||||
assert.ok(!!connection.id);
|
||||
assert.ok(!isUndefinedOrNull(connection.id));
|
||||
} else {
|
||||
let workspaceConnection = workspaceConnections.find(u => u.options['serverName'] === connection.serverName);
|
||||
assert.notEqual(connection.id, connection.getOptionsKey());
|
||||
@@ -394,7 +397,7 @@ suite('ConnectionConfig', () => {
|
||||
let color: string = 'red';
|
||||
|
||||
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
|
||||
assert.ok(!!result);
|
||||
assert.ok(!isUndefinedOrNull(result));
|
||||
assert.equal(result.groups.length, testGroups.length + 2, 'The result groups length is invalid');
|
||||
let newGroup = result.groups.find(g => g.name === 'new-group2');
|
||||
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
|
||||
@@ -407,7 +410,7 @@ suite('ConnectionConfig', () => {
|
||||
let color: string = 'red';
|
||||
|
||||
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
|
||||
assert.ok(!!result);
|
||||
assert.ok(!isUndefinedOrNull(result));
|
||||
assert.equal(result.groups.length, testGroups.length + 1, 'The result groups length is invalid');
|
||||
let newGroup = result.groups.find(g => g.name === 'g2-5');
|
||||
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
|
||||
@@ -420,7 +423,7 @@ suite('ConnectionConfig', () => {
|
||||
let color: string = 'red';
|
||||
|
||||
let result: ISaveGroupResult = config.saveGroup(groups, newGroups, color, newGroups);
|
||||
assert.ok(!!result);
|
||||
assert.ok(!isUndefinedOrNull(result));
|
||||
assert.equal(result.groups.length, testGroups.length, 'The result groups length is invalid');
|
||||
let newGroup = result.groups.find(g => g.name === 'g2-1');
|
||||
assert.equal(result.newGroupId, newGroup.id, 'The groups id is invalid');
|
||||
@@ -445,7 +448,7 @@ suite('ConnectionConfig', () => {
|
||||
connectionName: undefined
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
@@ -453,7 +456,7 @@ suite('ConnectionConfig', () => {
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.deleteConnection(connectionProfile);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length - 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length - 1);
|
||||
});
|
||||
|
||||
test('deleteConnectionGroup should remove the children connections and subgroups from config', async () => {
|
||||
@@ -475,8 +478,8 @@ suite('ConnectionConfig', () => {
|
||||
connectionName: undefined
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
connectionProfile.options['databaseDisplayName'] = 'database';
|
||||
@@ -489,8 +492,8 @@ suite('ConnectionConfig', () => {
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.deleteGroup(connectionProfileGroup);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length - 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user.length, testGroups.length - 2);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length - 1);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user.length, testGroups.length - 2);
|
||||
});
|
||||
|
||||
test('deleteConnection should not throw error for connection not in config', async () => {
|
||||
@@ -512,34 +515,34 @@ suite('ConnectionConfig', () => {
|
||||
connectionName: undefined
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.deleteConnection(connectionProfile);
|
||||
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user.length, testConnections.length);
|
||||
assert.equal(configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user.length, testConnections.length);
|
||||
});
|
||||
|
||||
test('renameGroup should change group name', async () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfileGroup = new ConnectionProfileGroup('g-renamed', undefined, 'g2', undefined, undefined);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.editGroup(connectionProfileGroup);
|
||||
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
|
||||
assert.equal(editedGroups.length, testGroups.length);
|
||||
let editedGroup = editedGroups.find(group => group.id === 'g2');
|
||||
assert.ok(!!editedGroup);
|
||||
assert.ok(!isUndefinedOrNull(editedGroup));
|
||||
assert.equal(editedGroup.name, 'g-renamed');
|
||||
});
|
||||
|
||||
test('edit group should throw if there is a confliction', async () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let sameNameGroup = new ConnectionProfileGroup('g3', undefined, 'g2', undefined, undefined);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
@@ -548,27 +551,27 @@ suite('ConnectionConfig', () => {
|
||||
await config.editGroup(sameNameGroup);
|
||||
assert.fail();
|
||||
} catch (e) {
|
||||
let groups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
let groups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
let originalGroup = groups.find(g => g.id === 'g2');
|
||||
assert.ok(!!originalGroup);
|
||||
assert.ok(!isUndefinedOrNull(originalGroup));
|
||||
assert.equal(originalGroup.name, 'g2');
|
||||
}
|
||||
});
|
||||
|
||||
test('change group(parent) for connection group', async () => {
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let sourceProfileGroup = new ConnectionProfileGroup('g2', undefined, 'g2', undefined, undefined);
|
||||
let targetProfileGroup = new ConnectionProfileGroup('g3', undefined, 'g3', undefined, undefined);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.changeGroupIdForConnectionGroup(sourceProfileGroup, targetProfileGroup);
|
||||
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
let editedGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
|
||||
assert.equal(editedGroups.length, testGroups.length);
|
||||
let editedGroup = editedGroups.find(group => group.id === 'g2');
|
||||
assert.ok(!!editedGroup);
|
||||
assert.ok(!isUndefinedOrNull(editedGroup));
|
||||
assert.equal(editedGroup.parentId, 'g3');
|
||||
});
|
||||
|
||||
@@ -612,7 +615,7 @@ suite('ConnectionConfig', () => {
|
||||
let _testConnections = deepClone(testConnections).concat([existingProfile, changingProfile]);
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', _testConnections, ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, _testConnections, ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, changingProfile);
|
||||
|
||||
@@ -621,11 +624,11 @@ suite('ConnectionConfig', () => {
|
||||
await config.changeGroupIdForConnection(connectionProfile, 'test');
|
||||
assert.fail();
|
||||
} catch (e) {
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user;
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user;
|
||||
// two
|
||||
assert.equal(editedConnections.length, _testConnections.length);
|
||||
let editedConnection = editedConnections.find(con => con.id === 'server3-2');
|
||||
assert.ok(!!editedConnection);
|
||||
assert.ok(!isUndefinedOrNull(editedConnection));
|
||||
assert.equal(editedConnection.groupId, 'g3');
|
||||
}
|
||||
});
|
||||
@@ -650,7 +653,7 @@ suite('ConnectionConfig', () => {
|
||||
};
|
||||
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService.object, newProfile);
|
||||
let newId = 'newid';
|
||||
@@ -658,18 +661,18 @@ suite('ConnectionConfig', () => {
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
await config.changeGroupIdForConnection(connectionProfile, newId);
|
||||
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>('datasource.connections').user;
|
||||
let editedConnections = configurationService.inspect<IConnectionProfileStore[]>(Constants.connectionsArrayName).user;
|
||||
assert.equal(editedConnections.length, testConnections.length);
|
||||
let editedConnection = editedConnections.find(con => con.id === 'server3');
|
||||
assert.ok(!!editedConnection);
|
||||
assert.ok(!isUndefinedOrNull(editedConnection));
|
||||
assert.equal(editedConnection.groupId, 'newid');
|
||||
});
|
||||
|
||||
test('addConnection should not move the connection when editing', async () => {
|
||||
// Set up the connection config
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connections', deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionsArrayName, deepClone(testConnections), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
|
||||
// Clone a connection and modify an option
|
||||
@@ -699,13 +702,13 @@ suite('ConnectionConfig', () => {
|
||||
description: 'new group'
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
let config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
|
||||
await config.addGroup(newGroup);
|
||||
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
|
||||
assert.equal(editGroups.length, testGroups.length + 1);
|
||||
});
|
||||
@@ -719,14 +722,14 @@ suite('ConnectionConfig', () => {
|
||||
description: 'new group'
|
||||
};
|
||||
let configurationService = new TestConfigurationService();
|
||||
configurationService.updateValue('datasource.connectionGroups', deepClone(testGroups), ConfigurationTarget.USER);
|
||||
configurationService.updateValue(Constants.connectionGroupsArrayName, deepClone(testGroups), ConfigurationTarget.USER);
|
||||
|
||||
const config = new ConnectionConfig(configurationService, capabilitiesService.object);
|
||||
try {
|
||||
await config.addGroup(existingGroupName);
|
||||
assert.fail();
|
||||
} catch (e) {
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>('datasource.connectionGroups').user;
|
||||
let editGroups = configurationService.inspect<IConnectionProfileGroup[]>(Constants.connectionGroupsArrayName).user;
|
||||
|
||||
assert.equal(editGroups.length, testGroups.length);
|
||||
}
|
||||
|
||||
@@ -1,528 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as azdata from 'azdata';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { IConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
||||
import { ConnectionStore } from 'sql/platform/connection/common/connectionStore';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService';
|
||||
import { TestStateService } from 'sql/platform/connection/test/common/testStateService';
|
||||
import { TestCredentialsService } from 'sql/platform/credentials/test/common/testCredentialsService';
|
||||
import { ConnectionOptionSpecialType, ServiceOptionType } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
|
||||
import { deepClone, deepFreeze } from 'vs/base/common/objects';
|
||||
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
suite('ConnectionStore', () => {
|
||||
let defaultNamedProfile: IConnectionProfile = deepFreeze({
|
||||
connectionName: 'new name',
|
||||
serverName: 'namedServer',
|
||||
databaseName: 'bcd',
|
||||
authenticationType: 'SqlLogin',
|
||||
userName: 'cde',
|
||||
password: 'asdf!@#$',
|
||||
savePassword: true,
|
||||
groupId: '',
|
||||
groupFullName: '',
|
||||
getOptionsKey: undefined,
|
||||
matches: undefined,
|
||||
providerName: 'MSSQL',
|
||||
options: {},
|
||||
saveProfile: true,
|
||||
id: undefined
|
||||
});
|
||||
let capabilitiesService: CapabilitiesTestService;
|
||||
let maxRecent = 5;
|
||||
let msSQLCapabilities: ConnectionProviderProperties;
|
||||
let provider2Capabilities: ConnectionProviderProperties;
|
||||
let defaultNamedConnectionProfile: ConnectionProfile;
|
||||
|
||||
setup(() => {
|
||||
// setup configuration to return maxRecent for the #MRU items
|
||||
|
||||
capabilitiesService = new CapabilitiesTestService();
|
||||
let connectionProvider: azdata.ConnectionOption[] = [
|
||||
{
|
||||
name: 'connectionName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.connectionName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'serverName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.serverName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'databaseName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.databaseName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'userName',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.userName,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'authenticationType',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.authType,
|
||||
valueType: ServiceOptionType.string
|
||||
},
|
||||
{
|
||||
name: 'password',
|
||||
displayName: undefined,
|
||||
description: undefined,
|
||||
groupName: undefined,
|
||||
categoryValues: undefined,
|
||||
defaultValue: undefined,
|
||||
isIdentity: true,
|
||||
isRequired: true,
|
||||
specialValueType: ConnectionOptionSpecialType.password,
|
||||
valueType: ServiceOptionType.string
|
||||
}
|
||||
];
|
||||
msSQLCapabilities = {
|
||||
providerId: 'MSSQL',
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: connectionProvider
|
||||
};
|
||||
|
||||
provider2Capabilities = {
|
||||
providerId: 'MSSQL',
|
||||
displayName: 'MSSQL',
|
||||
connectionOptions: connectionProvider
|
||||
};
|
||||
capabilitiesService.capabilities['MSSQL'] = { connection: msSQLCapabilities };
|
||||
capabilitiesService.capabilities['Provider2'] = { connection: provider2Capabilities };
|
||||
|
||||
defaultNamedConnectionProfile = new ConnectionProfile(capabilitiesService, defaultNamedProfile);
|
||||
});
|
||||
|
||||
test('addActiveConnection should limit recent connection saves to the MaxRecentConnections amount', async () => {
|
||||
// Given 5 is the max # creds
|
||||
let numCreds = 6;
|
||||
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
await configurationService.updateValue('sql.maxRecentConnections', 5, ConfigurationTarget.USER);
|
||||
|
||||
// When saving 4 connections
|
||||
// Expect all of them to be saved even if size is limited to 3
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
for (let i = 0; i < numCreds; i++) {
|
||||
let cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService, cred);
|
||||
await connectionStore.addRecentConnection(connectionProfile);
|
||||
let current = connectionStore.getRecentlyUsedConnections();
|
||||
if (i >= maxRecent) {
|
||||
assert.equal(current.length, maxRecent, `expect only top ${maxRecent} creds to be saved`);
|
||||
} else {
|
||||
assert.equal(current.length, i + 1, `expect all credentials to be saved ${current.length}|${i + 1} `);
|
||||
}
|
||||
assert.equal(current[0].serverName, cred.serverName, 'Expect most recently saved item to be first in list');
|
||||
assert.ok(!current[0].password);
|
||||
}
|
||||
assert.equal(credentialsService.credentials.size, numCreds);
|
||||
});
|
||||
|
||||
test('getRecentlyUsedConnections should return connection for given provider', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let connections = connectionStore.getRecentlyUsedConnections(['Provider2']);
|
||||
assert.ok(!!connections);
|
||||
assert.ok(connections.every(c => c.providerName === 'Provider2'));
|
||||
});
|
||||
|
||||
test('addActiveConnection should add same connection exactly once', async () => {
|
||||
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
// 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(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + 1 });
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService, cred);
|
||||
await connectionStore.addRecentConnection(defaultNamedConnectionProfile);
|
||||
await connectionStore.addRecentConnection(connectionProfile);
|
||||
await connectionStore.addRecentConnection(connectionProfile);
|
||||
let current = connectionStore.getRecentlyUsedConnections();
|
||||
assert.equal(current.length, 2, 'expect 2 unique credentials to have been added');
|
||||
assert.equal(current[0].serverName, cred.serverName, 'Expect most recently saved item to be first in list');
|
||||
assert.ok(!current[0].password);
|
||||
});
|
||||
|
||||
test('addActiveConnection should save password to credential store', async () => {
|
||||
|
||||
// Setup credential store to capture credentials sent to it
|
||||
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
// Given we save 1 connection with password and multiple other connections without
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let integratedCred = Object.assign({}, defaultNamedProfile, {
|
||||
serverName: defaultNamedProfile.serverName + 'Integrated',
|
||||
authenticationType: 'Integrated',
|
||||
userName: '',
|
||||
password: ''
|
||||
});
|
||||
let noPwdCred = Object.assign({}, defaultNamedProfile, {
|
||||
serverName: defaultNamedProfile.serverName + 'NoPwd',
|
||||
password: ''
|
||||
});
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService, defaultNamedProfile);
|
||||
|
||||
let recentCredential: azdata.Credential;
|
||||
credentialsService.onCredential(e => recentCredential = e);
|
||||
|
||||
await connectionStore.addRecentConnection(connectionProfile);
|
||||
|
||||
let current = connectionStore.getRecentlyUsedConnections();
|
||||
// Then verify that since its password based we save the password
|
||||
assert.equal(credentialsService.credentials.size, 1);
|
||||
assert.strictEqual(recentCredential.password, defaultNamedProfile.password);
|
||||
assert.ok(recentCredential.credentialId.includes('Profile'), 'Expect credential to be marked as an Profile cred');
|
||||
assert.ok(!current[0].password);
|
||||
// When add integrated auth connection
|
||||
let integratedCredConnectionProfile = new ConnectionProfile(capabilitiesService, integratedCred);
|
||||
await connectionStore.addRecentConnection(integratedCredConnectionProfile);
|
||||
current = connectionStore.getRecentlyUsedConnections();
|
||||
// then expect not to have credential store called, but MRU count upped to 2
|
||||
assert.equal(credentialsService.credentials.size, 1);
|
||||
assert.equal(current.length, 2);
|
||||
// When add connection without password
|
||||
let noPwdCredConnectionProfile = new ConnectionProfile(capabilitiesService, noPwdCred);
|
||||
await connectionStore.addRecentConnection(noPwdCredConnectionProfile);
|
||||
current = connectionStore.getRecentlyUsedConnections();
|
||||
// then expect not to have credential store called, but MRU count upped to 3
|
||||
assert.equal(current.length, 3);
|
||||
assert.equal(credentialsService.credentials.size, 1);
|
||||
});
|
||||
|
||||
test('can clear connections list', async () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
await connectionStore.addRecentConnection(defaultNamedProfile);
|
||||
let result = connectionStore.getRecentlyUsedConnections();
|
||||
assert.equal(result.length, 1);
|
||||
connectionStore.clearRecentlyUsed();
|
||||
result = connectionStore.getRecentlyUsedConnections();
|
||||
assert.equal(result.length, 0);
|
||||
// Then test is complete
|
||||
});
|
||||
|
||||
test('isPasswordRequired should return true for MSSQL SqlLogin', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
assert.ok(connectionStore.isPasswordRequired(defaultNamedProfile));
|
||||
});
|
||||
|
||||
test('isPasswordRequired should return true for MSSQL SqlLogin for connection profile object', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService, defaultNamedProfile);
|
||||
|
||||
assert.ok(connectionStore.isPasswordRequired(connectionProfile));
|
||||
});
|
||||
|
||||
test('isPasswordRequired should return false if the password is not required in capabilities', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let providerName: string = 'providername';
|
||||
let connectionProvider = msSQLCapabilities.connectionOptions.map(o => {
|
||||
if (o.name === 'password') {
|
||||
o.isRequired = false;
|
||||
}
|
||||
return o;
|
||||
});
|
||||
let providerCapabilities = {
|
||||
providerId: providerName,
|
||||
displayName: providerName,
|
||||
connectionOptions: connectionProvider
|
||||
};
|
||||
|
||||
capabilitiesService.capabilities[providerName] = { connection: providerCapabilities };
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let connectionProfile: IConnectionProfile = Object.assign({}, defaultNamedProfile, { providerName: providerName });
|
||||
|
||||
assert.ok(!connectionStore.isPasswordRequired(connectionProfile));
|
||||
});
|
||||
|
||||
test('saveProfile should save the password after the profile is saved', async () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let password: string = 'asdf!@#$';
|
||||
let connectionProfile: IConnectionProfile = Object.assign({}, defaultNamedProfile, { password });
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
let profile = await connectionStore.saveProfile(connectionProfile);
|
||||
// add connection should be called with a profile without password
|
||||
assert.equal(profile.password, password, 'The returned profile should still keep the password');
|
||||
assert.ok(!!profile.groupId, 'Group id should be set in the profile');
|
||||
});
|
||||
|
||||
test('getGroupFromId returns undefined when there is no group with the given ID', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let group = connectionStore.getGroupFromId('invalidId');
|
||||
assert.equal(group, undefined, 'Returned group was not undefined when there was no group with the given ID');
|
||||
});
|
||||
|
||||
test('getGroupFromId returns the group that has the given ID', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let parentGroupId = 'parentGroup';
|
||||
let childGroupId = 'childGroup';
|
||||
|
||||
let groups: IConnectionProfileGroup[] = [
|
||||
{
|
||||
id: parentGroupId,
|
||||
name: parentGroupId,
|
||||
color: undefined,
|
||||
description: '',
|
||||
parentId: ''
|
||||
},
|
||||
{
|
||||
id: childGroupId,
|
||||
name: childGroupId,
|
||||
color: undefined,
|
||||
description: '',
|
||||
parentId: parentGroupId
|
||||
}
|
||||
];
|
||||
|
||||
configurationService.updateValue('datasource.connectionGroups', groups, ConfigurationTarget.USER);
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
// If I look up the parent group using its ID, then I get back the correct group
|
||||
let actualGroup = connectionStore.getGroupFromId(parentGroupId);
|
||||
assert.equal(actualGroup.id, parentGroupId, 'Did not get the parent group when looking it up with its ID');
|
||||
|
||||
// If I look up the child group using its ID, then I get back the correct group
|
||||
actualGroup = connectionStore.getGroupFromId(childGroupId);
|
||||
assert.equal(actualGroup.id, childGroupId, 'Did not get the child group when looking it up with its ID');
|
||||
});
|
||||
|
||||
test('getProfileWithoutPassword can return the profile without credentials in the password property or options dictionary', () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
let profile = deepClone(defaultNamedProfile);
|
||||
profile.options['password'] = profile.password;
|
||||
profile.id = 'testId';
|
||||
let expectedProfile = Object.assign({}, profile);
|
||||
expectedProfile.password = '';
|
||||
expectedProfile.options['password'] = '';
|
||||
expectedProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, expectedProfile).toIConnectionProfile();
|
||||
let profileWithoutCredentials = connectionStore.getProfileWithoutPassword(profile);
|
||||
assert.deepEqual(profileWithoutCredentials.toIConnectionProfile(), expectedProfile);
|
||||
});
|
||||
|
||||
test('addPassword gets the password from the credentials service', async () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let profile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, Object.assign({}, defaultNamedProfile, { password: undefined }));
|
||||
|
||||
let credId = `Microsoft.SqlTools|itemtype:Profile|id:${profile.getConnectionInfoId()}`;
|
||||
let password: string = 'asdf!@#$';
|
||||
|
||||
await credentialsService.saveCredential(credId, password);
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
let passwordProfile = (await connectionStore.addSavedPassword(profile)).profile;
|
||||
|
||||
assert.equal(passwordProfile.password, password);
|
||||
});
|
||||
|
||||
test('getConnectionProfileGroups', async () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let parentGroupId = 'parentGroup';
|
||||
let childGroupId = 'childGroup';
|
||||
let groups: IConnectionProfileGroup[] = [
|
||||
{
|
||||
id: parentGroupId,
|
||||
name: parentGroupId,
|
||||
color: undefined,
|
||||
description: '',
|
||||
parentId: ''
|
||||
},
|
||||
{
|
||||
id: childGroupId,
|
||||
name: childGroupId,
|
||||
color: undefined,
|
||||
description: '',
|
||||
parentId: parentGroupId
|
||||
}
|
||||
];
|
||||
|
||||
configurationService.updateValue('datasource.connectionGroups', groups, ConfigurationTarget.USER);
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
let connectionGroups = connectionStore.getConnectionProfileGroups();
|
||||
|
||||
for (let group of connectionGroups) {
|
||||
let foundGroup = groups.find(g => g.id === group.id);
|
||||
assert.ok(foundGroup);
|
||||
}
|
||||
});
|
||||
|
||||
test('removing connection correctly removes', async () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
let cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService, cred);
|
||||
await connectionStore.addRecentConnection(connectionProfile);
|
||||
let current = connectionStore.getRecentlyUsedConnections();
|
||||
assert.equal(current.length, i + 1);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
let cred = Object.assign({}, defaultNamedProfile, { serverName: defaultNamedProfile.serverName + i });
|
||||
let connectionProfile = new ConnectionProfile(capabilitiesService, cred);
|
||||
await connectionStore.removeRecentConnection(connectionProfile);
|
||||
let current = connectionStore.getRecentlyUsedConnections();
|
||||
assert.equal(current.length, 4 - i);
|
||||
}
|
||||
});
|
||||
|
||||
test('getRecentlyUsedConnections correctly fills in group names', async () => {
|
||||
let stateService = new TestStateService();
|
||||
let configurationService = new TestConfigurationService();
|
||||
let credentialsService = new TestCredentialsService();
|
||||
|
||||
let connectionStore = new ConnectionStore(stateService, configurationService,
|
||||
credentialsService, capabilitiesService);
|
||||
|
||||
let parentGroupId = 'parentGroup';
|
||||
let parentGroupName = 'parentGroupName';
|
||||
let group: IConnectionProfileGroup = {
|
||||
id: parentGroupId,
|
||||
name: parentGroupName,
|
||||
color: undefined,
|
||||
description: '',
|
||||
parentId: ''
|
||||
};
|
||||
let connection: azdata.IConnectionProfile = {
|
||||
options: [],
|
||||
connectionName: '',
|
||||
serverName: 'server1',
|
||||
databaseName: 'database',
|
||||
userName: 'user',
|
||||
password: 'password',
|
||||
authenticationType: '',
|
||||
providerName: 'MSSQL',
|
||||
groupId: parentGroupId,
|
||||
groupFullName: '',
|
||||
savePassword: true,
|
||||
saveProfile: true,
|
||||
id: 'server1'
|
||||
};
|
||||
|
||||
configurationService.updateValue('datasource.connectionGroups', [group], ConfigurationTarget.USER);
|
||||
configurationService.updateValue('datasource.connections', [connection], ConfigurationTarget.USER);
|
||||
|
||||
connectionStore.addRecentConnection(ConnectionProfile.fromIConnectionProfile(capabilitiesService, connection));
|
||||
|
||||
let connections = connectionStore.getRecentlyUsedConnections();
|
||||
|
||||
assert.equal(connections[0].groupFullName, parentGroupName);
|
||||
});
|
||||
});
|
||||
@@ -17,8 +17,13 @@ export class TestConfigurationService implements IConfigurationService {
|
||||
return Promise.resolve(this.getValue());
|
||||
}
|
||||
|
||||
public getValue(arg1?: any): any {
|
||||
return getConfigurationValue(this.configuration.user, arg1);
|
||||
public getValue(arg1?: any, arg2?: any): any {
|
||||
let configuration;
|
||||
configuration = configuration ? configuration : this.configuration;
|
||||
if (arg1 && typeof arg1 === 'string') {
|
||||
return getConfigurationValue(configuration, arg1);
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public updateValue(key: string, value: any, target?: any): Promise<void> {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { IStateService } from 'vs/platform/state/common/state';
|
||||
|
||||
export class TestStateService implements IStateService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private storage = {};
|
||||
|
||||
constructor() { }
|
||||
|
||||
getItem<T>(key: string, defaultValue: T): T;
|
||||
getItem<T>(key: string, defaultValue: T | undefined): T | undefined;
|
||||
getItem<T>(key: string, defaultValue?: T): T | undefined {
|
||||
return this.storage[key] || defaultValue;
|
||||
}
|
||||
|
||||
setItem(key: string, data: any): void {
|
||||
this.storage[key] = data;
|
||||
}
|
||||
|
||||
removeItem(key: string): void {
|
||||
delete this.storage[key];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user