Add database name to attach to (if not connected to master) (#4076)

This commit is contained in:
Chris LaFreniere
2019-02-15 16:50:14 -10:00
committed by GitHub
parent f43b3508e9
commit d4ffe53dbd
3 changed files with 139 additions and 8 deletions

View File

@@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as should from 'should';
import { nb, IConnectionProfile } from 'sqlops';
import { CapabilitiesTestService } from 'sqltest/stubs/capabilitiesTestService';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { formatServerNameWithDatabaseNameForAttachTo, getServerFromFormattedAttachToName, getDatabaseFromFormattedAttachToName } from 'sql/parts/notebook/notebookUtils';
describe('notebookUtils', function(): void {
let conn: IConnectionProfile = {
connectionName: '',
serverName: '',
databaseName: '',
userName: '',
password: '',
authenticationType: '',
savePassword: true,
groupFullName: '',
groupId: '',
providerName: '',
saveProfile: true,
id: '',
options: {},
azureTenantId: undefined
};
it('Should format server and database name correctly for attach to', async function(): Promise<void> {
let capabilitiesService = new CapabilitiesTestService();
let connProfile = new ConnectionProfile(capabilitiesService, conn);
connProfile.serverName = 'serverName';
connProfile.databaseName = 'databaseName';
let attachToNameFormatted = formatServerNameWithDatabaseNameForAttachTo(connProfile);
should(attachToNameFormatted).equal('serverName (databaseName)');
});
it('Should format server name correctly for attach to', async function(): Promise<void> {
let capabilitiesService = new CapabilitiesTestService();
let connProfile = new ConnectionProfile(capabilitiesService, conn);
connProfile.serverName = 'serverName';
let attachToNameFormatted = formatServerNameWithDatabaseNameForAttachTo(connProfile);
should(attachToNameFormatted).equal('serverName');
});
it('Should format server name correctly for attach to when database is undefined', async function(): Promise<void> {
let capabilitiesService = new CapabilitiesTestService();
let connProfile = new ConnectionProfile(capabilitiesService, conn);
connProfile.serverName = 'serverName';
connProfile.databaseName = undefined;
let attachToNameFormatted = formatServerNameWithDatabaseNameForAttachTo(connProfile);
should(attachToNameFormatted).equal('serverName');
});
it('Should format server name as empty string when server/database are undefined', async function(): Promise<void> {
let capabilitiesService = new CapabilitiesTestService();
let connProfile = new ConnectionProfile(capabilitiesService, conn);
connProfile.serverName = undefined;
connProfile.databaseName = undefined;
let attachToNameFormatted = formatServerNameWithDatabaseNameForAttachTo(connProfile);
should(attachToNameFormatted).equal('');
});
it('Should extract server name when no database specified', async function(): Promise<void> {
let serverName = getServerFromFormattedAttachToName('serverName');
let databaseName = getDatabaseFromFormattedAttachToName('serverName');
should(serverName).equal('serverName');
should(databaseName).equal('');
});
it('Should extract server and database name', async function(): Promise<void> {
let serverName = getServerFromFormattedAttachToName('serverName (databaseName)');
let databaseName = getDatabaseFromFormattedAttachToName('serverName (databaseName)');
should(serverName).equal('serverName');
should(databaseName).equal('databaseName');
});
it('Should extract server and database name with other parentheses', async function(): Promise<void> {
let serverName = getServerFromFormattedAttachToName('serv()erName (databaseName)');
let databaseName = getDatabaseFromFormattedAttachToName('serv()erName (databaseName)');
should(serverName).equal('serv()erName');
should(databaseName).equal('databaseName');
});
});