Delete database reference (#12531)

* remove ItemGroup if node being removed is the only one

* fix for if ItemGroup has elements with different tag names

* fix for ItemGroups not at the end of the sqlproj

* add delete for db references

* fix failing tests

* add test

* cleanup

* Addressing comments and fixing a string
This commit is contained in:
Kim Santiago
2020-09-24 17:27:13 -07:00
committed by GitHub
parent 9780eebb12
commit 49de1f80cf
6 changed files with 105 additions and 14 deletions

View File

@@ -12,7 +12,7 @@ import * as testUtils from './testUtils';
import * as constants from '../common/constants';
import { promises as fs } from 'fs';
import { Project, EntryType, TargetPlatform, SystemDatabase, DacpacReferenceProjectEntry, SqlProjectReferenceProjectEntry } from '../models/project';
import { Project, EntryType, TargetPlatform, SystemDatabase, SystemDatabaseReferenceProjectEntry, SqlProjectReferenceProjectEntry } from '../models/project';
import { exists, convertSlashesForSqlProj } from '../common/utils';
import { Uri, window } from 'vscode';
@@ -47,7 +47,7 @@ describe('Project: sqlproj content operations', function (): void {
// should only have one database reference even though there are two master.dacpac references (1 for ADS and 1 for SSDT)
should(project.databaseReferences.length).equal(1);
should(project.databaseReferences[0].databaseName).containEql(constants.master);
should(project.databaseReferences[0] instanceof DacpacReferenceProjectEntry).equal(true);
should(project.databaseReferences[0] instanceof SystemDatabaseReferenceProjectEntry).equal(true);
// Pre-post deployment scripts
should(project.preDeployScripts.length).equal(1);
@@ -67,7 +67,7 @@ describe('Project: sqlproj content operations', function (): void {
// should only have two database references even though there are two master.dacpac references (1 for ADS and 1 for SSDT)
should(project.databaseReferences.length).equal(2);
should(project.databaseReferences[0].databaseName).containEql(constants.master);
should(project.databaseReferences[0] instanceof DacpacReferenceProjectEntry).equal(true);
should(project.databaseReferences[0] instanceof SystemDatabaseReferenceProjectEntry).equal(true);
should(project.databaseReferences[1].databaseName).containEql('TestProjectName');
should(project.databaseReferences[1] instanceof SqlProjectReferenceProjectEntry).equal(true);
});

View File

@@ -236,6 +236,39 @@ describe('ProjectsController', function (): void {
should(await exists(noneEntry.fsUri.fsPath)).equal(false, 'none entry pre-deployment script is supposed to be deleted');
});
it('Should delete database references', async function (): Promise<void> {
// setup - openProject baseline has a system db reference to master
const proj = await testUtils.createTestProject(baselines.openProjectFileBaseline);
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
sinon.stub(vscode.window, 'showWarningMessage').returns(<any>Promise.resolve(constants.yesString));
// add dacpac reference
proj.addDatabaseReference({
dacpacFileLocation: vscode.Uri.file('test2.dacpac'),
databaseName: 'test2DbName',
databaseVariable: 'test2Db',
suppressMissingDependenciesErrors: false
});
// add project reference
proj.addProjectReference({
projectName: 'project1',
projectGuid: '',
projectRelativePath: vscode.Uri.file(path.join('..','project1', 'project1.sqlproj')),
suppressMissingDependenciesErrors: false
});
const projTreeRoot = new ProjectRootTreeItem(proj);
should(proj.databaseReferences.length).equal(3, 'Should start with 3 database references');
const databaseReferenceNodeChildren = projTreeRoot.children.find(x => x.friendlyName === constants.databaseReferencesNodeName)?.children;
await projController.delete(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'master')!); // system db reference
await projController.delete(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'test2')!); // dacpac reference
await projController.delete(databaseReferenceNodeChildren?.find(x => x.friendlyName === 'project1')!); // project reference
// confirm result
should(proj.databaseReferences.length).equal(0, 'All database references should have been deleted');
});
it('Should exclude nested ProjectEntry from node', async function (): Promise<void> {
let proj = await testUtils.createTestProject(templates.newSqlProjectTemplate);
const setupResult = await setupDeleteExcludeTest(proj);