mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-15 01:25:36 -05:00
resend previous PR with test fixes (#19912)
* Revert "Revert "use reliable way to detect createtable statements (#19897)" (#19906)"
This reverts commit c211fb981c.
* fix tests
* fix test cases
This commit is contained in:
@@ -39,7 +39,7 @@ describe('Publish Database Dialog', () => {
|
||||
sdkStyle: false
|
||||
});
|
||||
|
||||
const project = new Project(projFilePath);
|
||||
const project = await Project.openProject(projFilePath);
|
||||
const publishDatabaseDialog = new PublishDatabaseDialog(project);
|
||||
publishDatabaseDialog.openDialog();
|
||||
should.notEqual(publishDatabaseDialog.publishTab, undefined);
|
||||
|
||||
@@ -12,6 +12,7 @@ import * as TypeMoq from 'typemoq';
|
||||
import { PublishOptionsDialog } from '../../dialogs/publishOptionsDialog';
|
||||
import { PublishDatabaseDialog } from '../../dialogs/publishDatabaseDialog';
|
||||
import { Project } from '../../models/project';
|
||||
import sinon = require('sinon');
|
||||
|
||||
describe('Publish Database Options Dialog', () => {
|
||||
before(async function (): Promise<void> {
|
||||
@@ -19,6 +20,8 @@ describe('Publish Database Options Dialog', () => {
|
||||
});
|
||||
|
||||
it('Should open dialog successfully ', async function (): Promise<void> {
|
||||
const proj = new Project('');
|
||||
sinon.stub(proj, 'getProjectTargetVersion').returns('150');
|
||||
const publishDatabaseDialog = new PublishDatabaseDialog(new Project(''));
|
||||
const optionsDialog = new PublishOptionsDialog(testData.getDeploymentOptions(), publishDatabaseDialog);
|
||||
optionsDialog.openDialog();
|
||||
|
||||
@@ -366,28 +366,36 @@ describe('ProjectsController', function (): void {
|
||||
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||
projController.callBase = true;
|
||||
projController.setup(x => x.getPublishDialog(TypeMoq.It.isAny())).returns(() => publishDialog.object);
|
||||
|
||||
void projController.object.publishProject(new Project('FakePath'));
|
||||
const proj = new Project('FakePath');
|
||||
sinon.stub(proj, 'getProjectTargetVersion').returns('150');
|
||||
void projController.object.publishProject(proj);
|
||||
should(opened).equal(true);
|
||||
});
|
||||
|
||||
it('Callbacks are hooked up and called from Publish dialog', async function (): Promise<void> {
|
||||
const projPath = path.dirname(await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline));
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, projPath);
|
||||
const proj = new Project(projPath);
|
||||
const projectFile = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline)
|
||||
const projFolder = path.dirname(projectFile);
|
||||
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, projFolder);
|
||||
const proj = await Project.openProject(projectFile);
|
||||
|
||||
const publishHoller = 'hello from callback for publish()';
|
||||
const generateHoller = 'hello from callback for generateScript()';
|
||||
|
||||
let holler = 'nothing';
|
||||
|
||||
let publishDialog = TypeMoq.Mock.ofType(PublishDatabaseDialog, undefined, undefined, proj);
|
||||
publishDialog.callBase = true;
|
||||
publishDialog.setup(x => x.getConnectionUri()).returns(() => Promise.resolve('fake|connection|uri'));
|
||||
const setupPublishDialog = (): PublishDatabaseDialog => {
|
||||
const dialog = new PublishDatabaseDialog(proj);
|
||||
sinon.stub(dialog, 'getConnectionUri').returns(Promise.resolve('fake|connection|uri'));
|
||||
return dialog;
|
||||
};
|
||||
|
||||
let publishDialog = setupPublishDialog();
|
||||
|
||||
let projController = TypeMoq.Mock.ofType(ProjectsController);
|
||||
projController.callBase = true;
|
||||
projController.setup(x => x.getPublishDialog(TypeMoq.It.isAny())).returns(() => publishDialog.object);
|
||||
projController.setup(x => x.getPublishDialog(TypeMoq.It.isAny())).returns(() => {
|
||||
return publishDialog;
|
||||
});
|
||||
projController.setup(x => x.publishOrScriptProject(TypeMoq.It.isAny(), TypeMoq.It.isAny(), true)).returns(() => {
|
||||
holler = publishHoller;
|
||||
return Promise.resolve(undefined);
|
||||
@@ -397,14 +405,15 @@ describe('ProjectsController', function (): void {
|
||||
holler = generateHoller;
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
publishDialog.object.publishToExistingServer = true;
|
||||
publishDialog.publishToExistingServer = true;
|
||||
void projController.object.publishProject(proj);
|
||||
await publishDialog.object.publishClick();
|
||||
await publishDialog.publishClick();
|
||||
|
||||
should(holler).equal(publishHoller, 'executionCallback() is supposed to have been setup and called for Publish scenario');
|
||||
|
||||
publishDialog = setupPublishDialog();
|
||||
void projController.object.publishProject(proj);
|
||||
await publishDialog.object.generateScriptClick();
|
||||
await publishDialog.generateScriptClick();
|
||||
|
||||
should(holler).equal(generateHoller, 'executionCallback() is supposed to have been setup and called for GenerateScript scenario');
|
||||
});
|
||||
@@ -603,6 +612,11 @@ describe('ProjectsController', function (): void {
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
dataWorkspaceMock.setup(x => x.getProjectsInWorkspace(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve([vscode.Uri.file(project1.projectFilePath), vscode.Uri.file(project2.projectFilePath)]));
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
||||
sinon.stub(utils, 'getDacFxService').returns(<any>{
|
||||
parseTSqlScript: (_: string, __: string) => {
|
||||
return Promise.resolve({ containsCreateTableStatement: true });
|
||||
}
|
||||
});
|
||||
|
||||
// add project reference from project1 to project2
|
||||
await projController.addDatabaseReferenceCallback(project1, {
|
||||
@@ -633,7 +647,11 @@ describe('ProjectsController', function (): void {
|
||||
const showErrorMessageSpy = sinon.spy(vscode.window, 'showErrorMessage');
|
||||
const dataWorkspaceMock = TypeMoq.Mock.ofType<dataworkspace.IExtension>();
|
||||
sinon.stub(vscode.extensions, 'getExtension').returns(<any>{ exports: dataWorkspaceMock.object });
|
||||
|
||||
sinon.stub(utils, 'getDacFxService').returns(<any>{
|
||||
parseTSqlScript: (_: string, __: string) => {
|
||||
return Promise.resolve({ containsCreateTableStatement: true });
|
||||
}
|
||||
});
|
||||
// add dacpac reference to something in the same folder
|
||||
should(project1.databaseReferences.length).equal(0, 'There should not be any database references to start with');
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ export class MockDacFxService implements mssql.IDacFxService {
|
||||
public generateDeployPlan(_: string, __: string, ___: string, ____: azdata.TaskExecutionMode): Thenable<mssql.GenerateDeployPlanResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public getOptionsFromProfile(_: string): Thenable<mssql.DacFxOptionsResult> { return Promise.resolve(mockDacFxOptionsResult); }
|
||||
public validateStreamingJob(_: string, __: string): Thenable<mssql.ValidateStreamingJobResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public parseTSqlScript(_: string, __: string): Thenable<mssql.ParseTSqlScriptResult> { return Promise.resolve({ containsCreateTableStatement: true }); }
|
||||
}
|
||||
|
||||
export function createContext(): TestContext {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as constants from '../common/constants';
|
||||
import * as templates from '../templates/templates';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import should = require('should');
|
||||
@@ -30,6 +31,10 @@ export async function shouldThrowSpecificError(block: Function, expectedMessage:
|
||||
|
||||
export async function createTestSqlProjFile(contents: string, folderPath?: string): Promise<string> {
|
||||
folderPath = folderPath ?? path.join(await generateTestFolderPath(), 'TestProject');
|
||||
const macroDict: Record<string, string> = {
|
||||
'PROJECT_DSP': constants.defaultDSP
|
||||
};
|
||||
contents = templates.macroExpansion(contents, macroDict);
|
||||
return await createTestFile(contents, 'TestProject.sqlproj', folderPath);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user