Tests for round tripping with SSDT projects (#10646)

* Test code for round tripping feature

* Fixed tests. Edited updateImportedTargetsToProjFile method to push newly added import target to the list.

* Added couple more tests

* Addressed comment
This commit is contained in:
Sakshi Sharma
2020-06-03 14:02:50 -07:00
committed by GitHub
parent 3860f07cab
commit c903112451
8 changed files with 260 additions and 20 deletions

View File

@@ -8,7 +8,7 @@ import * as xmldom from 'xmldom';
import * as constants from '../common/constants';
import * as utils from '../common/utils';
import { Uri, window } from 'vscode';
import { Uri } from 'vscode';
import { promises as fs } from 'fs';
import { DataSource } from './dataSources/dataSources';
@@ -62,17 +62,9 @@ export class Project {
}
public async updateProjectForRoundTrip() {
if (this.importedTargets.includes(constants.NetCoreTargets)) {
return;
}
window.showWarningMessage(constants.updateProjectForRoundTrip, constants.yesString, constants.noString).then(async (result) => {
if (result === constants.yesString) {
await fs.copyFile(this.projectFilePath, this.projectFilePath + '_backup');
await this.updateImportToSupportRoundTrip();
await this.updatePackageReferenceInProjFile();
}
});
await fs.copyFile(this.projectFilePath, this.projectFilePath + '_backup');
await this.updateImportToSupportRoundTrip();
await this.updatePackageReferenceInProjFile();
}
private async updateImportToSupportRoundTrip(): Promise<void> {
@@ -81,13 +73,13 @@ export class Project {
const importTarget = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.Import)[i];
let condition = importTarget.getAttribute(constants.Condition);
let project = importTarget.getAttribute(constants.Project);
let projectAttributeVal = importTarget.getAttribute(constants.Project);
if (condition === constants.SqlDbPresentCondition && project === constants.SqlDbTargets) {
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbPresentCondition, project, importTarget);
if (condition === constants.SqlDbPresentCondition && projectAttributeVal === constants.SqlDbTargets) {
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbPresentCondition, projectAttributeVal, importTarget);
}
if (condition === constants.SqlDbNotPresentCondition && project === constants.MsBuildtargets) {
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbNotPresentCondition, project, importTarget);
if (condition === constants.SqlDbNotPresentCondition && projectAttributeVal === constants.MsBuildtargets) {
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbNotPresentCondition, projectAttributeVal, importTarget);
}
}
@@ -185,16 +177,17 @@ export class Project {
this.findOrCreateItemGroup(constants.Folder).appendChild(newFolderNode);
}
private async updateImportedTargetsToProjFile(condition: string, project: string, oldImportNode?: any): Promise<any> {
private async updateImportedTargetsToProjFile(condition: string, projectAttributeVal: string, oldImportNode?: any): Promise<any> {
const importNode = this.projFileXmlDoc.createElement(constants.Import);
importNode.setAttribute(constants.Condition, condition);
importNode.setAttribute(constants.Project, project);
importNode.setAttribute(constants.Project, projectAttributeVal);
if (oldImportNode) {
this.projFileXmlDoc.documentElement.replaceChild(importNode, oldImportNode);
}
else {
this.projFileXmlDoc.documentElement.appendChild(importNode, oldImportNode);
this.importedTargets.push(projectAttributeVal); // Add new import target to the list
}
await this.serializeToProjFile(this.projFileXmlDoc);