mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Adding unit tests for schema compare service (#13642)
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
/**
|
||||
* Wrapper class to act as a facade over VSCode and Data APIs and allow us to test / mock callbacks into
|
||||
* this API from our code
|
||||
*/
|
||||
export class ApiWrapper {
|
||||
public openConnectionDialog(providers?: string[],
|
||||
initialConnectionProfile?: azdata.IConnectionProfile,
|
||||
connectionCompletionOptions?: azdata.IConnectionCompletionOptions): Thenable<azdata.connection.Connection> {
|
||||
return azdata.connection.openConnectionDialog(providers, initialConnectionProfile, connectionCompletionOptions);
|
||||
}
|
||||
|
||||
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
|
||||
return vscode.commands.registerCommand(command, callback, thisArg);
|
||||
}
|
||||
|
||||
public getUriForConnection(connectionId: string): Thenable<string> {
|
||||
return azdata.connection.getUriForConnection(connectionId);
|
||||
}
|
||||
|
||||
public getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
|
||||
return azdata.connection.getConnections(activeConnectionsOnly);
|
||||
}
|
||||
|
||||
public connect(connectionProfile: azdata.IConnectionProfile, saveConnection?: boolean, showDashboard?: boolean): Thenable<azdata.ConnectionResult> {
|
||||
return azdata.connection.connect(connectionProfile, saveConnection, showDashboard);
|
||||
}
|
||||
|
||||
public showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
||||
return vscode.window.showErrorMessage(message, ...items);
|
||||
}
|
||||
|
||||
public showWarningMessage(message: string, options?: vscode.MessageOptions, ...items: string[]): Thenable<string | undefined> {
|
||||
if (options) {
|
||||
return vscode.window.showWarningMessage(message, options, ...items);
|
||||
}
|
||||
else {
|
||||
return vscode.window.showWarningMessage(message, ...items);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,10 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { ApiWrapper } from './common/apiWrapper';
|
||||
import { SchemaCompareMainWindow } from './schemaCompareMainWindow';
|
||||
|
||||
export async function activate(extensionContext: vscode.ExtensionContext): Promise<void> {
|
||||
vscode.commands.registerCommand('schemaCompare.start', async (context: any) => { await new SchemaCompareMainWindow(new ApiWrapper(), undefined, extensionContext).start(context); });
|
||||
vscode.commands.registerCommand('schemaCompare.start', async (context: any) => { await new SchemaCompareMainWindow(undefined, extensionContext).start(context); });
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
|
||||
@@ -14,7 +14,6 @@ import { TelemetryReporter, TelemetryViews } from './telemetry';
|
||||
import { getTelemetryErrorType, getEndpointName, verifyConnectionAndGetOwnerUri, getRootPath } from './utils';
|
||||
import { SchemaCompareDialog } from './dialogs/schemaCompareDialog';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { ApiWrapper } from './common/apiWrapper';
|
||||
|
||||
// Do not localize this, this is used to decide the icon for the editor.
|
||||
// TODO : In future icon should be decided based on language id (scmp) and not resource name
|
||||
@@ -69,7 +68,7 @@ export class SchemaCompareMainWindow {
|
||||
public sourceEndpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
public targetEndpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
|
||||
constructor(private apiWrapper: ApiWrapper, private schemaCompareService?: mssql.ISchemaCompareService, private extensionContext?: vscode.ExtensionContext) {
|
||||
constructor(private schemaCompareService?: mssql.ISchemaCompareService, private extensionContext?: vscode.ExtensionContext) {
|
||||
this.SchemaCompareActionMap = new Map<Number, string>();
|
||||
this.SchemaCompareActionMap[mssql.SchemaUpdateAction.Delete] = loc.deleteAction;
|
||||
this.SchemaCompareActionMap[mssql.SchemaUpdateAction.Change] = loc.changeAction;
|
||||
@@ -87,7 +86,7 @@ export class SchemaCompareMainWindow {
|
||||
let profile = context ? <azdata.IConnectionProfile>context.connectionProfile : undefined;
|
||||
let sourceDacpac = context as string;
|
||||
if (profile) {
|
||||
let ownerUri = await this.apiWrapper.getUriForConnection((profile.id));
|
||||
let ownerUri = await azdata.connection.getUriForConnection((profile.id));
|
||||
this.sourceEndpointInfo = {
|
||||
endpointType: mssql.SchemaCompareEndpointType.Database,
|
||||
serverDisplayName: `${profile.serverName} ${profile.userName}`,
|
||||
@@ -295,11 +294,11 @@ export class SchemaCompareMainWindow {
|
||||
}
|
||||
this.comparisonResult = await service.schemaCompare(this.operationId, this.sourceEndpointInfo, this.targetEndpointInfo, azdata.TaskExecutionMode.execute, this.deploymentOptions);
|
||||
if (!this.comparisonResult || !this.comparisonResult.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaComparisonFailed', undefined, getTelemetryErrorType(this.comparisonResult.errorMessage))
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaComparisonFailed', undefined, getTelemetryErrorType(this.comparisonResult?.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
operationId: this.comparisonResult.operationId
|
||||
}).send();
|
||||
this.apiWrapper.showErrorMessage(loc.compareErrorMessage(this.comparisonResult.errorMessage));
|
||||
vscode.window.showErrorMessage(loc.compareErrorMessage(this.comparisonResult?.errorMessage));
|
||||
return;
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaComparisonFinished')
|
||||
@@ -407,69 +406,76 @@ export class SchemaCompareMainWindow {
|
||||
this.tablelistenersToDispose.push(this.differencesTable.onCellAction(async (rowState) => {
|
||||
let checkboxState = <azdata.ICheckboxCellActionEventArgs>rowState;
|
||||
if (checkboxState) {
|
||||
// show an info notification the first time when trying to exclude to notify the user that it may take some time to calculate affected dependencies
|
||||
if (this.showIncludeExcludeWaitingMessage) {
|
||||
this.showIncludeExcludeWaitingMessage = false;
|
||||
vscode.window.showInformationMessage(loc.includeExcludeInfoMessage);
|
||||
}
|
||||
|
||||
let diff = this.comparisonResult.differences[checkboxState.row];
|
||||
const result = await service.schemaCompareIncludeExcludeNode(this.comparisonResult.operationId, diff, checkboxState.checked, azdata.TaskExecutionMode.execute);
|
||||
let checkboxesToChange = [];
|
||||
if (result.success) {
|
||||
this.saveExcludeState(checkboxState);
|
||||
|
||||
// dependencies could have been included or excluded as a result, so save their exclude states
|
||||
result.affectedDependencies.forEach(difference => {
|
||||
// find the row of the difference and set its checkbox
|
||||
const diffEntryKey = this.createDiffEntryKey(difference);
|
||||
if (this.diffEntryRowMap.has(diffEntryKey)) {
|
||||
const row = this.diffEntryRowMap.get(diffEntryKey);
|
||||
checkboxesToChange.push({ row: row, column: 2, columnName: 'Include', checked: difference.included });
|
||||
const dependencyCheckBoxState: azdata.ICheckboxCellActionEventArgs = {
|
||||
checked: difference.included,
|
||||
row: row,
|
||||
column: 2,
|
||||
columnName: undefined
|
||||
};
|
||||
this.saveExcludeState(dependencyCheckBoxState);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// failed because of dependencies
|
||||
if (result.blockingDependencies) {
|
||||
// show the first dependent that caused this to fail in the warning message
|
||||
const diffEntryName = this.createName(diff.sourceValue ? diff.sourceValue : diff.targetValue);
|
||||
const firstDependentName = this.createName(result.blockingDependencies[0].sourceValue ? result.blockingDependencies[0].sourceValue : result.blockingDependencies[0].targetValue);
|
||||
let cannotExcludeMessage: string;
|
||||
let cannotIncludeMessage: string;
|
||||
if (firstDependentName) {
|
||||
cannotExcludeMessage = loc.cannotExcludeMessageDependent(diffEntryName, firstDependentName);
|
||||
cannotIncludeMessage = loc.cannotIncludeMessageDependent(diffEntryName, firstDependentName);
|
||||
} else {
|
||||
cannotExcludeMessage = loc.cannotExcludeMessage(diffEntryName);
|
||||
cannotIncludeMessage = loc.cannotIncludeMessage(diffEntryName);
|
||||
}
|
||||
vscode.window.showWarningMessage(checkboxState.checked ? cannotIncludeMessage : cannotExcludeMessage);
|
||||
} else {
|
||||
vscode.window.showWarningMessage(result.errorMessage);
|
||||
}
|
||||
|
||||
// set checkbox back to previous state
|
||||
checkboxesToChange.push({ row: checkboxState.row, column: checkboxState.column, columnName: 'Include', checked: !checkboxState.checked });
|
||||
}
|
||||
|
||||
if (checkboxesToChange.length > 0) {
|
||||
this.differencesTable.updateCells = checkboxesToChange;
|
||||
}
|
||||
await this.applyIncludeExclude(checkboxState);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public async applyIncludeExclude(checkboxState: azdata.ICheckboxCellActionEventArgs): Promise<void> {
|
||||
const service = await this.getService();
|
||||
// show an info notification the first time when trying to exclude to notify the user that it may take some time to calculate affected dependencies
|
||||
if (this.showIncludeExcludeWaitingMessage) {
|
||||
this.showIncludeExcludeWaitingMessage = false;
|
||||
vscode.window.showInformationMessage(loc.includeExcludeInfoMessage);
|
||||
}
|
||||
|
||||
let diff = this.comparisonResult.differences[checkboxState.row];
|
||||
const result = await service.schemaCompareIncludeExcludeNode(this.comparisonResult.operationId, diff, checkboxState.checked, azdata.TaskExecutionMode.execute);
|
||||
let checkboxesToChange = [];
|
||||
if (result.success) {
|
||||
this.saveExcludeState(checkboxState);
|
||||
|
||||
// dependencies could have been included or excluded as a result, so save their exclude states
|
||||
result.affectedDependencies.forEach(difference => {
|
||||
// find the row of the difference and set its checkbox
|
||||
const diffEntryKey = this.createDiffEntryKey(difference);
|
||||
if (this.diffEntryRowMap.has(diffEntryKey)) {
|
||||
const row = this.diffEntryRowMap.get(diffEntryKey);
|
||||
checkboxesToChange.push({ row: row, column: 2, columnName: 'Include', checked: difference.included });
|
||||
const dependencyCheckBoxState: azdata.ICheckboxCellActionEventArgs = {
|
||||
checked: difference.included,
|
||||
row: row,
|
||||
column: 2,
|
||||
columnName: undefined
|
||||
};
|
||||
this.saveExcludeState(dependencyCheckBoxState);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// failed because of dependencies
|
||||
if (result.blockingDependencies) {
|
||||
// show the first dependent that caused this to fail in the warning message
|
||||
const diffEntryName = this.createName(diff.sourceValue ? diff.sourceValue : diff.targetValue);
|
||||
const firstDependentName = this.createName(result.blockingDependencies[0].sourceValue ? result.blockingDependencies[0].sourceValue : result.blockingDependencies[0].targetValue);
|
||||
let cannotExcludeMessage: string;
|
||||
let cannotIncludeMessage: string;
|
||||
if (firstDependentName) {
|
||||
cannotExcludeMessage = loc.cannotExcludeMessageDependent(diffEntryName, firstDependentName);
|
||||
cannotIncludeMessage = loc.cannotIncludeMessageDependent(diffEntryName, firstDependentName);
|
||||
} else {
|
||||
cannotExcludeMessage = loc.cannotExcludeMessage(diffEntryName);
|
||||
cannotIncludeMessage = loc.cannotIncludeMessage(diffEntryName);
|
||||
}
|
||||
vscode.window.showWarningMessage(checkboxState.checked ? cannotIncludeMessage : cannotExcludeMessage);
|
||||
} else {
|
||||
vscode.window.showWarningMessage(result.errorMessage);
|
||||
}
|
||||
|
||||
// set checkbox back to previous state
|
||||
checkboxesToChange.push({ row: checkboxState.row, column: checkboxState.column, columnName: 'Include', checked: !checkboxState.checked });
|
||||
}
|
||||
|
||||
if (checkboxesToChange.length > 0) {
|
||||
this.differencesTable.updateCells = checkboxesToChange;
|
||||
}
|
||||
}
|
||||
|
||||
// save state based on source name if present otherwise target name (parity with SSDT)
|
||||
private saveExcludeState(rowState: azdata.ICheckboxCellActionEventArgs) {
|
||||
if (rowState) {
|
||||
this.differencesTable.data[rowState.row][2] = rowState.checked;
|
||||
if (this.differencesTable.data[rowState.row]?.length > 2) {
|
||||
this.differencesTable.data[rowState.row][2] = rowState.checked;
|
||||
}
|
||||
let diff = this.comparisonResult.differences[rowState.row];
|
||||
let key = (diff.sourceValue && diff.sourceValue.length > 0) ? this.createName(diff.sourceValue) : this.createName(diff.targetValue);
|
||||
if (key) {
|
||||
@@ -647,7 +653,7 @@ export class SchemaCompareMainWindow {
|
||||
});
|
||||
}
|
||||
|
||||
private async cancelCompare() {
|
||||
public async cancelCompare() {
|
||||
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareCancelStarted')
|
||||
.withAdditionalProperties({
|
||||
@@ -691,28 +697,32 @@ export class SchemaCompareMainWindow {
|
||||
}).component();
|
||||
|
||||
this.generateScriptButton.onDidClick(async (click) => {
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareGenerateScriptStarted')
|
||||
.withAdditionalProperties({
|
||||
'startTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
const service = await this.getService();
|
||||
const result = await service.schemaCompareGenerateScript(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.script);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareGenerateScriptFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
vscode.window.showErrorMessage(loc.generateScriptErrorMessage(result.errorMessage));
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareGenerateScriptEnded')
|
||||
.withAdditionalProperties({
|
||||
'endTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
await this.generateScript();
|
||||
});
|
||||
}
|
||||
|
||||
public async generateScript(): Promise<void> {
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareGenerateScriptStarted')
|
||||
.withAdditionalProperties({
|
||||
'startTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
const service = await this.getService();
|
||||
const result = await service.schemaCompareGenerateScript(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.script);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareGenerateScriptFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
vscode.window.showErrorMessage(loc.generateScriptErrorMessage(result.errorMessage));
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareGenerateScriptEnded')
|
||||
.withAdditionalProperties({
|
||||
'endTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
}
|
||||
|
||||
private createOptionsButton(view: azdata.ModelView) {
|
||||
this.optionsButton = view.modelBuilder.button().withProperties({
|
||||
label: loc.options,
|
||||
@@ -741,43 +751,47 @@ export class SchemaCompareMainWindow {
|
||||
},
|
||||
}).component();
|
||||
|
||||
this.applyButton.onDidClick(async (click) => {
|
||||
await this.publishChanges();
|
||||
});
|
||||
}
|
||||
|
||||
public async publishChanges(): Promise<void> {
|
||||
|
||||
// need only yes button - since the modal dialog has a default cancel
|
||||
const yesString = loc.YesButtonText;
|
||||
this.applyButton.onDidClick(async (click) => {
|
||||
await vscode.window.showWarningMessage(loc.applyConfirmation, { modal: true }, yesString).then(async (result) => {
|
||||
if (result === yesString) {
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyStarted')
|
||||
.withAdditionalProperties({
|
||||
'startTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
|
||||
vscode.window.showWarningMessage(loc.applyConfirmation, { modal: true }, yesString).then(async (result) => {
|
||||
if (result === yesString) {
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyStarted')
|
||||
// disable apply and generate script buttons because the results are no longer valid after applying the changes
|
||||
this.setButtonsForRecompare();
|
||||
|
||||
const service = await this.getService();
|
||||
const result = await service.schemaComparePublishChanges(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.execute);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
'startTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
vscode.window.showErrorMessage(loc.applyErrorMessage(result.errorMessage));
|
||||
|
||||
// disable apply and generate script buttons because the results are no longer valid after applying the changes
|
||||
this.setButtonsForRecompare();
|
||||
|
||||
const service = await this.getService();
|
||||
const result = await service.schemaComparePublishChanges(this.comparisonResult.operationId, this.targetEndpointInfo.serverName, this.targetEndpointInfo.databaseName, azdata.TaskExecutionMode.execute);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
vscode.window.showErrorMessage(loc.applyErrorMessage(result.errorMessage));
|
||||
|
||||
// reenable generate script and apply buttons if apply failed
|
||||
this.generateScriptButton.enabled = true;
|
||||
this.generateScriptButton.title = loc.generateScriptEnabledMessage;
|
||||
this.applyButton.enabled = true;
|
||||
this.applyButton.title = loc.applyEnabledMessage;
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyEnded')
|
||||
.withAdditionalProperties({
|
||||
'endTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
// reenable generate script and apply buttons if apply failed
|
||||
this.generateScriptButton.enabled = true;
|
||||
this.generateScriptButton.title = loc.generateScriptEnabledMessage;
|
||||
this.applyButton.enabled = true;
|
||||
this.applyButton.title = loc.applyEnabledMessage;
|
||||
}
|
||||
});
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareApplyEnded')
|
||||
.withAdditionalProperties({
|
||||
'endTime': Date.now().toString(),
|
||||
'operationId': this.comparisonResult.operationId
|
||||
}).send();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -922,60 +936,64 @@ export class SchemaCompareMainWindow {
|
||||
}).component();
|
||||
|
||||
this.openScmpButton.onDidClick(async (click) => {
|
||||
TelemetryReporter.sendActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOpenScmpStarted');
|
||||
const rootPath = getRootPath();
|
||||
let fileUris = await vscode.window.showOpenDialog(
|
||||
{
|
||||
canSelectFiles: true,
|
||||
canSelectFolders: false,
|
||||
canSelectMany: false,
|
||||
defaultUri: vscode.Uri.file(rootPath),
|
||||
openLabel: loc.open,
|
||||
filters: {
|
||||
'scmp Files': ['scmp'],
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!fileUris || fileUris.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fileUri = fileUris[0];
|
||||
const service = await this.getService();
|
||||
let startTime = Date.now();
|
||||
const result = await service.schemaCompareOpenScmp(fileUri.fsPath);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.sendErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOpenScmpFailed', undefined, getTelemetryErrorType(result.errorMessage));
|
||||
vscode.window.showErrorMessage(loc.openScmpErrorMessage(result.errorMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
this.sourceEndpointInfo = await this.constructEndpointInfo(result.sourceEndpointInfo, loc.sourceTitle, this.apiWrapper);
|
||||
this.targetEndpointInfo = await this.constructEndpointInfo(result.targetEndpointInfo, loc.targetTitle, this.apiWrapper);
|
||||
|
||||
this.updateSourceAndTarget();
|
||||
this.setDeploymentOptions(result.deploymentOptions);
|
||||
this.scmpSourceExcludes = result.excludedSourceElements;
|
||||
this.scmpTargetExcludes = result.excludedTargetElements;
|
||||
this.sourceTargetSwitched = result.originalTargetName !== this.targetEndpointInfo.databaseName;
|
||||
|
||||
// clear out any old results
|
||||
this.resetForNewCompare();
|
||||
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOpenScmpEnded')
|
||||
.withAdditionalProperties({
|
||||
elapsedTime: (Date.now() - startTime).toString()
|
||||
}).send();
|
||||
await this.openScmp();
|
||||
});
|
||||
}
|
||||
|
||||
private async constructEndpointInfo(endpoint: mssql.SchemaCompareEndpointInfo, caller: string, apiWrapper: ApiWrapper): Promise<mssql.SchemaCompareEndpointInfo> {
|
||||
public async openScmp(): Promise<void> {
|
||||
TelemetryReporter.sendActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOpenScmpStarted');
|
||||
const rootPath = getRootPath();
|
||||
let fileUris = await vscode.window.showOpenDialog(
|
||||
{
|
||||
canSelectFiles: true,
|
||||
canSelectFolders: false,
|
||||
canSelectMany: false,
|
||||
defaultUri: vscode.Uri.file(rootPath),
|
||||
openLabel: loc.open,
|
||||
filters: {
|
||||
'scmp Files': ['scmp'],
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!fileUris || fileUris.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fileUri = fileUris[0];
|
||||
const service = await this.getService();
|
||||
let startTime = Date.now();
|
||||
const result = await service.schemaCompareOpenScmp(fileUri.fsPath);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.sendErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOpenScmpFailed', undefined, getTelemetryErrorType(result.errorMessage));
|
||||
vscode.window.showErrorMessage(loc.openScmpErrorMessage(result.errorMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
this.sourceEndpointInfo = await this.constructEndpointInfo(result.sourceEndpointInfo, loc.sourceTitle);
|
||||
this.targetEndpointInfo = await this.constructEndpointInfo(result.targetEndpointInfo, loc.targetTitle);
|
||||
|
||||
this.updateSourceAndTarget();
|
||||
this.setDeploymentOptions(result.deploymentOptions);
|
||||
this.scmpSourceExcludes = result.excludedSourceElements;
|
||||
this.scmpTargetExcludes = result.excludedTargetElements;
|
||||
this.sourceTargetSwitched = result.originalTargetName !== this.targetEndpointInfo.databaseName;
|
||||
|
||||
// clear out any old results
|
||||
this.resetForNewCompare();
|
||||
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOpenScmpEnded')
|
||||
.withAdditionalProperties({
|
||||
elapsedTime: (Date.now() - startTime).toString()
|
||||
}).send();
|
||||
}
|
||||
|
||||
private async constructEndpointInfo(endpoint: mssql.SchemaCompareEndpointInfo, caller: string): Promise<mssql.SchemaCompareEndpointInfo> {
|
||||
let ownerUri;
|
||||
let endpointInfo;
|
||||
if (endpoint && endpoint.endpointType === mssql.SchemaCompareEndpointType.Database) {
|
||||
// only set endpoint info if able to connect to the database
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(endpoint, caller, apiWrapper);
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(endpoint, caller);
|
||||
}
|
||||
if (ownerUri) {
|
||||
endpointInfo = endpoint;
|
||||
@@ -1007,44 +1025,48 @@ export class SchemaCompareMainWindow {
|
||||
}).component();
|
||||
|
||||
this.saveScmpButton.onDidClick(async (click) => {
|
||||
const rootPath = getRootPath();
|
||||
const filePath = await vscode.window.showSaveDialog(
|
||||
{
|
||||
defaultUri: vscode.Uri.file(rootPath),
|
||||
saveLabel: loc.save,
|
||||
filters: {
|
||||
'scmp Files': ['scmp'],
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
// convert include/exclude maps to arrays of object ids
|
||||
let sourceExcludes: mssql.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalSourceExcludes);
|
||||
let targetExcludes: mssql.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalTargetExcludes);
|
||||
|
||||
let startTime = Date.now();
|
||||
TelemetryReporter.sendActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareSaveScmp');
|
||||
const service = await this.getService();
|
||||
const result = await service.schemaCompareSaveScmp(this.sourceEndpointInfo, this.targetEndpointInfo, azdata.TaskExecutionMode.execute, this.deploymentOptions, filePath.fsPath, sourceExcludes, targetExcludes);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareSaveScmpFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
operationId: this.comparisonResult.operationId
|
||||
}).send();
|
||||
vscode.window.showErrorMessage(loc.saveScmpErrorMessage(result.errorMessage));
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareSaveScmpEnded')
|
||||
.withAdditionalProperties({
|
||||
elapsedTime: (Date.now() - startTime).toString(),
|
||||
operationId: this.comparisonResult.operationId
|
||||
});
|
||||
await this.saveScmp();
|
||||
});
|
||||
}
|
||||
|
||||
public async saveScmp(): Promise<void> {
|
||||
const rootPath = getRootPath();
|
||||
const filePath = await vscode.window.showSaveDialog(
|
||||
{
|
||||
defaultUri: vscode.Uri.file(rootPath),
|
||||
saveLabel: loc.save,
|
||||
filters: {
|
||||
'scmp Files': ['scmp'],
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!filePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
// convert include/exclude maps to arrays of object ids
|
||||
let sourceExcludes: mssql.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalSourceExcludes);
|
||||
let targetExcludes: mssql.SchemaCompareObjectId[] = this.convertExcludesToObjectIds(this.originalTargetExcludes);
|
||||
|
||||
let startTime = Date.now();
|
||||
TelemetryReporter.sendActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareSaveScmp');
|
||||
const service = await this.getService();
|
||||
const result = await service.schemaCompareSaveScmp(this.sourceEndpointInfo, this.targetEndpointInfo, azdata.TaskExecutionMode.execute, this.deploymentOptions, filePath.fsPath, sourceExcludes, targetExcludes);
|
||||
if (!result || !result.success) {
|
||||
TelemetryReporter.createErrorEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareSaveScmpFailed', undefined, getTelemetryErrorType(result.errorMessage))
|
||||
.withAdditionalProperties({
|
||||
operationId: this.comparisonResult.operationId
|
||||
}).send();
|
||||
vscode.window.showErrorMessage(loc.saveScmpErrorMessage(result.errorMessage));
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareSaveScmpEnded')
|
||||
.withAdditionalProperties({
|
||||
elapsedTime: (Date.now() - startTime).toString(),
|
||||
operationId: this.comparisonResult.operationId
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts excluded diff entries into object ids which are needed to save them in an scmp
|
||||
*/
|
||||
@@ -1071,7 +1093,7 @@ export class SchemaCompareMainWindow {
|
||||
}
|
||||
|
||||
private async getService(): Promise<mssql.ISchemaCompareService> {
|
||||
if (isNullOrUndefined(this.schemaCompareService)) {
|
||||
if (this.schemaCompareService === null || this.schemaCompareService === undefined) {
|
||||
this.schemaCompareService = (vscode.extensions.getExtension(mssql.extension.name).exports as mssql.IExtension).schemaCompare;
|
||||
}
|
||||
return this.schemaCompareService;
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as should from 'should';
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as mssql from '../../../mssql';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import * as loc from '../localizedConstants';
|
||||
import 'mocha';
|
||||
import { SchemaCompareDialog } from './../dialogs/schemaCompareDialog';
|
||||
import * as sinon from 'sinon';
|
||||
import { SchemaCompareMainWindow } from '../schemaCompareMainWindow';
|
||||
import { SchemaCompareTestService, testStateScmp } from './testSchemaCompareService';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
@@ -28,15 +27,24 @@ before(function (): void {
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
describe('SchemaCompareMainWindow.start', function (): void {
|
||||
before(() => {
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should be correct when created.', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService();
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
await result.start(undefined);
|
||||
|
||||
should(result.getComparisonResult() === undefined);
|
||||
@@ -52,7 +60,7 @@ describe('SchemaCompareMainWindow.start', function (): void {
|
||||
it('Should start with the source as undefined', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService();
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
await result.start(undefined);
|
||||
|
||||
should.equal(result.sourceEndpointInfo, undefined);
|
||||
@@ -62,8 +70,8 @@ describe('SchemaCompareMainWindow.start', function (): void {
|
||||
it('Should start with the source as database', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService();
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
await result.start({connectionProfile: mockIConnectionProfile});
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
await result.start({ connectionProfile: mockIConnectionProfile });
|
||||
|
||||
should.notEqual(result.sourceEndpointInfo, undefined);
|
||||
should.equal(result.sourceEndpointInfo.endpointType, mssql.SchemaCompareEndpointType.Database);
|
||||
@@ -75,7 +83,7 @@ describe('SchemaCompareMainWindow.start', function (): void {
|
||||
it('Should start with the source as dacpac.', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService();
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
const dacpacPath = mockFilePath;
|
||||
await result.start(dacpacPath);
|
||||
|
||||
@@ -85,7 +93,287 @@ describe('SchemaCompareMainWindow.start', function (): void {
|
||||
should.equal(result.targetEndpointInfo, undefined);
|
||||
});
|
||||
});
|
||||
let showErrorMessageSpy: any;
|
||||
let showWarningMessageStub: any;
|
||||
let showOpenDialogStub: any;
|
||||
|
||||
describe('SchemaCompareMainWindow.results', function (): void {
|
||||
before(() => {
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
mockExtensionContext.setup(x => x.extensionPath).returns(() => '');
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
this.beforeEach(() => {
|
||||
sinon.restore();
|
||||
showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
});
|
||||
|
||||
it('Should show error if publish changes fails', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaComparePublishChanges(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: false,
|
||||
errorMessage: 'error1'
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('Yes'));
|
||||
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.publishChanges();
|
||||
|
||||
should(showErrorMessageSpy.calledOnce).be.true();
|
||||
should.equal(showErrorMessageSpy.getCall(0).args[0], loc.applyErrorMessage('error1'));
|
||||
});
|
||||
|
||||
it('Should show not error if publish changes succeed', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaComparePublishChanges(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: true,
|
||||
errorMessage: ''
|
||||
}));
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('Yes'));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.publishChanges();
|
||||
should(showErrorMessageSpy.notCalled).be.true();
|
||||
});
|
||||
|
||||
it('Should show error if openScmp fails', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
let files: vscode.Uri[] = [vscode.Uri.parse('file:///test')];
|
||||
service.setup(x => x.schemaCompareOpenScmp(TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
sourceEndpointInfo: undefined,
|
||||
targetEndpointInfo: undefined,
|
||||
originalTargetName: 'string',
|
||||
originalConnectionString: '',
|
||||
deploymentOptions: undefined,
|
||||
excludedSourceElements: [],
|
||||
excludedTargetElements: [],
|
||||
success: false,
|
||||
errorMessage: 'error1'
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('Yes'));
|
||||
showOpenDialogStub = sinon.stub(vscode.window, 'showOpenDialog').returns(<any>Promise.resolve(files));
|
||||
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.openScmp();
|
||||
|
||||
should(showErrorMessageSpy.calledOnce).be.true();
|
||||
should.equal(showErrorMessageSpy.getCall(0).args[0], loc.openScmpErrorMessage('error1'));
|
||||
});
|
||||
|
||||
it('Should show error if saveScmp fails', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
let file: vscode.Uri = vscode.Uri.parse('file:///test');
|
||||
service.setup(x => x.schemaCompareSaveScmp(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
sourceEndpointInfo: undefined,
|
||||
targetEndpointInfo: undefined,
|
||||
originalTargetName: 'string',
|
||||
originalConnectionString: '',
|
||||
deploymentOptions: undefined,
|
||||
excludedSourceElements: [],
|
||||
excludedTargetElements: [],
|
||||
success: false,
|
||||
errorMessage: 'error1'
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('Yes'));
|
||||
showOpenDialogStub = sinon.stub(vscode.window, 'showSaveDialog').returns(<any>Promise.resolve(file));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.saveScmp();
|
||||
|
||||
should(showErrorMessageSpy.calledOnce).be.true();
|
||||
should.equal(showErrorMessageSpy.getCall(0).args[0], loc.saveScmpErrorMessage('error1'));
|
||||
});
|
||||
|
||||
|
||||
it('Should show error if generateScript fails', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaCompareGenerateScript(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: false,
|
||||
errorMessage: 'error1'
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('Yes'));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.generateScript();
|
||||
|
||||
should(showErrorMessageSpy.calledOnce).be.true();
|
||||
should.equal(showErrorMessageSpy.getCall(0).args[0], loc.generateScriptErrorMessage('error1'));
|
||||
});
|
||||
|
||||
it('Should show error if cancel fails', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaCompareCancel(TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: false,
|
||||
errorMessage: 'error1'
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('Yes'));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.cancelCompare();
|
||||
|
||||
should(showErrorMessageSpy.calledOnce).be.true();
|
||||
should.equal(showErrorMessageSpy.getCall(0).args[0], loc.cancelErrorMessage('error1'));
|
||||
});
|
||||
|
||||
it('Should show error if IncludeExcludeNode fails', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaCompareIncludeExcludeNode(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: false,
|
||||
errorMessage: '',
|
||||
affectedDependencies: [],
|
||||
blockingDependencies: [{
|
||||
updateAction: 2,
|
||||
differenceType: 0,
|
||||
name: 'SqlTable',
|
||||
sourceValue: ['dbo', 'table1'],
|
||||
targetValue: null,
|
||||
parent: null,
|
||||
children: [{
|
||||
updateAction: 2,
|
||||
differenceType: 0,
|
||||
name: 'SqlSimpleColumn',
|
||||
sourceValue: ['dbo', 'table1', 'id'],
|
||||
targetValue: null,
|
||||
parent: null,
|
||||
children: [],
|
||||
sourceScript: '',
|
||||
targetScript: null,
|
||||
included: false
|
||||
}],
|
||||
sourceScript: 'CREATE TABLE [dbo].[table1](id int)',
|
||||
targetScript: null,
|
||||
included: true
|
||||
}]
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(''));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.applyIncludeExclude({
|
||||
row: 0,
|
||||
column: 0,
|
||||
columnName: 1,
|
||||
checked: true
|
||||
});
|
||||
|
||||
should(showWarningMessageStub.calledOnce).be.true();
|
||||
});
|
||||
|
||||
it('Should not show warning if IncludeExcludeNode succeed', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaCompareIncludeExcludeNode(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: true,
|
||||
errorMessage: '',
|
||||
affectedDependencies: [],
|
||||
blockingDependencies: [{
|
||||
updateAction: 2,
|
||||
differenceType: 0,
|
||||
name: 'SqlTable',
|
||||
sourceValue: ['dbo', 'table1'],
|
||||
targetValue: null,
|
||||
parent: null,
|
||||
children: [{
|
||||
updateAction: 2,
|
||||
differenceType: 0,
|
||||
name: 'SqlSimpleColumn',
|
||||
sourceValue: ['dbo', 'table1', 'id'],
|
||||
targetValue: null,
|
||||
parent: null,
|
||||
children: [],
|
||||
sourceScript: '',
|
||||
targetScript: null,
|
||||
included: false
|
||||
}],
|
||||
sourceScript: 'CREATE TABLE [dbo].[table1](id int)',
|
||||
targetScript: null,
|
||||
included: true
|
||||
}]
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(''));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.applyIncludeExclude({
|
||||
row: 0,
|
||||
column: 0,
|
||||
columnName: 1,
|
||||
checked: false
|
||||
});
|
||||
|
||||
should(showWarningMessageStub.notCalled).be.true();
|
||||
});
|
||||
|
||||
it('Should not show error if user does not want to publish', async function (): Promise<void> {
|
||||
let service = createServiceMock();
|
||||
service.setup(x => x.schemaComparePublishChanges(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
success: true,
|
||||
errorMessage: ''
|
||||
}));
|
||||
|
||||
showWarningMessageStub = sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve('No'));
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(service.object, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
await schemaCompareResult.execute();
|
||||
await schemaCompareResult.publishChanges();
|
||||
|
||||
should(showErrorMessageSpy.notCalled).be.true();
|
||||
});
|
||||
|
||||
function createServiceMock() {
|
||||
let sc = new SchemaCompareTestService(testStateScmp.SUCCESS_NOT_EQUAL);
|
||||
let service = TypeMoq.Mock.ofInstance(new SchemaCompareTestService());
|
||||
service.setup(x => x.schemaCompareGetDefaultOptions()).returns(x => sc.schemaCompareGetDefaultOptions());
|
||||
service.setup(x => x.schemaCompare(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => sc.schemaCompare('', undefined, undefined, undefined, undefined));
|
||||
return service;
|
||||
}
|
||||
});
|
||||
|
||||
let showErrorMessageStub: any;
|
||||
describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
before(() => {
|
||||
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
|
||||
@@ -93,16 +381,22 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
beforeEach(function (): void {
|
||||
testContext.apiWrapper.reset();
|
||||
this.afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
this.beforeEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should fail for failing Schema Compare service', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService(testStateScmp.FAILURE);
|
||||
|
||||
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
showErrorMessageStub = sinon.stub(vscode.window, 'showErrorMessage').callsFake((message) => {
|
||||
throw new Error(message);
|
||||
});
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
await result.start(undefined);
|
||||
|
||||
should(result.getComparisonResult() === undefined);
|
||||
@@ -116,8 +410,7 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
it('Should exit for failing Schema Compare service', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService(testStateScmp.FAILURE);
|
||||
|
||||
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns(() => Promise.resolve(''));
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
|
||||
await result.start(undefined);
|
||||
|
||||
@@ -127,13 +420,12 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
|
||||
await result.execute();
|
||||
testContext.apiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
|
||||
});
|
||||
|
||||
it('Should disable script button and apply button for Schema Compare service for dacpac', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService(testStateScmp.SUCCESS_NOT_EQUAL);
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
|
||||
await result.start(undefined);
|
||||
|
||||
@@ -145,7 +437,7 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
await result.execute();
|
||||
|
||||
//Generate script button and apply button should be disabled for dacpac comparison
|
||||
result.verifyButtonsState( {
|
||||
result.verifyButtonsState({
|
||||
compareButtonState: true,
|
||||
optionsButtonState: true,
|
||||
switchButtonState: true,
|
||||
@@ -156,13 +448,13 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
selectTargetButtonState: true,
|
||||
generateScriptButtonState: false,
|
||||
applyButtonState: false
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
it('Should disable script button and apply button for Schema Compare service for database', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService(testStateScmp.SUCCESS_NOT_EQUAL);
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
|
||||
await result.start(undefined);
|
||||
|
||||
@@ -174,7 +466,7 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
await result.execute();
|
||||
|
||||
//Generate script button and apply button should be enabled for database comparison
|
||||
result.verifyButtonsState( {
|
||||
result.verifyButtonsState({
|
||||
compareButtonState: true,
|
||||
optionsButtonState: true,
|
||||
switchButtonState: true,
|
||||
@@ -185,7 +477,7 @@ describe('SchemaCompareMainWindow.execute', function (): void {
|
||||
selectTargetButtonState: true,
|
||||
generateScriptButtonState: true,
|
||||
applyButtonState: true
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -201,18 +493,18 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
|
||||
let sc = new SchemaCompareTestService();
|
||||
let endpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
|
||||
await result.start(undefined);
|
||||
|
||||
should(result.getComparisonResult() === undefined);
|
||||
|
||||
result.sourceEndpointInfo = {...endpointInfo};
|
||||
result.targetEndpointInfo = {...endpointInfo};
|
||||
result.sourceEndpointInfo = { ...endpointInfo };
|
||||
result.targetEndpointInfo = { ...endpointInfo };
|
||||
|
||||
result.updateSourceAndTarget();
|
||||
|
||||
result.verifyButtonsState( {
|
||||
result.verifyButtonsState({
|
||||
compareButtonState: false,
|
||||
optionsButtonState: false,
|
||||
switchButtonState: false,
|
||||
@@ -223,25 +515,25 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
|
||||
selectTargetButtonState: true,
|
||||
generateScriptButtonState: false,
|
||||
applyButtonState: false
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
it('Should set buttons appropriately when source endpoint is empty and target endpoint is populated', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService();
|
||||
let endpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
|
||||
await result.start(undefined);
|
||||
|
||||
should(result.getComparisonResult() === undefined);
|
||||
|
||||
result.sourceEndpointInfo = {...endpointInfo};
|
||||
result.sourceEndpointInfo = { ...endpointInfo };
|
||||
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
|
||||
result.updateSourceAndTarget();
|
||||
|
||||
result.verifyButtonsState( {
|
||||
result.verifyButtonsState({
|
||||
compareButtonState: false,
|
||||
optionsButtonState: false,
|
||||
switchButtonState: true,
|
||||
@@ -252,14 +544,14 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
|
||||
selectTargetButtonState: true,
|
||||
generateScriptButtonState: false,
|
||||
applyButtonState: false
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
it('Should set buttons appropriately when source and target endpoints are populated', async function (): Promise<void> {
|
||||
let sc = new SchemaCompareTestService();
|
||||
let endpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
|
||||
let result = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, sc, mockExtensionContext.object);
|
||||
let result = new SchemaCompareMainWindowTest(sc, mockExtensionContext.object);
|
||||
|
||||
await result.start(undefined);
|
||||
|
||||
@@ -270,7 +562,7 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
|
||||
|
||||
result.updateSourceAndTarget();
|
||||
|
||||
result.verifyButtonsState( {
|
||||
result.verifyButtonsState({
|
||||
compareButtonState: true,
|
||||
optionsButtonState: true,
|
||||
switchButtonState: true,
|
||||
@@ -281,7 +573,7 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
|
||||
selectTargetButtonState: true,
|
||||
generateScriptButtonState: false,
|
||||
applyButtonState: false
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('SchemaCompareDialog.openDialog', function (): void {
|
||||
});
|
||||
|
||||
it('Should be correct when created.', async function (): Promise<void> {
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(testContext.apiWrapper.object, undefined, mockExtensionContext.object);
|
||||
let schemaCompareResult = new SchemaCompareMainWindow(undefined, mockExtensionContext.object);
|
||||
let dialog = new SchemaCompareDialog(schemaCompareResult);
|
||||
await dialog.openDialog();
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('SchemaCompareDialog.openDialog', function (): void {
|
||||
});
|
||||
|
||||
it('Simulate ok button- with both endpoints set to dacpac', async function (): Promise<void> {
|
||||
let schemaCompareResult = new SchemaCompareMainWindowTest(testContext.apiWrapper.object, undefined, mockExtensionContext.object);
|
||||
let schemaCompareResult = new SchemaCompareMainWindowTest(undefined, mockExtensionContext.object);
|
||||
await schemaCompareResult.start(undefined);
|
||||
schemaCompareResult.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
|
||||
schemaCompareResult.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
|
||||
@@ -53,7 +53,7 @@ describe('SchemaCompareDialog.openDialog', function (): void {
|
||||
await dialog.execute();
|
||||
|
||||
// Confirm that ok button got clicked
|
||||
schemaCompareResult.verifyButtonsState( {
|
||||
schemaCompareResult.verifyButtonsState({
|
||||
compareButtonState: true,
|
||||
optionsButtonState: true,
|
||||
switchButtonState: true,
|
||||
@@ -64,6 +64,6 @@ describe('SchemaCompareDialog.openDialog', function (): void {
|
||||
selectTargetButtonState: true,
|
||||
generateScriptButtonState: false,
|
||||
applyButtonState: false
|
||||
} );
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
|
||||
export interface TestContext {
|
||||
apiWrapper: TypeMoq.IMock<ApiWrapper>;
|
||||
context: vscode.ExtensionContext;
|
||||
}
|
||||
|
||||
@@ -17,7 +14,6 @@ export function createContext(): TestContext {
|
||||
let extensionPath = path.join(__dirname, '..', '..');
|
||||
|
||||
return {
|
||||
apiWrapper: TypeMoq.Mock.ofType(ApiWrapper),
|
||||
context: {
|
||||
subscriptions: [],
|
||||
workspaceState: {
|
||||
|
||||
@@ -7,7 +7,6 @@ import * as vscode from 'vscode';
|
||||
import * as mssql from '../../../mssql';
|
||||
import * as should from 'should';
|
||||
import { SchemaCompareMainWindow } from '../schemaCompareMainWindow';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
|
||||
export interface ButtonState {
|
||||
compareButtonState: boolean;
|
||||
@@ -24,10 +23,9 @@ export interface ButtonState {
|
||||
export class SchemaCompareMainWindowTest extends SchemaCompareMainWindow {
|
||||
|
||||
constructor(
|
||||
apiWrapper: ApiWrapper,
|
||||
schemaCompareService: mssql.ISchemaCompareService,
|
||||
extensionContext: vscode.ExtensionContext) {
|
||||
super(apiWrapper, schemaCompareService, extensionContext);
|
||||
super(schemaCompareService, extensionContext);
|
||||
}
|
||||
|
||||
// only for test
|
||||
|
||||
@@ -47,7 +47,7 @@ export class SchemaCompareTestService implements mssql.ISchemaCompareService {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
schemaCompare(operationId: string, sourceEndpointInfo: mssql.SchemaCompareEndpointInfo, targetEndpointInfo: mssql.SchemaCompareEndpointInfo, taskExecutionMode: azdata.TaskExecutionMode): Thenable<mssql.SchemaCompareResult> {
|
||||
schemaCompare(operationId: string, sourceEndpointInfo: mssql.SchemaCompareEndpointInfo, targetEndpointInfo: mssql.SchemaCompareEndpointInfo, taskExecutionMode: azdata.TaskExecutionMode, deploymentOptions: mssql.DeploymentOptions): Thenable<mssql.SchemaCompareResult> {
|
||||
let result: mssql.SchemaCompareResult;
|
||||
if (this.testState === testStateScmp.FAILURE) {
|
||||
result = {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import * as should from 'should';
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as mssql from '../../../mssql';
|
||||
import * as loc from '../localizedConstants';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
@@ -15,10 +16,15 @@ import { promises as fs } from 'fs';
|
||||
import { getEndpointName, verifyConnectionAndGetOwnerUri, exists } from '../utils';
|
||||
import { mockDacpacEndpoint, mockDatabaseEndpoint, mockFilePath, mockConnectionInfo, shouldThrowSpecificError, mockConnectionResult, mockConnectionProfile } from './testUtils';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
import * as sinon from 'sinon';
|
||||
|
||||
let testContext: TestContext;
|
||||
|
||||
describe('utils: Tests to verify getEndpointName', function (): void {
|
||||
afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should generate correct endpoint information', () => {
|
||||
let endpointInfo: mssql.SchemaCompareEndpointInfo;
|
||||
|
||||
@@ -52,7 +58,7 @@ describe('utils: Basic tests to verify verifyConnectionAndGetOwnerUri', function
|
||||
|
||||
it('Should return undefined for endpoint as dacpac', async function (): Promise<void> {
|
||||
let ownerUri = undefined;
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(mockDacpacEndpoint, 'test', testContext.apiWrapper.object);
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(mockDacpacEndpoint, 'test');
|
||||
|
||||
should(ownerUri).equal(undefined);
|
||||
});
|
||||
@@ -62,7 +68,7 @@ describe('utils: Basic tests to verify verifyConnectionAndGetOwnerUri', function
|
||||
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = { ...mockDatabaseEndpoint };
|
||||
testDatabaseEndpoint.connectionDetails = undefined;
|
||||
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test', testContext.apiWrapper.object);
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test');
|
||||
|
||||
should(ownerUri).equal(undefined);
|
||||
});
|
||||
@@ -73,6 +79,10 @@ describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', funct
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should throw an error asking to make a connection', async function (): Promise<void> {
|
||||
let getConnectionsResults: azdata.connection.ConnectionProfile[] = [];
|
||||
let connection = { ...mockConnectionResult };
|
||||
@@ -80,12 +90,14 @@ describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', funct
|
||||
testDatabaseEndpoint.connectionDetails = { ...mockConnectionInfo };
|
||||
const getConnectionString = loc.getConnectionString('test');
|
||||
|
||||
testContext.apiWrapper.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { return Promise.resolve(connection); });
|
||||
testContext.apiWrapper.setup(x => x.getUriForConnection(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(undefined); });
|
||||
testContext.apiWrapper.setup(x => x.getConnections(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(getConnectionsResults); });
|
||||
testContext.apiWrapper.setup(x => x.showWarningMessage(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
|
||||
sinon.stub(azdata.connection, 'connect').returns(<any>Promise.resolve(connection));
|
||||
sinon.stub(azdata.connection, 'getUriForConnection').returns(<any>Promise.resolve(undefined));
|
||||
sinon.stub(azdata.connection, 'getConnections').returns(<any>Promise.resolve(getConnectionsResults));
|
||||
sinon.stub(vscode.window, 'showWarningMessage').callsFake((message) => {
|
||||
throw new Error(message);
|
||||
});
|
||||
|
||||
await shouldThrowSpecificError(async () => await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test', testContext.apiWrapper.object), getConnectionString);
|
||||
await shouldThrowSpecificError(async () => await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test'), getConnectionString);
|
||||
});
|
||||
|
||||
it('Should throw an error for login failure', async function (): Promise<void> {
|
||||
@@ -94,12 +106,15 @@ describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', funct
|
||||
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = { ...mockDatabaseEndpoint };
|
||||
testDatabaseEndpoint.connectionDetails = { ...mockConnectionInfo };
|
||||
|
||||
testContext.apiWrapper.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { return Promise.resolve(connection); });
|
||||
testContext.apiWrapper.setup(x => x.getUriForConnection(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(undefined); });
|
||||
testContext.apiWrapper.setup(x => x.getConnections(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(getConnectionsResults); });
|
||||
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
|
||||
sinon.stub(azdata.connection, 'connect').returns(<any>Promise.resolve(connection));
|
||||
sinon.stub(azdata.connection, 'getUriForConnection').returns(<any>Promise.resolve(undefined));
|
||||
sinon.stub(azdata.connection, 'getConnections').returns(<any>Promise.resolve(getConnectionsResults));
|
||||
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(loc.YesButtonText));
|
||||
sinon.stub(vscode.window, 'showErrorMessage').callsFake((message) => {
|
||||
throw new Error(message);
|
||||
});
|
||||
|
||||
await shouldThrowSpecificError(async () => await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test', testContext.apiWrapper.object), connection.errorMessage);
|
||||
await shouldThrowSpecificError(async () => await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test'), connection.errorMessage);
|
||||
});
|
||||
|
||||
it('Should throw an error for login failure with openConnectionDialog but no ownerUri', async function (): Promise<void> {
|
||||
@@ -108,13 +123,18 @@ describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', funct
|
||||
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = { ...mockDatabaseEndpoint };
|
||||
testDatabaseEndpoint.connectionDetails = { ...mockConnectionInfo };
|
||||
|
||||
testContext.apiWrapper.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { return Promise.resolve(connection); });
|
||||
testContext.apiWrapper.setup(x => x.getUriForConnection(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(undefined); });
|
||||
testContext.apiWrapper.setup(x => x.getConnections(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(getConnectionsResults); });
|
||||
testContext.apiWrapper.setup(x => x.showWarningMessage(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { return Promise.resolve(loc.YesButtonText); });
|
||||
testContext.apiWrapper.setup(x => x.openConnectionDialog(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { return Promise.resolve(undefined); });
|
||||
sinon.stub(azdata.connection, 'connect').returns(<any>Promise.resolve(connection));
|
||||
sinon.stub(azdata.connection, 'getUriForConnection').returns(<any>Promise.resolve(undefined));
|
||||
sinon.stub(azdata.connection, 'openConnectionDialog').returns(<any>Promise.resolve({
|
||||
connectionId: 'id'
|
||||
}));
|
||||
sinon.stub(azdata.connection, 'getConnections').returns(<any>Promise.resolve(getConnectionsResults));
|
||||
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(loc.YesButtonText));
|
||||
sinon.stub(vscode.window, 'showErrorMessage').callsFake((message) => {
|
||||
throw new Error(message);
|
||||
});
|
||||
|
||||
await shouldThrowSpecificError(async () => await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test', testContext.apiWrapper.object), connection.errorMessage);
|
||||
await shouldThrowSpecificError(async () => await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test'), connection.errorMessage);
|
||||
});
|
||||
|
||||
it('Should not throw an error and set ownerUri appropriately', async function (): Promise<void> {
|
||||
@@ -124,10 +144,10 @@ describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', funct
|
||||
let expectedOwnerUri: string = 'providerName:MSSQL|authenticationType:SqlLogin|database:My Database|server:My Server|user:My User|databaseDisplayName:My Database';
|
||||
testDatabaseEndpoint.connectionDetails = { ...mockConnectionInfo };
|
||||
|
||||
testContext.apiWrapper.setup(x => x.connect(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => { return Promise.resolve(connection); });
|
||||
testContext.apiWrapper.setup(x => x.getUriForConnection(TypeMoq.It.isAny())).returns(() => { return Promise.resolve(expectedOwnerUri); });
|
||||
sinon.stub(azdata.connection, 'connect').returns(<any>Promise.resolve(connection));
|
||||
sinon.stub(azdata.connection, 'getUriForConnection').returns(<any>Promise.resolve(expectedOwnerUri));
|
||||
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test', testContext.apiWrapper.object);
|
||||
ownerUri = await verifyConnectionAndGetOwnerUri(testDatabaseEndpoint, 'test');
|
||||
|
||||
should(ownerUri).equal(expectedOwnerUri);
|
||||
});
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as vscode from 'vscode';
|
||||
import * as mssql from '../../mssql';
|
||||
import * as os from 'os';
|
||||
import * as loc from './localizedConstants';
|
||||
import { ApiWrapper } from './common/apiWrapper';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
export interface IPackageInfo {
|
||||
@@ -32,7 +31,7 @@ export function getPackageInfo(packageJson: any): IPackageInfo {
|
||||
* @param msg The error message to map
|
||||
*/
|
||||
export function getTelemetryErrorType(msg: string): string {
|
||||
if (msg.indexOf('Object reference not set to an instance of an object') !== -1) {
|
||||
if (msg && msg.indexOf('Object reference not set to an instance of an object') !== -1) {
|
||||
return 'ObjectReferenceNotSet';
|
||||
}
|
||||
else {
|
||||
@@ -85,18 +84,18 @@ function connectionInfoToConnectionProfile(details: azdata.ConnectionInfo): azda
|
||||
};
|
||||
}
|
||||
|
||||
export async function verifyConnectionAndGetOwnerUri(endpoint: mssql.SchemaCompareEndpointInfo, caller: string, apiWrapper: ApiWrapper): Promise<string | undefined> {
|
||||
export async function verifyConnectionAndGetOwnerUri(endpoint: mssql.SchemaCompareEndpointInfo, caller: string): Promise<string | undefined> {
|
||||
let ownerUri = undefined;
|
||||
|
||||
if (endpoint.endpointType === mssql.SchemaCompareEndpointType.Database && endpoint.connectionDetails) {
|
||||
let connectionProfile = await connectionInfoToConnectionProfile(endpoint.connectionDetails);
|
||||
let connection = await apiWrapper.connect(connectionProfile, false, false);
|
||||
let connection = await azdata.connection.connect(connectionProfile, false, false);
|
||||
|
||||
if (connection) {
|
||||
ownerUri = await apiWrapper.getUriForConnection(connection.connectionId);
|
||||
ownerUri = await azdata.connection.getUriForConnection(connection.connectionId);
|
||||
|
||||
if (!ownerUri) {
|
||||
let connectionList = await apiWrapper.getConnections(true);
|
||||
let connectionList = await azdata.connection.getConnections(true);
|
||||
|
||||
let userConnection;
|
||||
userConnection = connectionList.find(connection =>
|
||||
@@ -109,18 +108,18 @@ export async function verifyConnectionAndGetOwnerUri(endpoint: mssql.SchemaCompa
|
||||
if (userConnection === undefined) {
|
||||
const getConnectionString = loc.getConnectionString(caller);
|
||||
// need only yes button - since the modal dialog has a default cancel
|
||||
let result = await apiWrapper.showWarningMessage(getConnectionString, { modal: true }, loc.YesButtonText);
|
||||
let result = await vscode.window.showWarningMessage(getConnectionString, { modal: true }, loc.YesButtonText);
|
||||
if (result === loc.YesButtonText) {
|
||||
userConnection = await apiWrapper.openConnectionDialog(undefined, connectionProfile);
|
||||
userConnection = await azdata.connection.openConnectionDialog(undefined, connectionProfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (userConnection !== undefined) {
|
||||
ownerUri = await apiWrapper.getUriForConnection(userConnection.connectionId);
|
||||
ownerUri = await azdata.connection.getUriForConnection(userConnection.connectionId);
|
||||
}
|
||||
}
|
||||
if (!ownerUri && connection.errorMessage) {
|
||||
apiWrapper.showErrorMessage(connection.errorMessage);
|
||||
vscode.window.showErrorMessage(connection.errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user