mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Final ADS-side hookup for sqlcmd vars (#10815)
* Adding reading SqlCmdVars from project file * organized apiWrapper, added calls * Adding test to confirm deployment/script gen profiles with sqlcmd vars
This commit is contained in:
@@ -11,26 +11,98 @@ import * as azdata from 'azdata';
|
|||||||
* this API from our code
|
* this API from our code
|
||||||
*/
|
*/
|
||||||
export class ApiWrapper {
|
export class ApiWrapper {
|
||||||
public createOutputChannel(name: string): vscode.OutputChannel {
|
//#region azdata.accounts
|
||||||
return vscode.window.createOutputChannel(name);
|
|
||||||
|
public getAllAccounts(): Thenable<azdata.Account[]> {
|
||||||
|
return azdata.accounts.getAllAccounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public createTerminalWithOptions(options: vscode.TerminalOptions): vscode.Terminal {
|
public getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{ [key: string]: any }> {
|
||||||
return vscode.window.createTerminal(options);
|
return azdata.accounts.getSecurityToken(account, resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region azdata.connection
|
||||||
|
|
||||||
public getCurrentConnection(): Thenable<azdata.connection.ConnectionProfile> {
|
public getCurrentConnection(): Thenable<azdata.connection.ConnectionProfile> {
|
||||||
return azdata.connection.getCurrentConnection();
|
return azdata.connection.getCurrentConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public openConnectionDialog(): Thenable<azdata.connection.Connection> {
|
public openConnectionDialog(providers?: string[],
|
||||||
return azdata.connection.openConnectionDialog();
|
initialConnectionProfile?: azdata.IConnectionProfile,
|
||||||
|
connectionCompletionOptions?: azdata.IConnectionCompletionOptions): Thenable<azdata.connection.Connection> {
|
||||||
|
return azdata.connection.openConnectionDialog(providers, initialConnectionProfile, connectionCompletionOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCredentials(connectionId: string): Thenable<{ [name: string]: string }> {
|
public getCredentials(connectionId: string): Thenable<{ [name: string]: string }> {
|
||||||
return azdata.connection.getCredentials(connectionId);
|
return azdata.connection.getCredentials(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public connectionConnect(connectionProfile: azdata.IConnectionProfile, saveConnection?: boolean, showDashboard?: boolean): Thenable<azdata.ConnectionResult> {
|
||||||
|
return azdata.connection.connect(connectionProfile, saveConnection, showDashboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getUriForConnection(connectionId: string): Thenable<string> {
|
||||||
|
return azdata.connection.getUriForConnection(connectionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public listDatabases(connectionId: string): Thenable<string[]> {
|
||||||
|
return azdata.connection.listDatabases(connectionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region azdata.dataprotocol
|
||||||
|
|
||||||
|
public getProvider<T extends azdata.DataProvider>(providerId: string, providerType: azdata.DataProviderType): T {
|
||||||
|
return azdata.dataprotocol.getProvider<T>(providerId, providerType);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region azdata.queryeditor
|
||||||
|
|
||||||
|
public connect(fileUri: string, connectionId: string): Thenable<void> {
|
||||||
|
return azdata.queryeditor.connect(fileUri, connectionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public runQuery(fileUri: string, options?: Map<string, string>, runCurrentQuery?: boolean): void {
|
||||||
|
azdata.queryeditor.runQuery(fileUri, options, runCurrentQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region azdata.tasks
|
||||||
|
|
||||||
|
public registerTaskHandler(taskId: string, handler: (profile: azdata.IConnectionProfile) => void): void {
|
||||||
|
azdata.tasks.registerTask(taskId, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public startBackgroundOperation(operationInfo: azdata.BackgroundOperationInfo): void {
|
||||||
|
azdata.tasks.startBackgroundOperation(operationInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region azdata.ui
|
||||||
|
|
||||||
|
public registerWidget(widgetId: string, handler: (view: azdata.ModelView) => void): void {
|
||||||
|
azdata.ui.registerModelViewProvider(widgetId, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region azdata.window
|
||||||
|
|
||||||
|
public closeDialog(dialog: azdata.window.Dialog) {
|
||||||
|
azdata.window.closeDialog(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region vscode.commands
|
||||||
|
|
||||||
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
|
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
|
||||||
return vscode.commands.registerCommand(command, callback, thisArg);
|
return vscode.commands.registerCommand(command, callback, thisArg);
|
||||||
}
|
}
|
||||||
@@ -39,26 +111,38 @@ export class ApiWrapper {
|
|||||||
return vscode.commands.executeCommand(command, ...rest);
|
return vscode.commands.executeCommand(command, ...rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerTaskHandler(taskId: string, handler: (profile: azdata.IConnectionProfile) => void): void {
|
//#endregion
|
||||||
azdata.tasks.registerTask(taskId, handler);
|
|
||||||
|
//#region vscode.env
|
||||||
|
|
||||||
|
public openExternal(target: vscode.Uri): Thenable<boolean> {
|
||||||
|
return vscode.env.openExternal(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region vscode.extensions
|
||||||
|
|
||||||
|
public getExtension(extensionId: string): vscode.Extension<any> | undefined {
|
||||||
|
return vscode.extensions.getExtension(extensionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region vscode.window
|
||||||
|
|
||||||
|
public createOutputChannel(name: string): vscode.OutputChannel {
|
||||||
|
return vscode.window.createOutputChannel(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public createTerminalWithOptions(options: vscode.TerminalOptions): vscode.Terminal {
|
||||||
|
return vscode.window.createTerminal(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerTreeDataProvider<T>(viewId: string, treeDataProvider: vscode.TreeDataProvider<T>): vscode.Disposable {
|
public registerTreeDataProvider<T>(viewId: string, treeDataProvider: vscode.TreeDataProvider<T>): vscode.Disposable {
|
||||||
return vscode.window.registerTreeDataProvider(viewId, treeDataProvider);
|
return vscode.window.registerTreeDataProvider(viewId, treeDataProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createTreeView<T>(viewId: string, options: vscode.TreeViewOptions<T>): vscode.TreeView<T> {
|
|
||||||
return vscode.window.createTreeView(viewId, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getUriForConnection(connectionId: string): Thenable<string> {
|
|
||||||
return azdata.connection.getUriForConnection(connectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getProvider<T extends azdata.DataProvider>(providerId: string, providerType: azdata.DataProviderType): T {
|
|
||||||
return azdata.dataprotocol.getProvider<T>(providerId, providerType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
public showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
||||||
return vscode.window.showErrorMessage(message, ...items);
|
return vscode.window.showErrorMessage(message, ...items);
|
||||||
}
|
}
|
||||||
@@ -75,26 +159,6 @@ export class ApiWrapper {
|
|||||||
return vscode.window.showOpenDialog(options);
|
return vscode.window.showOpenDialog(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public startBackgroundOperation(operationInfo: azdata.BackgroundOperationInfo): void {
|
|
||||||
azdata.tasks.startBackgroundOperation(operationInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public openExternal(target: vscode.Uri): Thenable<boolean> {
|
|
||||||
return vscode.env.openExternal(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getExtension(extensionId: string): vscode.Extension<any> | undefined {
|
|
||||||
return vscode.extensions.getExtension(extensionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getConfiguration(section?: string, resource?: vscode.Uri | null): vscode.WorkspaceConfiguration {
|
|
||||||
return vscode.workspace.getConfiguration(section, resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public workspaceFolders(): readonly vscode.WorkspaceFolder[] | undefined {
|
|
||||||
return vscode.workspace.workspaceFolders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTab(title: string): azdata.window.DialogTab {
|
public createTab(title: string): azdata.window.DialogTab {
|
||||||
return azdata.window.createTab(title);
|
return azdata.window.createTab(title);
|
||||||
}
|
}
|
||||||
@@ -115,14 +179,6 @@ export class ApiWrapper {
|
|||||||
return azdata.window.openDialog(dialog);
|
return azdata.window.openDialog(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllAccounts(): Thenable<azdata.Account[]> {
|
|
||||||
return azdata.accounts.getAllAccounts();
|
|
||||||
}
|
|
||||||
|
|
||||||
public getSecurityToken(account: azdata.Account, resource: azdata.AzureResource): Thenable<{ [key: string]: any }> {
|
|
||||||
return azdata.accounts.getSecurityToken(account, resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
public showQuickPick<T extends vscode.QuickPickItem>(items: T[] | Thenable<T[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<T | undefined> {
|
public showQuickPick<T extends vscode.QuickPickItem>(items: T[] | Thenable<T[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<T | undefined> {
|
||||||
return vscode.window.showQuickPick(items, options, token);
|
return vscode.window.showQuickPick(items, options, token);
|
||||||
}
|
}
|
||||||
@@ -135,22 +191,6 @@ export class ApiWrapper {
|
|||||||
return vscode.window.showSaveDialog(options);
|
return vscode.window.showSaveDialog(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public listDatabases(connectionId: string): Thenable<string[]> {
|
|
||||||
return azdata.connection.listDatabases(connectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public openTextDocument(options?: { language?: string; content?: string; }): Thenable<vscode.TextDocument> {
|
|
||||||
return vscode.workspace.openTextDocument(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public connect(fileUri: string, connectionId: string): Thenable<void> {
|
|
||||||
return azdata.queryeditor.connect(fileUri, connectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public runQuery(fileUri: string, options?: Map<string, string>, runCurrentQuery?: boolean): void {
|
|
||||||
azdata.queryeditor.runQuery(fileUri, options, runCurrentQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
public showTextDocument(uri: vscode.Uri, options?: vscode.TextDocumentShowOptions): Thenable<vscode.TextEditor> {
|
public showTextDocument(uri: vscode.Uri, options?: vscode.TextDocumentShowOptions): Thenable<vscode.TextEditor> {
|
||||||
return vscode.window.showTextDocument(uri, options);
|
return vscode.window.showTextDocument(uri, options);
|
||||||
}
|
}
|
||||||
@@ -159,7 +199,25 @@ export class ApiWrapper {
|
|||||||
return azdata.window.createButton(label, position);
|
return azdata.window.createButton(label, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerWidget(widgetId: string, handler: (view: azdata.ModelView) => void): void {
|
public createTreeView<T>(viewId: string, options: vscode.TreeViewOptions<T>): vscode.TreeView<T> {
|
||||||
azdata.ui.registerModelViewProvider(widgetId, handler);
|
return vscode.window.createTreeView(viewId, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region vscode.workspace
|
||||||
|
|
||||||
|
public getConfiguration(section?: string, resource?: vscode.Uri | null): vscode.WorkspaceConfiguration {
|
||||||
|
return vscode.workspace.getConfiguration(section, resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public workspaceFolders(): readonly vscode.WorkspaceFolder[] | undefined {
|
||||||
|
return vscode.workspace.workspaceFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public openTextDocument(options?: { language?: string; content?: string; }): Thenable<vscode.TextDocument> {
|
||||||
|
return vscode.workspace.openTextDocument(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ export const Files = 'Files';
|
|||||||
export const PackageReference = 'PackageReference';
|
export const PackageReference = 'PackageReference';
|
||||||
export const Version = 'Version';
|
export const Version = 'Version';
|
||||||
export const PrivateAssets = 'PrivateAssets';
|
export const PrivateAssets = 'PrivateAssets';
|
||||||
|
export const SqlCmdVariable = 'SqlCmdVariable';
|
||||||
|
export const DefaultValue = 'DefaultValue';
|
||||||
export const ArtifactReference = 'ArtifactReference';
|
export const ArtifactReference = 'ArtifactReference';
|
||||||
export const SuppressMissingDependenciesErrors = 'SuppressMissingDependenciesErrors';
|
export const SuppressMissingDependenciesErrors = 'SuppressMissingDependenciesErrors';
|
||||||
export const DatabaseVariableLiteralValue = 'DatabaseVariableLiteralValue';
|
export const DatabaseVariableLiteralValue = 'DatabaseVariableLiteralValue';
|
||||||
|
|||||||
@@ -136,10 +136,10 @@ export class DeployDatabaseDialog {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (dataSource.integratedSecurity) {
|
if (dataSource.integratedSecurity) {
|
||||||
connId = (await azdata.connection.connect(connProfile, false, false)).connectionId;
|
connId = (await this.apiWrapper.connectionConnect(connProfile, false, false)).connectionId;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
connId = (await azdata.connection.openConnectionDialog(undefined, connProfile)).connectionId;
|
connId = (await this.apiWrapper.openConnectionDialog(undefined, connProfile)).connectionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -150,7 +150,7 @@ export class DeployDatabaseDialog {
|
|||||||
connId = this.connection?.connectionId;
|
connId = this.connection?.connectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await azdata.connection.getUriForConnection(connId);
|
return await this.apiWrapper.getUriForConnection(connId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deployClick(): Promise<void> {
|
public async deployClick(): Promise<void> {
|
||||||
@@ -161,7 +161,7 @@ export class DeployDatabaseDialog {
|
|||||||
sqlCmdVariables: this.project.sqlCmdVariables
|
sqlCmdVariables: this.project.sqlCmdVariables
|
||||||
};
|
};
|
||||||
|
|
||||||
azdata.window.closeDialog(this.dialog);
|
this.apiWrapper.closeDialog(this.dialog);
|
||||||
await this.deploy!(this.project, profile);
|
await this.deploy!(this.project, profile);
|
||||||
|
|
||||||
this.dispose();
|
this.dispose();
|
||||||
@@ -170,10 +170,11 @@ export class DeployDatabaseDialog {
|
|||||||
public async generateScriptClick(): Promise<void> {
|
public async generateScriptClick(): Promise<void> {
|
||||||
const profile: IGenerateScriptProfile = {
|
const profile: IGenerateScriptProfile = {
|
||||||
databaseName: this.getTargetDatabaseName(),
|
databaseName: this.getTargetDatabaseName(),
|
||||||
connectionUri: await this.getConnectionUri()
|
connectionUri: await this.getConnectionUri(),
|
||||||
|
sqlCmdVariables: this.project.sqlCmdVariables
|
||||||
};
|
};
|
||||||
|
|
||||||
azdata.window.closeDialog(this.dialog);
|
this.apiWrapper.closeDialog(this.dialog);
|
||||||
|
|
||||||
if (this.generateScript) {
|
if (this.generateScript) {
|
||||||
await this.generateScript!(this.project, profile);
|
await this.generateScript!(this.project, profile);
|
||||||
@@ -182,7 +183,7 @@ export class DeployDatabaseDialog {
|
|||||||
this.dispose();
|
this.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTargetDatabaseName(): string {
|
public getTargetDatabaseName(): string {
|
||||||
return this.targetDatabaseTextBox?.value ?? '';
|
return this.targetDatabaseTextBox?.value ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,15 @@ export class Project {
|
|||||||
this.importedTargets.push(importTarget.getAttribute(constants.Project));
|
this.importedTargets.push(importTarget.getAttribute(constants.Project));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find all SQLCMD variables to include
|
||||||
|
for (let i = 0; i < this.projFileXmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable).length; i++) {
|
||||||
|
const sqlCmdVar = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable)[i];
|
||||||
|
const varName = sqlCmdVar.getAttribute(constants.Include);
|
||||||
|
|
||||||
|
const varValue = sqlCmdVar.getElementsByTagName(constants.DefaultValue)[0].childNodes[0].nodeValue;
|
||||||
|
this.sqlCmdVariables[varName] = varValue;
|
||||||
|
}
|
||||||
|
|
||||||
// find all database references to include
|
// find all database references to include
|
||||||
for (let r = 0; r < this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference).length; r++) {
|
for (let r = 0; r < this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference).length; r++) {
|
||||||
const filepath = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference)[r].getAttribute(constants.Include);
|
const filepath = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference)[r].getAttribute(constants.Include);
|
||||||
|
|||||||
@@ -73,6 +73,16 @@
|
|||||||
<Folder Include="Views\User" />
|
<Folder Include="Views\User" />
|
||||||
<Build Include="Views\User\Profile.sql" />
|
<Build Include="Views\User\Profile.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<SqlCmdVariable Include="ProdDatabaseName">
|
||||||
|
<DefaultValue>MyProdDatabase</DefaultValue>
|
||||||
|
<Value>$(SqlCmdVar__1)</Value>
|
||||||
|
</SqlCmdVariable>
|
||||||
|
<SqlCmdVariable Include="BackupDatabaseName">
|
||||||
|
<DefaultValue>MyBackupDatabase</DefaultValue>
|
||||||
|
<Value>$(SqlCmdVar__2)</Value>
|
||||||
|
</SqlCmdVariable>
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\130\master.dacpac">
|
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\130\master.dacpac">
|
||||||
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
||||||
|
|||||||
@@ -9,22 +9,29 @@ import * as os from 'os';
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as baselines from './baselines/baselines';
|
import * as baselines from './baselines/baselines';
|
||||||
import * as templates from '../templates/templates';
|
import * as templates from '../templates/templates';
|
||||||
|
import * as testUtils from '../test/testUtils';
|
||||||
|
import * as TypeMoq from 'typemoq';
|
||||||
|
|
||||||
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
||||||
import { Project } from '../models/project';
|
import { Project } from '../models/project';
|
||||||
import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProjectTreeViewProvider';
|
import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProjectTreeViewProvider';
|
||||||
import { ProjectsController } from '../controllers/projectController';
|
import { ProjectsController } from '../controllers/projectController';
|
||||||
import { createContext, TestContext } from './testContext';
|
import { createContext, TestContext } from './testContext';
|
||||||
|
import { IDeploymentProfile, IGenerateScriptProfile } from '../models/IDeploymentProfile';
|
||||||
|
|
||||||
|
|
||||||
let testContext: TestContext;
|
let testContext: TestContext;
|
||||||
|
|
||||||
describe('Deploy Database Dialog', () => {
|
describe('Deploy Database Dialog', () => {
|
||||||
before(async function (): Promise<void> {
|
before(async function (): Promise<void> {
|
||||||
testContext = createContext();
|
|
||||||
await templates.loadTemplates(path.join(__dirname, '..', '..', 'resources', 'templates'));
|
await templates.loadTemplates(path.join(__dirname, '..', '..', 'resources', 'templates'));
|
||||||
await baselines.loadBaselines();
|
await baselines.loadBaselines();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(async function (): Promise<void> {
|
||||||
|
testContext = createContext();
|
||||||
|
});
|
||||||
|
|
||||||
it('Should open dialog successfully ', async function (): Promise<void> {
|
it('Should open dialog successfully ', async function (): Promise<void> {
|
||||||
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||||
@@ -47,4 +54,43 @@ describe('Deploy Database Dialog', () => {
|
|||||||
const deployDatabaseDialog = new DeployDatabaseDialog(testContext.apiWrapper.object, project);
|
const deployDatabaseDialog = new DeployDatabaseDialog(testContext.apiWrapper.object, project);
|
||||||
should.equal(deployDatabaseDialog.getDefaultDatabaseName(), project.projectFileName);
|
should.equal(deployDatabaseDialog.getDefaultDatabaseName(), project.projectFileName);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should include all info in deployment profile', async function (): Promise<void> {
|
||||||
|
const proj = await testUtils.createTestProject(baselines.openProjectFileBaseline);
|
||||||
|
const dialog = TypeMoq.Mock.ofType(DeployDatabaseDialog, undefined, undefined, testContext.apiWrapper.object, proj);
|
||||||
|
dialog.setup(x => x.getConnectionUri()).returns(async () => { return 'Mock|Connection|Uri'; });
|
||||||
|
dialog.setup(x => x.getTargetDatabaseName()).returns(() => 'MockDatabaseName');
|
||||||
|
dialog.callBase = true;
|
||||||
|
|
||||||
|
let profile: IDeploymentProfile | IGenerateScriptProfile | undefined;
|
||||||
|
|
||||||
|
const expectedDeploy: IDeploymentProfile = {
|
||||||
|
databaseName: 'MockDatabaseName',
|
||||||
|
connectionUri: 'Mock|Connection|Uri',
|
||||||
|
upgradeExisting: true,
|
||||||
|
sqlCmdVariables: {
|
||||||
|
'ProdDatabaseName': 'MyProdDatabase',
|
||||||
|
'BackupDatabaseName': 'MyBackupDatabase'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.object.deploy = async (_, prof) => { profile = prof; };
|
||||||
|
await dialog.object.deployClick();
|
||||||
|
|
||||||
|
should(profile).deepEqual(expectedDeploy);
|
||||||
|
|
||||||
|
const expectedGenScript: IGenerateScriptProfile = {
|
||||||
|
databaseName: 'MockDatabaseName',
|
||||||
|
connectionUri: 'Mock|Connection|Uri',
|
||||||
|
sqlCmdVariables: {
|
||||||
|
'ProdDatabaseName': 'MyProdDatabase',
|
||||||
|
'BackupDatabaseName': 'MyBackupDatabase'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog.object.generateScript = async (_, prof) => { profile = prof; };
|
||||||
|
await dialog.object.generateScriptClick();
|
||||||
|
|
||||||
|
should(profile).deepEqual(expectedGenScript);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,12 +31,19 @@ describe('Project: sqlproj content operations', function (): void {
|
|||||||
const project: Project = new Project(projFilePath);
|
const project: Project = new Project(projFilePath);
|
||||||
await project.readProjFile();
|
await project.readProjFile();
|
||||||
|
|
||||||
|
// Files and folders
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(4);
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(4);
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(5);
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(5);
|
||||||
|
|
||||||
should(project.files.find(f => f.type === EntryType.Folder && f.relativePath === 'Views\\User')).not.equal(undefined); // mixed ItemGroup folder
|
should(project.files.find(f => f.type === EntryType.Folder && f.relativePath === 'Views\\User')).not.equal(undefined); // mixed ItemGroup folder
|
||||||
should(project.files.find(f => f.type === EntryType.File && f.relativePath === 'Views\\User\\Profile.sql')).not.equal(undefined); // mixed ItemGroup file
|
should(project.files.find(f => f.type === EntryType.File && f.relativePath === 'Views\\User\\Profile.sql')).not.equal(undefined); // mixed ItemGroup file
|
||||||
|
|
||||||
|
// SqlCmdVariables
|
||||||
|
should(Object.keys(project.sqlCmdVariables).length).equal(2);
|
||||||
|
should(project.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
|
||||||
|
should(project.sqlCmdVariables['BackupDatabaseName']).equal('MyBackupDatabase');
|
||||||
|
|
||||||
|
// Database references
|
||||||
should(project.databaseReferences.length).equal(1);
|
should(project.databaseReferences.length).equal(1);
|
||||||
should(project.databaseReferences[0]).containEql(constants.master);
|
should(project.databaseReferences[0]).containEql(constants.master);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ export async function createTestSqlProjFile(contents: string, folderPath?: strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createTestProject(contents: string, folderPath?: string): Promise<Project> {
|
export async function createTestProject(contents: string, folderPath?: string): Promise<Project> {
|
||||||
return new Project(await createTestSqlProjFile(contents, folderPath));
|
const proj = new Project(await createTestSqlProjFile(contents, folderPath));
|
||||||
|
await proj.readProjFile();
|
||||||
|
|
||||||
|
return proj;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createTestDataSources(contents: string, folderPath?: string): Promise<string> {
|
export async function createTestDataSources(contents: string, folderPath?: string): Promise<string> {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ describe('Tests for conversion within PascalCase and camelCase', function (): vo
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Tests to verify exists function', function (): void {
|
describe('Tests to verify exists function', function (): void {
|
||||||
it('Should determine existance of files/folders', async () => {
|
it('Should determine existence of files/folders', async () => {
|
||||||
let testFolderPath = await createDummyFileStructure();
|
let testFolderPath = await createDummyFileStructure();
|
||||||
|
|
||||||
should(await exists(testFolderPath)).equal(true);
|
should(await exists(testFolderPath)).equal(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user