Schema Compare cleanup (#11418)

* cleanup async and await stuff

* remove awaits

* remove more awaits
This commit is contained in:
Kim Santiago
2020-07-21 09:47:14 -07:00
committed by GitHub
parent 92c8d890c4
commit d533af3019
6 changed files with 61 additions and 60 deletions

View File

@@ -275,14 +275,14 @@ export class SchemaCompareDialog {
let formModel = this.formBuilder.component();
await view.initializeModel(formModel);
if (this.sourceIsDacpac) {
this.sourceDacpacRadioButton.focus();
await this.sourceDacpacRadioButton.focus();
} else {
this.sourceDatabaseRadioButton.focus();
await this.sourceDatabaseRadioButton.focus();
}
});
}
private async createFileBrowser(view: azdata.ModelView, isTarget: boolean, endpoint: mssql.SchemaCompareEndpointInfo): Promise<azdata.FormComponent> {
private createFileBrowser(view: azdata.ModelView, isTarget: boolean, endpoint: mssql.SchemaCompareEndpointInfo): azdata.FormComponent {
let currentTextbox = isTarget ? this.targetTextBox : this.sourceTextBox;
if (isTarget) {
this.targetFileButton = view.modelBuilder.button().withProperties({
@@ -333,7 +333,7 @@ export class SchemaCompareDialog {
};
}
private async createSourceRadiobuttons(view: azdata.ModelView): Promise<azdata.FormComponent> {
private createSourceRadiobuttons(view: azdata.ModelView): azdata.FormComponent {
this.sourceDacpacRadioButton = view.modelBuilder.radioButton()
.withProperties({
name: 'source',
@@ -389,7 +389,7 @@ export class SchemaCompareDialog {
};
}
private async createTargetRadiobuttons(view: azdata.ModelView): Promise<azdata.FormComponent> {
private createTargetRadiobuttons(view: azdata.ModelView): azdata.FormComponent {
let dacpacRadioButton = view.modelBuilder.radioButton()
.withProperties({
name: 'target',
@@ -461,7 +461,7 @@ export class SchemaCompareDialog {
return !isNullOrUndefined(filename) && await exists(filename) && (filename.toLocaleLowerCase().endsWith('.dacpac'));
}
protected async createSourceServerDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
protected createSourceServerDropdown(view: azdata.ModelView): azdata.FormComponent {
this.sourceServerDropdown = view.modelBuilder.dropDown().withProperties(
{
editable: true,
@@ -471,7 +471,7 @@ export class SchemaCompareDialog {
).component();
this.sourceServerDropdown.onValueChanged(async (value) => {
if (this.sourceServerDropdown.values.findIndex(x => this.matchesValue(x, value)) === -1) {
this.sourceDatabaseDropdown.updateProperties({
await this.sourceDatabaseDropdown.updateProperties({
values: [],
value: ' '
});
@@ -487,7 +487,7 @@ export class SchemaCompareDialog {
};
}
protected async createTargetServerDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
protected createTargetServerDropdown(view: azdata.ModelView): azdata.FormComponent {
this.targetServerDropdown = view.modelBuilder.dropDown().withProperties(
{
editable: true,
@@ -497,7 +497,7 @@ export class SchemaCompareDialog {
).component();
this.targetServerDropdown.onValueChanged(async (value) => {
if (this.targetServerDropdown.values.findIndex(x => this.matchesValue(x, value)) === -1) {
this.targetDatabaseDropdown.updateProperties({
await this.targetDatabaseDropdown.updateProperties({
values: [],
value: ' '
});
@@ -518,7 +518,7 @@ export class SchemaCompareDialog {
let values = await this.getServerValues(isTarget);
if (values && values.length > 0) {
currentDropdown.updateProperties({
await currentDropdown.updateProperties({
values: values,
value: values[0]
});
@@ -585,7 +585,7 @@ export class SchemaCompareDialog {
return values;
}
protected async createSourceDatabaseDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
protected createSourceDatabaseDropdown(view: azdata.ModelView): azdata.FormComponent {
this.sourceDatabaseDropdown = view.modelBuilder.dropDown().withProperties(
{
editable: true,
@@ -604,7 +604,7 @@ export class SchemaCompareDialog {
};
}
protected async createTargetDatabaseDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
protected createTargetDatabaseDropdown(view: azdata.ModelView): azdata.FormComponent {
this.targetDatabaseDropdown = view.modelBuilder.dropDown().withProperties(
{
editable: true,
@@ -629,7 +629,7 @@ export class SchemaCompareDialog {
protected async populateDatabaseDropdown(connectionProfile: azdata.connection.ConnectionProfile, isTarget: boolean): Promise<void> {
let currentDropdown = isTarget ? this.targetDatabaseDropdown : this.sourceDatabaseDropdown;
currentDropdown.updateProperties({ values: [], value: null });
await currentDropdown.updateProperties({ values: [], value: null });
let values = [];
try {
@@ -640,7 +640,7 @@ export class SchemaCompareDialog {
console.warn(e);
}
if (values && values.length > 0) {
currentDropdown.updateProperties({
await currentDropdown.updateProperties({
values: values,
value: values[0],
});
@@ -672,7 +672,7 @@ export class SchemaCompareDialog {
return values;
}
protected async createNoActiveConnectionsText(view: azdata.ModelView): Promise<azdata.FormComponent> {
protected createNoActiveConnectionsText(view: azdata.ModelView): azdata.FormComponent {
let noActiveConnectionsText = view.modelBuilder.text().withProperties({ value: loc.NoActiveConnectionsLabel }).component();
return {

View File

@@ -35,19 +35,19 @@ export class SchemaCompareOptionsDialog {
this.optionsModel = new SchemaCompareOptionsModel(defaultOptions);
}
protected async initializeDialog() {
protected initializeDialog(): void {
this.generalOptionsTab = azdata.window.createTab(loc.GeneralOptionsLabel);
this.objectTypesTab = azdata.window.createTab(loc.ObjectTypesOptionsLabel);
await this.initializeSchemaCompareOptionsDialogTab();
await this.initializeSchemaCompareObjectTypesDialogTab();
this.initializeSchemaCompareOptionsDialogTab();
this.initializeSchemaCompareObjectTypesDialogTab();
this.dialog.content = [this.generalOptionsTab, this.objectTypesTab];
}
public async openDialog() {
public openDialog(): void {
let event = null;
this.dialog = azdata.window.createModelViewDialog(loc.OptionsLabel, event);
await this.initializeDialog();
this.initializeDialog();
this.dialog.okButton.label = loc.OkButtonText;
this.dialog.okButton.onClick(async () => await this.execute());
@@ -63,7 +63,7 @@ export class SchemaCompareOptionsDialog {
azdata.window.openDialog(this.dialog);
}
protected async execute() {
protected execute(): void {
this.optionsModel.setDeploymentOptions();
this.optionsModel.setObjectTypeOptions();
this.schemaComparison.setDeploymentOptions(this.deploymentOptions);
@@ -78,26 +78,26 @@ export class SchemaCompareOptionsDialog {
this.disposeListeners();
}
protected async cancel() {
protected cancel(): void {
this.disposeListeners();
}
private async reset() {
private async reset(): Promise<void> {
let service = (vscode.extensions.getExtension(mssql.extension.name).exports as mssql.IExtension).schemaCompare;
let result = await service.schemaCompareGetDefaultOptions();
this.deploymentOptions = result.defaultDeploymentOptions;
this.optionsChanged = true;
this.updateOptionsTable();
await this.updateOptionsTable();
this.optionsFlexBuilder.removeItem(this.optionsTable);
this.optionsFlexBuilder.insertItem(this.optionsTable, 0, { CSSStyles: { 'overflow': 'scroll', 'height': '65vh' } });
this.updateObjectsTable();
await this.updateObjectsTable();
this.objectTypesFlexBuilder.removeItem(this.objectsTable);
this.objectTypesFlexBuilder.addItem(this.objectsTable, { CSSStyles: { 'overflow': 'scroll', 'height': '80vh' } });
}
private async initializeSchemaCompareOptionsDialogTab() {
private initializeSchemaCompareOptionsDialogTab(): void {
this.generalOptionsTab.registerContent(async view => {
this.descriptionHeading = view.modelBuilder.table().withProperties({
@@ -116,17 +116,17 @@ export class SchemaCompareOptionsDialog {
this.optionsTable = view.modelBuilder.table().component();
this.updateOptionsTable();
await this.updateOptionsTable();
this.disposableListeners.push(this.optionsTable.onRowSelected(async () => {
let row = this.optionsTable.selectedRows[0];
let label = this.optionsModel.optionsLabels[row];
this.descriptionText.updateProperties({
await this.descriptionText.updateProperties({
value: this.optionsModel.getDescription(label)
});
}));
this.disposableListeners.push(this.optionsTable.onCellAction(async (rowState) => {
this.disposableListeners.push(this.optionsTable.onCellAction((rowState) => {
let checkboxState = <azdata.ICheckboxCellActionEventArgs>rowState;
if (checkboxState && checkboxState.row !== undefined) {
let label = this.optionsModel.optionsLabels[checkboxState.row];
@@ -144,11 +144,11 @@ export class SchemaCompareOptionsDialog {
this.optionsFlexBuilder.addItem(this.descriptionHeading, { CSSStyles: { 'font-weight': 'bold', 'height': '30px' } });
this.optionsFlexBuilder.addItem(this.descriptionText, { CSSStyles: { 'padding': '4px', 'margin-right': '10px', 'overflow': 'scroll', 'height': '10vh' } });
await view.initializeModel(this.optionsFlexBuilder);
this.optionsTable.focus();
await this.optionsTable.focus();
});
}
private async initializeSchemaCompareObjectTypesDialogTab() {
private initializeSchemaCompareObjectTypesDialogTab(): void {
this.objectTypesTab.registerContent(async view => {
this.objectTypesFlexBuilder = view.modelBuilder.flexContainer()
@@ -157,9 +157,9 @@ export class SchemaCompareOptionsDialog {
}).component();
this.objectsTable = view.modelBuilder.table().component();
this.updateObjectsTable();
await this.updateObjectsTable();
this.disposableListeners.push(this.objectsTable.onCellAction(async (rowState) => {
this.disposableListeners.push(this.objectsTable.onCellAction((rowState) => {
let checkboxState = <azdata.ICheckboxCellActionEventArgs>rowState;
if (checkboxState && checkboxState.row !== undefined) {
let label = this.optionsModel.objectTypeLabels[checkboxState.row];
@@ -180,9 +180,9 @@ export class SchemaCompareOptionsDialog {
}
}
private updateOptionsTable(): void {
private async updateOptionsTable(): Promise<void> {
let data = this.optionsModel.getOptionsData();
this.optionsTable.updateProperties({
await this.optionsTable.updateProperties({
data: data,
columns: [
{
@@ -204,9 +204,9 @@ export class SchemaCompareOptionsDialog {
});
}
private updateObjectsTable(): void {
private async updateObjectsTable(): Promise<void> {
let data = this.optionsModel.getObjectsData();
this.objectsTable.updateProperties({
await this.objectsTable.updateProperties({
data: data,
columns: [
{

View File

@@ -725,7 +725,7 @@ export class SchemaCompareMainWindow {
TelemetryReporter.sendActionEvent(TelemetryViews.SchemaCompareMainWindow, 'SchemaCompareOptionsOpened');
// create fresh every time
this.schemaCompareOptionDialog = new SchemaCompareOptionsDialog(this.deploymentOptions, this);
await this.schemaCompareOptionDialog.openDialog();
this.schemaCompareOptionDialog.openDialog();
});
}

View File

@@ -24,9 +24,10 @@ const mocktarget: string = 'target.dacpac';
let mockExtensionContext: TypeMoq.IMock<vscode.ExtensionContext>;
let testContext: TestContext;
before(async function (): Promise<void> {
before(function (): void {
testContext = createContext();
});
describe('SchemaCompareDialog.openDialog', function (): void {
before(() => {
mockExtensionContext = TypeMoq.Mock.ofType<vscode.ExtensionContext>();
@@ -57,8 +58,8 @@ describe('SchemaCompareMainWindow.start', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
result.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
await result.execute();
should(result.getComparisonResult() !== undefined);
@@ -109,7 +110,7 @@ describe('SchemaCompareMainWindow.execute', function (): void {
testContext = createContext();
});
beforeEach(async function (): Promise<void> {
beforeEach(function (): void {
testContext.apiWrapper.reset();
});
@@ -123,8 +124,8 @@ describe('SchemaCompareMainWindow.execute', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
result.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
await shouldThrowSpecificError(async () => await result.execute(), loc.compareErrorMessage('Test failure'));
});
@@ -139,8 +140,8 @@ describe('SchemaCompareMainWindow.execute', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
result.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
await result.execute();
testContext.apiWrapper.verify(x => x.showErrorMessage(TypeMoq.It.isAny()), TypeMoq.Times.once());
@@ -155,8 +156,8 @@ describe('SchemaCompareMainWindow.execute', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
result.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
await result.execute();
@@ -176,8 +177,8 @@ describe('SchemaCompareMainWindow.execute', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDatabaseEndpointInfo();
result.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = setDatabaseEndpointInfo();
await result.execute();
@@ -229,7 +230,7 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = {...endpointInfo};
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
result.updateSourceAndTarget();
@@ -249,8 +250,8 @@ describe('SchemaCompareMainWindow.updateSourceAndTarget', function (): void {
should(result.getComparisonResult() === undefined);
result.sourceEndpointInfo = await setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = await setDacpacEndpointInfo(mocktarget);
result.sourceEndpointInfo = setDacpacEndpointInfo(mocksource);
result.targetEndpointInfo = setDacpacEndpointInfo(mocktarget);
result.updateSourceAndTarget();

View File

@@ -100,7 +100,7 @@ export async function shouldThrowSpecificError(block: Function, expectedMessage:
}
}
export async function setDacpacEndpointInfo(path: string): Promise<mssql.SchemaCompareEndpointInfo> {
export function setDacpacEndpointInfo(path: string): mssql.SchemaCompareEndpointInfo {
let endpointInfo: mssql.SchemaCompareEndpointInfo;
endpointInfo = { ...mockDacpacEndpoint };
@@ -109,7 +109,7 @@ export async function setDacpacEndpointInfo(path: string): Promise<mssql.SchemaC
return endpointInfo;
}
export async function setDatabaseEndpointInfo(): Promise<mssql.SchemaCompareEndpointInfo> {
export function setDatabaseEndpointInfo(): mssql.SchemaCompareEndpointInfo {
let endpointInfo: mssql.SchemaCompareEndpointInfo;
let dbName = 'My Database';
let serverName = 'My Server';

View File

@@ -15,7 +15,7 @@ import { createContext, TestContext } from './testContext';
let testContext: TestContext;
describe('utils: Tests to verify getEndpointName', function (): void {
it('Should generate correct endpoint information', async () => {
it('Should generate correct endpoint information', () => {
let endpointInfo: mssql.SchemaCompareEndpointInfo;
should(getEndpointName(endpointInfo)).equal(' ');
@@ -23,14 +23,14 @@ describe('utils: Tests to verify getEndpointName', function (): void {
should(getEndpointName(mockDatabaseEndpoint)).equal(' ');
});
it('Should get endpoint information from ConnectionInfo', async () => {
it('Should get endpoint information from ConnectionInfo', () => {
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {...mockDatabaseEndpoint};
testDatabaseEndpoint.connectionDetails = {...mockConnectionInfo};
should(getEndpointName(testDatabaseEndpoint)).equal('My Server.My Database');
});
it('Should get correct endpoint information from SchemaCompareEndpointInfo', async () => {
it('Should get correct endpoint information from SchemaCompareEndpointInfo', () => {
let dbName = 'My Database';
let serverName = 'My Server';
let testDatabaseEndpoint: mssql.SchemaCompareEndpointInfo = {...mockDatabaseEndpoint};
@@ -42,7 +42,7 @@ describe('utils: Tests to verify getEndpointName', function (): void {
});
describe('utils: Basic tests to verify verifyConnectionAndGetOwnerUri', function (): void {
before(async function (): Promise<void> {
before(function (): void {
testContext = createContext();
});
@@ -65,7 +65,7 @@ describe('utils: Basic tests to verify verifyConnectionAndGetOwnerUri', function
});
describe('utils: In-depth tests to verify verifyConnectionAndGetOwnerUri', function (): void {
before(async function (): Promise<void> {
before(function (): void {
testContext = createContext();
});