Add a few unit tests for dacpac extension (#9194)

* add a few unit tests

* fix tests for linux
This commit is contained in:
Kim Santiago
2020-02-24 10:01:30 -08:00
committed by GitHub
parent 10b681b3c8
commit 9090143f9d
9 changed files with 247 additions and 136 deletions

View File

@@ -12,7 +12,7 @@ export abstract class BasePage {
protected readonly wizardPage: azdata.window.WizardPage;
protected readonly model: DacFxDataModel;
protected readonly view: azdata.ModelView;
protected databaseValues: string[];
public databaseValues: string[];
/**
* This method constructs all the elements of the page.

View File

@@ -207,7 +207,7 @@ export abstract class DacFxConfigPage extends BasePage {
}
// Compares database name with existing databases on the server
protected databaseNameExists(n: string): boolean {
public databaseNameExists(n: string): boolean {
for (let i = 0; i < this.databaseValues.length; ++i) {
if (this.databaseValues[i].toLowerCase() === n.toLowerCase()) {
// database name exists

View File

@@ -120,7 +120,7 @@ export function isValidBasenameErrorMessage(name: string | null | undefined): st
}
if (basename === '.' || basename === '..') {
return loc.reservedWindowsFilenameErrorMessage; // check for reserved values
return loc.reservedValueErrorMessage; // check for reserved values
}
if (isWindows && basename.length !== basename.trim().length) {
@@ -133,3 +133,7 @@ export function isValidBasenameErrorMessage(name: string | null | undefined): st
return '';
}
export function generateDatabaseName(filePath: string): string {
return path.parse(filePath).name;
}

View File

@@ -84,6 +84,7 @@ export class DataTierApplicationWizard {
public selectedOperation: Operation;
constructor() {
this.wizard = azdata.window.createWizard(loc.wizardTitle);
}
public async start(p: any, ...args: any[]) {
@@ -107,8 +108,16 @@ export class DataTierApplicationWizard {
}
this.model.serverId = this.connection.connectionId;
this.setPages();
this.wizard = azdata.window.createWizard(loc.wizardTitle);
this.wizard.generateScriptButton.hidden = true;
this.wizard.generateScriptButton.onClick(async () => await this.generateDeployScript());
this.wizard.doneButton.onClick(async () => await this.executeOperation());
this.wizard.open();
}
public setPages(): void {
let selectOperationWizardPage = azdata.window.createWizardPage(loc.selectOperationPageName);
let deployConfigWizardPage = azdata.window.createWizardPage(loc.deployConfigPageName);
let deployPlanWizardPage = azdata.window.createWizardPage(loc.deployPlanPageName);
@@ -186,11 +195,6 @@ export class DataTierApplicationWizard {
});
this.wizard.pages = [selectOperationWizardPage, deployConfigWizardPage, deployPlanWizardPage, summaryWizardPage];
this.wizard.generateScriptButton.hidden = true;
this.wizard.generateScriptButton.onClick(async () => await this.generateDeployScript());
this.wizard.doneButton.onClick(async () => await this.executeOperation());
this.wizard.open();
}
public registerNavigationValidator(validator: (pageChangeInfo: azdata.window.WizardPageChangeInfo) => boolean) {

View File

@@ -5,11 +5,11 @@
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as path from 'path';
import * as loc from '../../localizedConstants';
import { DacFxDataModel } from '../api/models';
import { DataTierApplicationWizard, DeployOperationPath, Operation, DeployNewOperationPath, PageName } from '../dataTierApplicationWizard';
import { DacFxConfigPage } from '../api/dacFxConfigPage';
import { generateDatabaseName } from '../api/utils';
export class DeployConfigPage extends DacFxConfigPage {
@@ -88,7 +88,7 @@ export class DeployConfigPage extends DacFxConfigPage {
this.fileTextBox.onTextChanged(async () => {
this.model.filePath = this.fileTextBox.value;
this.databaseTextBox.value = this.generateDatabaseName(this.model.filePath);
this.databaseTextBox.value = generateDatabaseName(this.model.filePath);
if (!this.model.upgradeExisting) {
this.model.database = this.databaseTextBox.value;
}
@@ -200,9 +200,4 @@ export class DeployConfigPage extends DacFxConfigPage {
this.databaseLoader.loading = false;
return true;
}
private generateDatabaseName(filePath: string): string {
let result = path.parse(filePath);
return result.name;
}
}

View File

@@ -5,11 +5,11 @@
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as path from 'path';
import * as loc from '../../localizedConstants';
import { DacFxDataModel } from '../api/models';
import { DataTierApplicationWizard } from '../dataTierApplicationWizard';
import { DacFxConfigPage } from '../api/dacFxConfigPage';
import { generateDatabaseName } from '../api/utils';
export class ImportConfigPage extends DacFxConfigPage {
@@ -75,13 +75,13 @@ export class ImportConfigPage extends DacFxConfigPage {
let fileUri = fileUris[0];
this.fileTextBox.value = fileUri.fsPath;
this.model.filePath = fileUri.fsPath;
this.model.database = this.generateDatabaseName(this.model.filePath);
this.model.database = generateDatabaseName(this.model.filePath);
this.databaseTextBox.value = this.model.database;
});
this.fileTextBox.onTextChanged(async () => {
this.model.filePath = this.fileTextBox.value;
this.model.database = this.generateDatabaseName(this.model.filePath);
this.model.database = generateDatabaseName(this.model.filePath);
this.databaseTextBox.value = this.model.database;
});
@@ -91,9 +91,4 @@ export class ImportConfigPage extends DacFxConfigPage {
actions: [this.fileButton]
};
}
private generateDatabaseName(filePath: string): string {
let result = path.parse(filePath);
return result.name;
}
}