mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 17:52:34 -05:00
Removing ApiWrapper and adding sinon (#11340)
* Added sinon removed api wrapper removed unnecesaary utils * merged from testfix * merged from aasim/import/downloadTestFix * merge from aasim/import/downloadTestFix
This commit is contained in:
@@ -5,14 +5,12 @@
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { ImportDataModel } from './models';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
|
||||
export abstract class BasePage {
|
||||
|
||||
protected readonly wizardPage: azdata.window.WizardPage;
|
||||
protected readonly model: ImportDataModel;
|
||||
protected readonly view: azdata.ModelView;
|
||||
protected _apiWrapper: ApiWrapper;
|
||||
|
||||
/**
|
||||
* This method constructs all the elements of the page.
|
||||
@@ -45,7 +43,7 @@ export abstract class BasePage {
|
||||
public abstract setupNavigationValidator(): void;
|
||||
|
||||
public async getServerValues(): Promise<{ connection: azdata.connection.Connection, displayName: string, name: string }[]> {
|
||||
let cons = await this._apiWrapper.getActiveConnections();
|
||||
let cons = await azdata.connection.getActiveConnections();
|
||||
// This user has no active connections ABORT MISSION
|
||||
if (!cons || cons.length === 0) {
|
||||
return undefined;
|
||||
@@ -95,7 +93,7 @@ export abstract class BasePage {
|
||||
public async getDatabaseValues(): Promise<{ displayName: string, name: string }[]> {
|
||||
let idx = -1;
|
||||
let count = -1;
|
||||
let values = (await this._apiWrapper.listDatabases(this.model.server.connectionId)).map(db => {
|
||||
let values = (await azdata.connection.listDatabases(this.model.server.connectionId)).map(db => {
|
||||
count++;
|
||||
if (this.model.database && db === this.model.database) {
|
||||
idx = count;
|
||||
|
||||
@@ -8,7 +8,6 @@ import * as azdata from 'azdata';
|
||||
import { FlatFileProvider } from '../../services/contracts';
|
||||
import { FlatFileWizard } from '../flatFileWizard';
|
||||
import { BasePage } from './basePage';
|
||||
import { ApiWrapper } from '../../common/apiWrapper';
|
||||
|
||||
export abstract class ImportPage extends BasePage {
|
||||
|
||||
@@ -19,13 +18,12 @@ export abstract class ImportPage extends BasePage {
|
||||
protected readonly provider: FlatFileProvider;
|
||||
|
||||
|
||||
constructor(instance: FlatFileWizard, wizardPage: azdata.window.WizardPage, model: ImportDataModel, view: azdata.ModelView, provider: FlatFileProvider, apiWrapper: ApiWrapper) {
|
||||
constructor(instance: FlatFileWizard, wizardPage: azdata.window.WizardPage, model: ImportDataModel, view: azdata.ModelView, provider: FlatFileProvider) {
|
||||
super();
|
||||
this.instance = instance;
|
||||
this.wizardPage = wizardPage;
|
||||
this.model = model;
|
||||
this.view = view;
|
||||
this.provider = provider;
|
||||
this._apiWrapper = apiWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import { FlatFileProvider } from '../services/contracts';
|
||||
import { ImportDataModel } from './api/models';
|
||||
import { ImportPage } from './api/importPage';
|
||||
@@ -12,7 +13,6 @@ import { FileConfigPage } from './pages/fileConfigPage';
|
||||
import { ProsePreviewPage } from './pages/prosePreviewPage';
|
||||
import { ModifyColumnsPage } from './pages/modifyColumnsPage';
|
||||
import { SummaryPage } from './pages/summaryPage';
|
||||
import { ApiWrapper } from '../common/apiWrapper';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
export class FlatFileWizard {
|
||||
@@ -27,7 +27,6 @@ export class FlatFileWizard {
|
||||
|
||||
constructor(
|
||||
provider: FlatFileProvider,
|
||||
private _apiWrapper: ApiWrapper
|
||||
) {
|
||||
this.provider = provider;
|
||||
}
|
||||
@@ -51,16 +50,16 @@ export class FlatFileWizard {
|
||||
|
||||
model.serverId = connectionId;
|
||||
|
||||
this.wizard = this._apiWrapper.createWizard(constants.wizardNameText);
|
||||
this.page1 = this._apiWrapper.createWizardPage(constants.page1NameText);
|
||||
this.page2 = this._apiWrapper.createWizardPage(constants.page2NameText);
|
||||
this.page3 = this._apiWrapper.createWizardPage(constants.page3NameText);
|
||||
this.page4 = this._apiWrapper.createWizardPage(constants.page4NameText);
|
||||
this.wizard = azdata.window.createWizard(constants.wizardNameText);
|
||||
this.page1 = azdata.window.createWizardPage(constants.page1NameText);
|
||||
this.page2 = azdata.window.createWizardPage(constants.page2NameText);
|
||||
this.page3 = azdata.window.createWizardPage(constants.page3NameText);
|
||||
this.page4 = azdata.window.createWizardPage(constants.page4NameText);
|
||||
|
||||
let fileConfigPage: FileConfigPage;
|
||||
|
||||
this.page1.registerContent(async (view) => {
|
||||
fileConfigPage = new FileConfigPage(this, this.page1, model, view, this.provider, this._apiWrapper);
|
||||
fileConfigPage = new FileConfigPage(this, this.page1, model, view, this.provider);
|
||||
pages.set(0, fileConfigPage);
|
||||
await fileConfigPage.start().then(() => {
|
||||
fileConfigPage.setupNavigationValidator();
|
||||
@@ -70,14 +69,14 @@ export class FlatFileWizard {
|
||||
|
||||
let prosePreviewPage: ProsePreviewPage;
|
||||
this.page2.registerContent(async (view) => {
|
||||
prosePreviewPage = new ProsePreviewPage(this, this.page2, model, view, this.provider, this._apiWrapper);
|
||||
prosePreviewPage = new ProsePreviewPage(this, this.page2, model, view, this.provider);
|
||||
pages.set(1, prosePreviewPage);
|
||||
await prosePreviewPage.start();
|
||||
});
|
||||
|
||||
let modifyColumnsPage: ModifyColumnsPage;
|
||||
this.page3.registerContent(async (view) => {
|
||||
modifyColumnsPage = new ModifyColumnsPage(this, this.page3, model, view, this.provider, this._apiWrapper);
|
||||
modifyColumnsPage = new ModifyColumnsPage(this, this.page3, model, view, this.provider);
|
||||
pages.set(2, modifyColumnsPage);
|
||||
await modifyColumnsPage.start();
|
||||
});
|
||||
@@ -85,13 +84,13 @@ export class FlatFileWizard {
|
||||
let summaryPage: SummaryPage;
|
||||
|
||||
this.page4.registerContent(async (view) => {
|
||||
summaryPage = new SummaryPage(this, this.page4, model, view, this.provider, this._apiWrapper);
|
||||
summaryPage = new SummaryPage(this, this.page4, model, view, this.provider);
|
||||
pages.set(3, summaryPage);
|
||||
await summaryPage.start();
|
||||
});
|
||||
|
||||
|
||||
this.importAnotherFileButton = this._apiWrapper.createButton(constants.importNewFileText);
|
||||
this.importAnotherFileButton = azdata.window.createButton(constants.importNewFileText);
|
||||
this.importAnotherFileButton.onClick(() => {
|
||||
//TODO replace this with proper cleanup for all the pages
|
||||
this.wizard.close();
|
||||
@@ -124,20 +123,20 @@ export class FlatFileWizard {
|
||||
}
|
||||
|
||||
public async getConnectionId(): Promise<string> {
|
||||
let currentConnection = await this._apiWrapper.getCurrentConnection();
|
||||
let currentConnection = await azdata.connection.getCurrentConnection();
|
||||
|
||||
let connectionId: string;
|
||||
|
||||
if (!currentConnection) {
|
||||
let connection = await this._apiWrapper.openConnectionDialog(constants.supportedProviders);
|
||||
let connection = await azdata.connection.openConnectionDialog(constants.supportedProviders);
|
||||
if (!connection) {
|
||||
this._apiWrapper.showErrorMessage(constants.needConnectionText);
|
||||
vscode.window.showErrorMessage(constants.needConnectionText);
|
||||
return undefined;
|
||||
}
|
||||
connectionId = connection.connectionId;
|
||||
} else {
|
||||
if (currentConnection.providerId !== 'MSSQL') {
|
||||
this._apiWrapper.showErrorMessage(constants.needSqlConnectionText);
|
||||
vscode.window.showErrorMessage(constants.needSqlConnectionText);
|
||||
return undefined;
|
||||
}
|
||||
connectionId = currentConnection.connectionId;
|
||||
|
||||
@@ -188,8 +188,8 @@ export class FileConfigPage extends ImportPage {
|
||||
this.databaseDropdown.onValueChanged(async (db) => {
|
||||
this.model.database = (<azdata.CategoryValue>this.databaseDropdown.value).name;
|
||||
//this.populateTableNames();
|
||||
let connectionProvider = this._apiWrapper.getProvider<azdata.ConnectionProvider>(this.model.server.providerName, azdata.DataProviderType.ConnectionProvider);
|
||||
let connectionUri = await this._apiWrapper.getUriForConnection(this.model.server.connectionId);
|
||||
let connectionProvider = azdata.dataprotocol.getProvider<azdata.ConnectionProvider>(this.model.server.providerName, azdata.DataProviderType.ConnectionProvider);
|
||||
let connectionUri = await azdata.connection.getUriForConnection(this.model.server.connectionId);
|
||||
connectionProvider.changeDatabase(connectionUri, this.model.database);
|
||||
this.populateSchemaDropdown();
|
||||
});
|
||||
@@ -372,8 +372,8 @@ export class FileConfigPage extends ImportPage {
|
||||
}
|
||||
|
||||
public async getSchemaValues(): Promise<{ displayName: string, name: string }[]> {
|
||||
let connectionUri = await this._apiWrapper.getUriForConnection(this.model.server.connectionId);
|
||||
let queryProvider = this._apiWrapper.getProvider<azdata.QueryProvider>(this.model.server.providerName, azdata.DataProviderType.QueryProvider);
|
||||
let connectionUri = await azdata.connection.getUriForConnection(this.model.server.connectionId);
|
||||
let queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(this.model.server.providerName, azdata.DataProviderType.QueryProvider);
|
||||
|
||||
let results = await queryProvider.runQueryAndReturn(connectionUri, constants.selectSchemaQuery);
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ export class SummaryPage extends ImportPage {
|
||||
|
||||
try {
|
||||
result = await this.provider.sendInsertDataRequest({
|
||||
connectionString: await this._apiWrapper.getConnectionString(this.model.server.connectionId, includePasswordInConnectionString),
|
||||
connectionString: await azdata.connection.getConnectionString(this.model.server.connectionId, includePasswordInConnectionString),
|
||||
//TODO check what SSMS uses as batch size
|
||||
batchSize: 500
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user