Add support for resource level connection configs (#1018)

This commit is contained in:
Matt Irvine 2017-11-07 10:56:24 -08:00 коммит произвёл GitHub
Родитель 64374019cf
Коммит 2e745d3d24
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 52 добавлений и 4 удалений

Просмотреть файл

@ -32,7 +32,8 @@
"MSSQL",
"SQL Server",
"Azure SQL Database",
"Azure SQL Data Warehouse"
"Azure SQL Data Warehouse",
"multi-root ready"
],
"activationEvents": [
"onLanguage:sql",
@ -427,7 +428,7 @@
}
}
},
"scope": "window"
"scope": "resource"
},
"mssql.shortcuts": {
"type": "object",

Просмотреть файл

@ -120,7 +120,7 @@ export class ConnectionConfig implements IConnectionConfig {
* @returns the set of connection profiles found in the settings.
*/
public getProfilesFromSettings(global: boolean = true): IConnectionProfile[] {
let configuration = this._vscodeWrapper.getConfiguration(Constants.extensionName);
let configuration = this._vscodeWrapper.getConfiguration(Constants.extensionName, this._vscodeWrapper.activeTextEditorUri);
let profiles: IConnectionProfile[] = [];
let configValue = configuration.inspect<IConnectionProfile[]>(Constants.connectionsArrayName);
@ -128,6 +128,11 @@ export class ConnectionConfig implements IConnectionConfig {
profiles = configValue.globalValue;
} else {
profiles = configValue.workspaceValue;
if (profiles !== undefined) {
profiles = profiles.concat(configValue.workspaceFolderValue || []);
} else {
profiles = configValue.workspaceFolderValue;
}
}
if (profiles === undefined) {

Просмотреть файл

@ -266,6 +266,11 @@ suite('ConnectionStore tests', () => {
workspaceConfiguration.update('connections', [defaultNamedProfile, unnamedProfile, namedProfile]);
let updatedCredentials: interfaces.IConnectionProfile[];
vscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(x => {
return workspaceConfiguration;
});
let config = new ConnectionConfig(vscodeWrapper.object);
credentialStore.setup(x => x.deleteCredential(TypeMoq.It.isAny()))
@ -301,6 +306,11 @@ suite('ConnectionStore tests', () => {
let updatedCredentials: interfaces.IConnectionProfile[];
vscodeWrapper.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(x => {
return workspaceConfiguration;
});
let config = new ConnectionConfig(vscodeWrapper.object);
credentialStore.setup(x => x.deleteCredential(TypeMoq.It.isAny()))

Просмотреть файл

@ -37,7 +37,7 @@ suite('ConnectionConfig tests', () => {
let configResult: {[key: string]: any} = {};
configResult[Constants.connectionsArrayName] = connections;
workspaceConfiguration = stubs.createWorkspaceConfiguration(configResult);
vscodeWrapperMock.setup(x => x.getConfiguration(TypeMoq.It.isAny()))
vscodeWrapperMock.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(x => {
return workspaceConfiguration;
});
@ -59,4 +59,36 @@ suite('ConnectionConfig tests', () => {
// Verify that no error message was displayed to the user
vscodeWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
});
test('getProfilesFromSettings displays connections from resource settings', () => {
/// Set up the resource setting config to contain its own connection
let vscodeWrapperMock = TypeMoq.Mock.ofType(VscodeWrapper);
let workspaceConfiguration: vscode.WorkspaceConfiguration;
let configResult: {[key: string]: any} = {};
configResult[Constants.connectionsArrayName] = connections;
let resourceProfile = {
server: 'testpc',
database: 'testdb',
user: 'testuser',
password: 'abcd',
authenticationType: 'SqlLogin',
profileName: 'resourceProfile'
};
configResult[Constants.configMyConnections] = [resourceProfile];
workspaceConfiguration = stubs.createWorkspaceConfiguration(configResult);
vscodeWrapperMock.setup(x => x.getConfiguration(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(x => {
return workspaceConfiguration;
});
// Given a connection config object that reads a valid json file
let config = new ConnectionConfig(vscodeWrapperMock.object);
let profiles: IConnectionProfile[] = config.getProfilesFromSettings();
// Verify that a profile matches the one read from the resource config
assert.ok(profiles.some(profile => profile === resourceProfile));
// Verify that no error message was displayed to the user
vscodeWrapperMock.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.never());
});
});