Add target platform as an option in create project api (#16035)

* add target platform as an option in create project api

* add test

* move constant
This commit is contained in:
Kim Santiago
2021-07-12 15:14:33 -07:00
committed by GitHub
parent 9fc2cff654
commit affe3a838b
8 changed files with 82 additions and 40 deletions

View File

@@ -16,6 +16,7 @@ import { Project, EntryType, SystemDatabase, SystemDatabaseReferenceProjectEntry
import { exists, convertSlashesForSqlProj, trimChars, trimUri } from '../common/utils';
import { Uri, window } from 'vscode';
import { IDacpacReferenceSettings, IProjectReferenceSettings, ISystemDatabaseReferenceSettings } from '../models/IDatabaseReferenceSettings';
import { SqlTargetPlatform } from 'sqldbproj';
let projFilePath: string;
@@ -155,19 +156,19 @@ describe('Project: sqlproj content operations', function (): void {
should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '150', constants.masterDacpac)).fsPath);
should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '150', 'SqlSchemas', constants.masterDacpac)).fsPath);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlServer2016)!);
uri = project.getSystemDacpacUri(constants.masterDacpac);
ssdtUri = project.getSystemDacpacSsdtUri(constants.masterDacpac);
should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.masterDacpac)).fsPath);
should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '130', 'SqlSchemas', constants.masterDacpac)).fsPath);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlAzure)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure)!);
uri = project.getSystemDacpacUri(constants.masterDacpac);
ssdtUri = project.getSystemDacpacSsdtUri(constants.masterDacpac);
should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureV12', constants.masterDacpac)).fsPath);
should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureV12', 'SqlSchemas', constants.masterDacpac)).fsPath);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlDW)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlDW)!);
uri = project.getSystemDacpacUri(constants.masterDacpac);
ssdtUri = project.getSystemDacpacSsdtUri(constants.masterDacpac);
should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureDw', constants.masterDacpac)).fsPath);
@@ -189,17 +190,17 @@ describe('Project: sqlproj content operations', function (): void {
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '150', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should be 150');
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '150', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be 150');
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlServer2016)!);
projFileText = await fs.readFile(projFilePath);
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should have been updated to 130');
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '130', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be 130');
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlAzure)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure)!);
projFileText = await fs.readFile(projFilePath);
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureV12', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should have been updated to AzureV12');
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureV12', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be AzureV12');
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlDW)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlDW)!);
projFileText = await fs.readFile(projFilePath);
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureDw', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should have been updated to AzureDw');
should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureDw', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be AzureDw');
@@ -214,7 +215,7 @@ describe('Project: sqlproj content operations', function (): void {
should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '150', constants.msdbDacpac)).fsPath);
should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '150', 'SqlSchemas', constants.msdbDacpac)).fsPath);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!);
await project.changeTargetPlatform(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlServer2016)!);
uri = project.getSystemDacpacUri(constants.msdbDacpac);
ssdtUri = project.getSystemDacpacSsdtUri(constants.msdbDacpac);
should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.msdbDacpac)).fsPath);

View File

@@ -31,6 +31,7 @@ import { AddDatabaseReferenceDialog } from '../dialogs/addDatabaseReferenceDialo
import { IDacpacReferenceSettings } from '../models/IDatabaseReferenceSettings';
import { CreateProjectFromDatabaseDialog } from '../dialogs/createProjectFromDatabaseDialog';
import { ImportDataModel } from '../models/api/import';
import { SqlTargetPlatform } from 'sqldbproj';
let testContext: TestContext;
@@ -66,6 +67,25 @@ describe('ProjectsController', function (): void {
should(projFileText).equal(baselines.newProjectFileBaseline);
});
it('Should create new sqlproj file with correct specified target platform', async function (): Promise<void> {
const projController = new ProjectsController();
const projFileDir = path.join(os.tmpdir(), `TestProject_${new Date().getTime()}`);
const projTargetPlatform = SqlTargetPlatform.sqlAzure; // default is SQL Server 2019
const projFilePath = await projController.createNewProject({
newProjName: 'TestProjectName',
folderUri: vscode.Uri.file(projFileDir),
projectTypeId: constants.emptySqlDatabaseProjectTypeId,
projectGuid: 'BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575',
targetPlatform: projTargetPlatform
});
const project = await Project.openProject(projFilePath);
const projTargetVersion = project.getProjectTargetVersion();
should(constants.getTargetPlatformFromVersion(projTargetVersion)).equal(projTargetPlatform);
});
it('Should return silently when no SQL object name provided in prompts', async function (): Promise<void> {
for (const name of ['', ' ', undefined]) {
const showInputBoxStub = sinon.stub(vscode.window, 'showInputBox').resolves(name);
@@ -316,21 +336,21 @@ describe('ProjectsController', function (): void {
});
it('Should change target platform', async function (): Promise<void> {
sinon.stub(vscode.window, 'showQuickPick').resolves({ label: constants.sqlAzure });
sinon.stub(vscode.window, 'showQuickPick').resolves({ label: SqlTargetPlatform.sqlAzure });
const projController = new ProjectsController();
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline);
const project = await Project.openProject(sqlProjPath);
should(project.getProjectTargetVersion()).equal(constants.targetPlatformToVersion.get(constants.sqlServer2019));
should(project.getProjectTargetVersion()).equal(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlServer2019));
should(project.databaseReferences.length).equal(1, 'Project should have one database reference to master');
should(project.databaseReferences[0].fsUri.fsPath).containEql(constants.targetPlatformToVersion.get(constants.sqlServer2019));
should((<SystemDatabaseReferenceProjectEntry>project.databaseReferences[0]).ssdtUri.fsPath).containEql(constants.targetPlatformToVersion.get(constants.sqlServer2019));
should(project.databaseReferences[0].fsUri.fsPath).containEql(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlServer2019));
should((<SystemDatabaseReferenceProjectEntry>project.databaseReferences[0]).ssdtUri.fsPath).containEql(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlServer2019));
await projController.changeTargetPlatform(project);
should(project.getProjectTargetVersion()).equal(constants.targetPlatformToVersion.get(constants.sqlAzure));
should(project.getProjectTargetVersion()).equal(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure));
// verify system db reference got updated too
should(project.databaseReferences[0].fsUri.fsPath).containEql(constants.targetPlatformToVersion.get(constants.sqlAzure));
should((<SystemDatabaseReferenceProjectEntry>project.databaseReferences[0]).ssdtUri.fsPath).containEql(constants.targetPlatformToVersion.get(constants.sqlAzure));
should(project.databaseReferences[0].fsUri.fsPath).containEql(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure));
should((<SystemDatabaseReferenceProjectEntry>project.databaseReferences[0]).ssdtUri.fsPath).containEql(constants.targetPlatformToVersion.get(SqlTargetPlatform.sqlAzure));
});
});