mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 09:35:37 -05:00
Final ADS-side hookup for sqlcmd vars (#10815)
* Adding reading SqlCmdVars from project file * organized apiWrapper, added calls * Adding test to confirm deployment/script gen profiles with sqlcmd vars
This commit is contained in:
@@ -73,6 +73,16 @@
|
||||
<Folder Include="Views\User" />
|
||||
<Build Include="Views\User\Profile.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<SqlCmdVariable Include="ProdDatabaseName">
|
||||
<DefaultValue>MyProdDatabase</DefaultValue>
|
||||
<Value>$(SqlCmdVar__1)</Value>
|
||||
</SqlCmdVariable>
|
||||
<SqlCmdVariable Include="BackupDatabaseName">
|
||||
<DefaultValue>MyBackupDatabase</DefaultValue>
|
||||
<Value>$(SqlCmdVar__2)</Value>
|
||||
</SqlCmdVariable>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\130\master.dacpac">
|
||||
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
||||
|
||||
@@ -9,22 +9,29 @@ import * as os from 'os';
|
||||
import * as vscode from 'vscode';
|
||||
import * as baselines from './baselines/baselines';
|
||||
import * as templates from '../templates/templates';
|
||||
import * as testUtils from '../test/testUtils';
|
||||
import * as TypeMoq from 'typemoq';
|
||||
|
||||
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
||||
import { Project } from '../models/project';
|
||||
import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProjectTreeViewProvider';
|
||||
import { ProjectsController } from '../controllers/projectController';
|
||||
import { createContext, TestContext } from './testContext';
|
||||
import { IDeploymentProfile, IGenerateScriptProfile } from '../models/IDeploymentProfile';
|
||||
|
||||
|
||||
let testContext: TestContext;
|
||||
|
||||
describe('Deploy Database Dialog', () => {
|
||||
before(async function (): Promise<void> {
|
||||
testContext = createContext();
|
||||
await templates.loadTemplates(path.join(__dirname, '..', '..', 'resources', 'templates'));
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
beforeEach(async function (): Promise<void> {
|
||||
testContext = createContext();
|
||||
});
|
||||
|
||||
it('Should open dialog successfully ', async function (): Promise<void> {
|
||||
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
|
||||
@@ -47,4 +54,43 @@ describe('Deploy Database Dialog', () => {
|
||||
const deployDatabaseDialog = new DeployDatabaseDialog(testContext.apiWrapper.object, project);
|
||||
should.equal(deployDatabaseDialog.getDefaultDatabaseName(), project.projectFileName);
|
||||
});
|
||||
|
||||
it('Should include all info in deployment profile', async function (): Promise<void> {
|
||||
const proj = await testUtils.createTestProject(baselines.openProjectFileBaseline);
|
||||
const dialog = TypeMoq.Mock.ofType(DeployDatabaseDialog, undefined, undefined, testContext.apiWrapper.object, proj);
|
||||
dialog.setup(x => x.getConnectionUri()).returns(async () => { return 'Mock|Connection|Uri'; });
|
||||
dialog.setup(x => x.getTargetDatabaseName()).returns(() => 'MockDatabaseName');
|
||||
dialog.callBase = true;
|
||||
|
||||
let profile: IDeploymentProfile | IGenerateScriptProfile | undefined;
|
||||
|
||||
const expectedDeploy: IDeploymentProfile = {
|
||||
databaseName: 'MockDatabaseName',
|
||||
connectionUri: 'Mock|Connection|Uri',
|
||||
upgradeExisting: true,
|
||||
sqlCmdVariables: {
|
||||
'ProdDatabaseName': 'MyProdDatabase',
|
||||
'BackupDatabaseName': 'MyBackupDatabase'
|
||||
}
|
||||
};
|
||||
|
||||
dialog.object.deploy = async (_, prof) => { profile = prof; };
|
||||
await dialog.object.deployClick();
|
||||
|
||||
should(profile).deepEqual(expectedDeploy);
|
||||
|
||||
const expectedGenScript: IGenerateScriptProfile = {
|
||||
databaseName: 'MockDatabaseName',
|
||||
connectionUri: 'Mock|Connection|Uri',
|
||||
sqlCmdVariables: {
|
||||
'ProdDatabaseName': 'MyProdDatabase',
|
||||
'BackupDatabaseName': 'MyBackupDatabase'
|
||||
}
|
||||
};
|
||||
|
||||
dialog.object.generateScript = async (_, prof) => { profile = prof; };
|
||||
await dialog.object.generateScriptClick();
|
||||
|
||||
should(profile).deepEqual(expectedGenScript);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,12 +31,19 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
const project: Project = new Project(projFilePath);
|
||||
await project.readProjFile();
|
||||
|
||||
// Files and folders
|
||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(4);
|
||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(5);
|
||||
|
||||
should(project.files.find(f => f.type === EntryType.Folder && f.relativePath === 'Views\\User')).not.equal(undefined); // mixed ItemGroup folder
|
||||
should(project.files.find(f => f.type === EntryType.File && f.relativePath === 'Views\\User\\Profile.sql')).not.equal(undefined); // mixed ItemGroup file
|
||||
|
||||
// SqlCmdVariables
|
||||
should(Object.keys(project.sqlCmdVariables).length).equal(2);
|
||||
should(project.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
|
||||
should(project.sqlCmdVariables['BackupDatabaseName']).equal('MyBackupDatabase');
|
||||
|
||||
// Database references
|
||||
should(project.databaseReferences.length).equal(1);
|
||||
should(project.databaseReferences[0]).containEql(constants.master);
|
||||
});
|
||||
|
||||
@@ -32,7 +32,10 @@ export async function createTestSqlProjFile(contents: string, folderPath?: strin
|
||||
}
|
||||
|
||||
export async function createTestProject(contents: string, folderPath?: string): Promise<Project> {
|
||||
return new Project(await createTestSqlProjFile(contents, folderPath));
|
||||
const proj = new Project(await createTestSqlProjFile(contents, folderPath));
|
||||
await proj.readProjFile();
|
||||
|
||||
return proj;
|
||||
}
|
||||
|
||||
export async function createTestDataSources(contents: string, folderPath?: string): Promise<string> {
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('Tests for conversion within PascalCase and camelCase', function (): vo
|
||||
});
|
||||
|
||||
describe('Tests to verify exists function', function (): void {
|
||||
it('Should determine existance of files/folders', async () => {
|
||||
it('Should determine existence of files/folders', async () => {
|
||||
let testFolderPath = await createDummyFileStructure();
|
||||
|
||||
should(await exists(testFolderPath)).equal(true);
|
||||
|
||||
Reference in New Issue
Block a user