Add connection API method to get URI (#2021)

This commit is contained in:
Matt Irvine
2018-07-30 10:52:24 -07:00
committed by GitHub
parent e9ef95ef1f
commit d2b6f6844d
10 changed files with 61 additions and 18 deletions

View File

@@ -756,8 +756,8 @@ suite('SQL ConnectionManagementService tests', () => {
connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
try {
// If I get the URI for the connection with or without a database from the connection management service
let actualUriWithDb = connectionManagementService.getConnectionId(connectionProfileWithDb);
let actualUriWithoutDb = connectionManagementService.getConnectionId(connectionProfileWithoutDb);
let actualUriWithDb = connectionManagementService.getConnectionUri(connectionProfileWithDb);
let actualUriWithoutDb = connectionManagementService.getConnectionUri(connectionProfileWithoutDb);
// Then the retrieved URIs should match the one on the connection
let expectedUri = Utils.generateUri(connectionProfileWithoutDb);
@@ -804,4 +804,33 @@ suite('SQL ConnectionManagementService tests', () => {
let credentials = connectionManagementService.getActiveConnectionCredentials(profile.id);
assert.equal(credentials['password'], profile.options['password']);
});
test('getConnectionUriFromId returns a URI of an active connection with the given id', () => {
let profile = Object.assign({}, connectionProfile);
profile.options = {password: profile.password};
profile.id = 'test_id';
let uri = 'test_initial_uri';
connectionStatusManager.addConnection(profile, uri);
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
// If I call getConnectionUriFromId on the given connection
let foundUri = connectionManagementService.getConnectionUriFromId(profile.id);
// Then the returned URI matches the connection's
assert.equal(foundUri, Utils.generateUri(new ConnectionProfile(capabilitiesService, profile)));
});
test('getConectionUriFromId returns undefined if the given connection is not active', () => {
let profile = Object.assign({}, connectionProfile);
profile.options = {password: profile.password};
profile.id = 'test_id';
connectionStatusManager.addConnection(profile, Utils.generateUri(profile));
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
// If I call getConnectionUriFromId with a different URI than the connection's
let foundUri = connectionManagementService.getConnectionUriFromId('different_id');
// Then undefined is returned
assert.equal(foundUri, undefined);
});
});

View File

@@ -115,7 +115,7 @@ export class TestConnectionManagementService implements IConnectionManagementSer
return [];
}
getConnectionId(connectionProfile: ConnectionProfile): string {
getConnectionUri(connectionProfile: ConnectionProfile): string {
return undefined;
}
@@ -123,6 +123,10 @@ export class TestConnectionManagementService implements IConnectionManagementSer
return undefined;
}
getConnectionUriFromId(connectionId: string): string {
return undefined;
}
isConnected(fileUri: string, connectionProfile?: ConnectionProfile): boolean {
return false;
}