mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 02:48:30 -05:00
Add more SsmsMin interactions (#5267)
* Add support for more SsmsMin property dialogs and the Generate Script Wizard. Also fixed bug with ExtHostObjectExplorerNode getParent function * Localize package.json entries * Fix localization tokens * Address PR comments * Fix regex and getParent
This commit is contained in:
@@ -8,11 +8,13 @@
|
||||
import * as should from 'should';
|
||||
import 'mocha';
|
||||
|
||||
import * as extensionMain from '../main';
|
||||
import { buildSsmsMinCommandArgs, buildUrn, LaunchSsmsDialogParams } from '../main';
|
||||
import { doubleEscapeSingleQuotes, backEscapeDoubleQuotes } from '../utils';
|
||||
import { ExtHostObjectExplorerNodeStub } from './stubs';
|
||||
|
||||
describe('buildSsmsMinCommandArgs Method Tests', () => {
|
||||
it('Should be built correctly with all params and UseAAD as false', function (): void {
|
||||
let params: extensionMain.LaunchSsmsDialogParams = {
|
||||
const params: LaunchSsmsDialogParams = {
|
||||
action: 'myAction',
|
||||
server: 'myServer',
|
||||
database: 'myDatabase',
|
||||
@@ -21,12 +23,12 @@ describe('buildSsmsMinCommandArgs Method Tests', () => {
|
||||
useAad: false,
|
||||
urn: 'Server\\Database\\Table'
|
||||
};
|
||||
let args = extensionMain.buildSsmsMinCommandArgs(params);
|
||||
const args = buildSsmsMinCommandArgs(params);
|
||||
should(args).equal('-a "myAction" -S "myServer" -D "myDatabase" -U "user" -u "Server\\Database\\Table"');
|
||||
});
|
||||
|
||||
it('Should be built correctly with all params and UseAAD as true', function (): void {
|
||||
let params: extensionMain.LaunchSsmsDialogParams = {
|
||||
const params: LaunchSsmsDialogParams = {
|
||||
action: 'myAction',
|
||||
server: 'myServer',
|
||||
database: 'myDatabase',
|
||||
@@ -35,13 +37,13 @@ describe('buildSsmsMinCommandArgs Method Tests', () => {
|
||||
useAad: true,
|
||||
urn: 'Server\\Database\\Table'
|
||||
};
|
||||
let args = extensionMain.buildSsmsMinCommandArgs(params);
|
||||
const args = buildSsmsMinCommandArgs(params);
|
||||
// User is omitted since UseAAD is true
|
||||
should(args).equal('-a "myAction" -S "myServer" -D "myDatabase" -G -u "Server\\Database\\Table"');
|
||||
});
|
||||
|
||||
it('Should be built correctly and names escaped correctly', function (): void {
|
||||
let params: extensionMain.LaunchSsmsDialogParams = {
|
||||
const params: LaunchSsmsDialogParams = {
|
||||
action: 'myAction\'"/\\[]tricky',
|
||||
server: 'myServer\'"/\\[]tricky',
|
||||
database: 'myDatabase\'"/\\[]tricky',
|
||||
@@ -50,18 +52,87 @@ describe('buildSsmsMinCommandArgs Method Tests', () => {
|
||||
useAad: true,
|
||||
urn: 'Server\\Database[\'myDatabase\'\'"/\\[]tricky\']\\Table["myTable\'""/\\[]tricky"]'
|
||||
};
|
||||
let args = extensionMain.buildSsmsMinCommandArgs(params);
|
||||
const args = buildSsmsMinCommandArgs(params);
|
||||
// User is omitted since UseAAD is true
|
||||
should(args).equal('-a "myAction\'\\"/\\[]tricky" -S "myServer\'\\"/\\[]tricky" -D "myDatabase\'\\"/\\[]tricky" -G -u "Server\\Database[\'myDatabase\'\'\\"/\\[]tricky\']\\Table[\\"myTable\'\\"\\"/\\[]tricky\\"]"');
|
||||
});
|
||||
|
||||
it('Should be built correctly with only action and server', function (): void {
|
||||
|
||||
let params: extensionMain.LaunchSsmsDialogParams = {
|
||||
const params: LaunchSsmsDialogParams = {
|
||||
action: 'myAction',
|
||||
server: 'myServer'
|
||||
};
|
||||
let args = extensionMain.buildSsmsMinCommandArgs(params);
|
||||
const args = buildSsmsMinCommandArgs(params);
|
||||
should(args).equal('-a "myAction" -S "myServer"');
|
||||
});
|
||||
});
|
||||
|
||||
const serverName = 'My\'Server';
|
||||
const escapedServerName = doubleEscapeSingleQuotes(serverName);
|
||||
const dbName = 'My\'Db';
|
||||
const escapedDbName = doubleEscapeSingleQuotes(dbName);
|
||||
const dbSchema = 'db\'sch';
|
||||
const escapedDbSchema = doubleEscapeSingleQuotes(dbSchema);
|
||||
const tableName = 'My\'Table';
|
||||
const escapedTableName = doubleEscapeSingleQuotes(tableName);
|
||||
const tableSchema = 'tbl\'sch';
|
||||
const escapedTableSchema = doubleEscapeSingleQuotes(tableSchema);
|
||||
|
||||
describe('buildUrn Method Tests', () => {
|
||||
it('Urn should be correct with just server', async function (): Promise<void> {
|
||||
should(await buildUrn(serverName, undefined)).equal(`Server[@Name=\'${escapedServerName}\']`);
|
||||
});
|
||||
|
||||
it('Urn should be correct with Server and only Databases folder', async function (): Promise<void> {
|
||||
const leafNode: ExtHostObjectExplorerNodeStub =
|
||||
new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined);
|
||||
should(await buildUrn(serverName, leafNode)).equal(`Server[@Name='${escapedServerName}']`);
|
||||
});
|
||||
|
||||
it('Urn should be correct with Server and Database node', async function (): Promise<void> {
|
||||
const leafNode: ExtHostObjectExplorerNodeStub =
|
||||
new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined)
|
||||
.createChild(dbName, dbSchema, 'Database');
|
||||
should(await buildUrn(serverName, leafNode)).equal(
|
||||
`Server[@Name='${escapedServerName}']/Database[@Name='${escapedDbName}' and @Schema='${escapedDbSchema}']`);
|
||||
});
|
||||
|
||||
it('Urn should be correct with Multiple levels of Nodes', async function (): Promise<void> {
|
||||
const rootNode: ExtHostObjectExplorerNodeStub =
|
||||
new ExtHostObjectExplorerNodeStub('Databases', undefined, 'Folder', undefined)
|
||||
.createChild(dbName, dbSchema, 'Database')
|
||||
.createChild('Tables', undefined, 'Folder')
|
||||
.createChild(tableName, tableSchema, 'Table');
|
||||
should(await buildUrn(serverName, rootNode)).equal(
|
||||
`Server[@Name='${escapedServerName}']/Database[@Name='${escapedDbName}' and @Schema='${escapedDbSchema}']/Table[@Name='${escapedTableName}' and @Schema='${escapedTableSchema}']`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('doubleEscapeSingleQuotes Method Tests', () => {
|
||||
it('Should return original string if no single quotes', function (): void {
|
||||
const testString: string = 'MyTestString';
|
||||
const ret = doubleEscapeSingleQuotes(testString);
|
||||
should(ret).equal(testString);
|
||||
});
|
||||
|
||||
it('Should return escaped original string if it contains single quotes', function (): void {
|
||||
const testString: string = 'MyTestString\'\'WithQuotes';
|
||||
const ret = doubleEscapeSingleQuotes(testString);
|
||||
should(ret).equal('MyTestString\'\'\'\'WithQuotes');
|
||||
});
|
||||
});
|
||||
|
||||
describe('backEscapeDoubleQuotes Method Tests', () => {
|
||||
it('Should return original string if no double quotes', function (): void {
|
||||
const testString: string = 'MyTestString';
|
||||
const ret = backEscapeDoubleQuotes(testString);
|
||||
should(ret).equal(testString);
|
||||
});
|
||||
|
||||
it('Should return escaped original string if it contains double quotes', function (): void {
|
||||
const testString: string = 'MyTestString\"\"WithQuotes';
|
||||
const ret = backEscapeDoubleQuotes(testString);
|
||||
should(ret).equal('MyTestString\\"\\"WithQuotes');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user