mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
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:
@@ -63,6 +63,10 @@ export class ApiWrapper {
|
|||||||
return vscode.window.showInformationMessage(message, ...items);
|
return vscode.window.showInformationMessage(message, ...items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public showWarningMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
||||||
|
return vscode.window.showWarningMessage(message, ...items);
|
||||||
|
}
|
||||||
|
|
||||||
public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined> {
|
public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined> {
|
||||||
return vscode.window.showOpenDialog(options);
|
return vscode.window.showOpenDialog(options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class ProjectsController {
|
|||||||
this.projects.push(newProject);
|
this.projects.push(newProject);
|
||||||
|
|
||||||
// Update for round tripping as needed
|
// Update for round tripping as needed
|
||||||
await newProject.updateProjectForRoundTrip();
|
await this.updateProjectForRoundTrip(newProject);
|
||||||
|
|
||||||
// Read datasources.json (if present)
|
// Read datasources.json (if present)
|
||||||
const dataSourcesFilePath = path.join(path.dirname(projectFile.fsPath), constants.dataSourcesFileName);
|
const dataSourcesFilePath = path.join(path.dirname(projectFile.fsPath), constants.dataSourcesFileName);
|
||||||
@@ -298,6 +298,17 @@ export class ProjectsController {
|
|||||||
return new DeployDatabaseDialog(this.apiWrapper, project);
|
return new DeployDatabaseDialog(this.apiWrapper, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updateProjectForRoundTrip(project: Project) {
|
||||||
|
if (project.importedTargets.includes(constants.NetCoreTargets)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await this.apiWrapper.showWarningMessage(constants.updateProjectForRoundTrip, constants.yesString, constants.noString);
|
||||||
|
if (result === constants.yesString) {
|
||||||
|
await project.updateProjectForRoundTrip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static getProjectFromContext(context: Project | BaseProjectTreeItem) {
|
private static getProjectFromContext(context: Project | BaseProjectTreeItem) {
|
||||||
if (context instanceof Project) {
|
if (context instanceof Project) {
|
||||||
return context;
|
return context;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import * as xmldom from 'xmldom';
|
|||||||
import * as constants from '../common/constants';
|
import * as constants from '../common/constants';
|
||||||
import * as utils from '../common/utils';
|
import * as utils from '../common/utils';
|
||||||
|
|
||||||
import { Uri, window } from 'vscode';
|
import { Uri } from 'vscode';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { DataSource } from './dataSources/dataSources';
|
import { DataSource } from './dataSources/dataSources';
|
||||||
|
|
||||||
@@ -62,18 +62,10 @@ export class Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async updateProjectForRoundTrip() {
|
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 fs.copyFile(this.projectFilePath, this.projectFilePath + '_backup');
|
||||||
await this.updateImportToSupportRoundTrip();
|
await this.updateImportToSupportRoundTrip();
|
||||||
await this.updatePackageReferenceInProjFile();
|
await this.updatePackageReferenceInProjFile();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private async updateImportToSupportRoundTrip(): Promise<void> {
|
private async updateImportToSupportRoundTrip(): Promise<void> {
|
||||||
// update an SSDT project to include Net core target information
|
// update an SSDT project to include Net core target information
|
||||||
@@ -81,13 +73,13 @@ export class Project {
|
|||||||
const importTarget = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.Import)[i];
|
const importTarget = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.Import)[i];
|
||||||
|
|
||||||
let condition = importTarget.getAttribute(constants.Condition);
|
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) {
|
if (condition === constants.SqlDbPresentCondition && projectAttributeVal === constants.SqlDbTargets) {
|
||||||
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbPresentCondition, project, importTarget);
|
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbPresentCondition, projectAttributeVal, importTarget);
|
||||||
}
|
}
|
||||||
if (condition === constants.SqlDbNotPresentCondition && project === constants.MsBuildtargets) {
|
if (condition === constants.SqlDbNotPresentCondition && projectAttributeVal === constants.MsBuildtargets) {
|
||||||
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbNotPresentCondition, project, importTarget);
|
await this.updateImportedTargetsToProjFile(constants.RoundTripSqlDbNotPresentCondition, projectAttributeVal, importTarget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,16 +177,17 @@ export class Project {
|
|||||||
this.findOrCreateItemGroup(constants.Folder).appendChild(newFolderNode);
|
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);
|
const importNode = this.projFileXmlDoc.createElement(constants.Import);
|
||||||
importNode.setAttribute(constants.Condition, condition);
|
importNode.setAttribute(constants.Condition, condition);
|
||||||
importNode.setAttribute(constants.Project, project);
|
importNode.setAttribute(constants.Project, projectAttributeVal);
|
||||||
|
|
||||||
if (oldImportNode) {
|
if (oldImportNode) {
|
||||||
this.projFileXmlDoc.documentElement.replaceChild(importNode, oldImportNode);
|
this.projFileXmlDoc.documentElement.replaceChild(importNode, oldImportNode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.projFileXmlDoc.documentElement.appendChild(importNode, oldImportNode);
|
this.projFileXmlDoc.documentElement.appendChild(importNode, oldImportNode);
|
||||||
|
this.importedTargets.push(projectAttributeVal); // Add new import target to the list
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.serializeToProjFile(this.projFileXmlDoc);
|
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<Name>TestProjectName</Name>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectVersion>4.1</ProjectVersion>
|
||||||
|
<ProjectGuid>{BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575}</ProjectGuid>
|
||||||
|
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider</DSP>
|
||||||
|
<OutputType>Database</OutputType>
|
||||||
|
<RootPath>
|
||||||
|
</RootPath>
|
||||||
|
<RootNamespace>TestProjectName</RootNamespace>
|
||||||
|
<AssemblyName>TestProjectName</AssemblyName>
|
||||||
|
<ModelCollation>1033, CI</ModelCollation>
|
||||||
|
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
|
||||||
|
<DeployToDatabase>True</DeployToDatabase>
|
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
|
<TargetLanguage>CS</TargetLanguage>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<SqlServerVerification>False</SqlServerVerification>
|
||||||
|
<IncludeCompositeObjects>True</IncludeCompositeObjects>
|
||||||
|
<TargetDatabaseSet>True</TargetDatabaseSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||||
|
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DefineDebug>false</DefineDebug>
|
||||||
|
<DefineTrace>true</DefineTrace>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<DefineDebug>true</DefineDebug>
|
||||||
|
<DefineTrace>true</DefineTrace>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||||
|
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
|
||||||
|
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
|
||||||
|
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Condition="'$(NetCoreBuild)' != 'true' AND '$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets"/>
|
||||||
|
<Import Condition="'$(NetCoreBuild)' != 'true' AND '$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets"/>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties"/>
|
||||||
|
<Folder Include="Tables"/>
|
||||||
|
<Folder Include="Views"/>
|
||||||
|
<Folder Include="Views\Maintenance"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Build Include="Tables\Users.sql"/>
|
||||||
|
<Build Include="Tables\Action History.sql"/>
|
||||||
|
<Build Include="Views\Maintenance\Database Performance.sql"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Views\User"/>
|
||||||
|
<Build Include="Views\User\Profile.sql"/>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Condition="'$(NetCoreBuild)' == 'true'" Project="$(NETCoreTargetsPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets"/><ItemGroup><PackageReference Condition="'$(NetCoreBuild)' == 'true'" Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All"/></ItemGroup></Project>
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<Name>TestProjectName</Name>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectVersion>4.1</ProjectVersion>
|
||||||
|
<ProjectGuid>{BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575}</ProjectGuid>
|
||||||
|
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider</DSP>
|
||||||
|
<OutputType>Database</OutputType>
|
||||||
|
<RootPath>
|
||||||
|
</RootPath>
|
||||||
|
<RootNamespace>TestProjectName</RootNamespace>
|
||||||
|
<AssemblyName>TestProjectName</AssemblyName>
|
||||||
|
<ModelCollation>1033, CI</ModelCollation>
|
||||||
|
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
|
||||||
|
<DeployToDatabase>True</DeployToDatabase>
|
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
|
<TargetLanguage>CS</TargetLanguage>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<SqlServerVerification>False</SqlServerVerification>
|
||||||
|
<IncludeCompositeObjects>True</IncludeCompositeObjects>
|
||||||
|
<TargetDatabaseSet>True</TargetDatabaseSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||||
|
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<DefineDebug>false</DefineDebug>
|
||||||
|
<DefineTrace>true</DefineTrace>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
|
||||||
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<DefineDebug>true</DefineDebug>
|
||||||
|
<DefineTrace>true</DefineTrace>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
|
||||||
|
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
|
||||||
|
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
|
||||||
|
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
|
||||||
|
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties" />
|
||||||
|
<Folder Include="Tables" />
|
||||||
|
<Folder Include="Views" />
|
||||||
|
<Folder Include="Views\Maintenance" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Build Include="Tables\Users.sql" />
|
||||||
|
<Build Include="Tables\Action History.sql" />
|
||||||
|
<Build Include="Views\Maintenance\Database Performance.sql" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Views\User" />
|
||||||
|
<Build Include="Views\User\Profile.sql" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -10,6 +10,8 @@ import { promises as fs } from 'fs';
|
|||||||
export let newProjectFileBaseline: string;
|
export let newProjectFileBaseline: string;
|
||||||
export let openProjectFileBaseline: string;
|
export let openProjectFileBaseline: string;
|
||||||
export let openDataSourcesBaseline: string;
|
export let openDataSourcesBaseline: string;
|
||||||
|
export let SSDTProjectFileBaseline: string;
|
||||||
|
export let SSDTProjectAfterUpdateBaseline: string;
|
||||||
|
|
||||||
const baselineFolderPath = __dirname;
|
const baselineFolderPath = __dirname;
|
||||||
|
|
||||||
@@ -17,6 +19,8 @@ export async function loadBaselines() {
|
|||||||
newProjectFileBaseline = await loadBaseline(baselineFolderPath, 'newSqlProjectBaseline.xml');
|
newProjectFileBaseline = await loadBaseline(baselineFolderPath, 'newSqlProjectBaseline.xml');
|
||||||
openProjectFileBaseline = await loadBaseline(baselineFolderPath, 'openSqlProjectBaseline.xml');
|
openProjectFileBaseline = await loadBaseline(baselineFolderPath, 'openSqlProjectBaseline.xml');
|
||||||
openDataSourcesBaseline = await loadBaseline(baselineFolderPath, 'openDataSourcesBaseline.json');
|
openDataSourcesBaseline = await loadBaseline(baselineFolderPath, 'openDataSourcesBaseline.json');
|
||||||
|
SSDTProjectFileBaseline = await loadBaseline(baselineFolderPath, 'SSDTProjectBaseline.xml');
|
||||||
|
SSDTProjectAfterUpdateBaseline = await loadBaseline(baselineFolderPath, 'SSDTProjectAfterUpdateBaseline.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {
|
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import * as testUtils from './testUtils';
|
|||||||
|
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { Project, EntryType } from '../models/project';
|
import { Project, EntryType } from '../models/project';
|
||||||
|
import { exists } from '../common/utils';
|
||||||
|
|
||||||
let projFilePath: string;
|
let projFilePath: string;
|
||||||
|
|
||||||
@@ -82,3 +83,23 @@ describe('Project: sqlproj content operations', function (): void {
|
|||||||
await testUtils.shouldThrowSpecificError(async () => await project.addToProject(list), `ENOENT: no such file or directory, stat \'${nonexistentFile}\'`);
|
await testUtils.shouldThrowSpecificError(async () => await project.addToProject(list), `ENOENT: no such file or directory, stat \'${nonexistentFile}\'`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Project: round trip updates', function (): void {
|
||||||
|
before(async function () : Promise<void> {
|
||||||
|
await baselines.loadBaselines();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should update SSDT project to work in ADS', async function (): Promise<void> {
|
||||||
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline);
|
||||||
|
const project: Project = new Project(projFilePath);
|
||||||
|
await project.readProjFile();
|
||||||
|
|
||||||
|
await project.updateProjectForRoundTrip();
|
||||||
|
|
||||||
|
should(await exists(projFilePath + '_backup')).equal(true); // backup file should be generated before the project is updated
|
||||||
|
should(project.importedTargets.length).equal(3); // additional target added by updateProjectForRoundTrip method
|
||||||
|
|
||||||
|
let projFileText = (await fs.readFile(projFilePath)).toString();
|
||||||
|
should(projFileText).equal(baselines.SSDTProjectAfterUpdateBaseline.trim());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { Project } from '../models/project';
|
|||||||
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
import { DeployDatabaseDialog } from '../dialogs/deployDatabaseDialog';
|
||||||
import { ApiWrapper } from '../common/apiWrapper';
|
import { ApiWrapper } from '../common/apiWrapper';
|
||||||
import { IDeploymentProfile, IGenerateScriptProfile } from '../models/IDeploymentProfile';
|
import { IDeploymentProfile, IGenerateScriptProfile } from '../models/IDeploymentProfile';
|
||||||
|
import { exists } from '../common/utils';
|
||||||
|
|
||||||
let testContext: TestContext;
|
let testContext: TestContext;
|
||||||
|
|
||||||
@@ -225,3 +226,65 @@ describe('ProjectsController: import operations', function (): void {
|
|||||||
await testUtils.shouldThrowSpecificError(async () => await projController.importNewDatabaseProject(mockConnectionProfile), constants.projectLocationNotEmpty);
|
await testUtils.shouldThrowSpecificError(async () => await projController.importNewDatabaseProject(mockConnectionProfile), constants.projectLocationNotEmpty);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ProjectsController: round trip feature with SSDT', function (): void {
|
||||||
|
it('Should show warning message for SSDT project opened in Azure Data Studio', async function (): Promise<void> {
|
||||||
|
testContext.apiWrapper.setup(x => x.showWarningMessage(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
|
||||||
|
|
||||||
|
// setup test files
|
||||||
|
const folderPath = await testUtils.generateTestFolderPath();
|
||||||
|
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||||
|
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||||
|
|
||||||
|
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||||
|
|
||||||
|
await testUtils.shouldThrowSpecificError(async () => await projController.openProject(vscode.Uri.file(sqlProjPath)), constants.updateProjectForRoundTrip);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should not show warning message for non-SSDT projects that have the additional information for Build', async function (): Promise<void> {
|
||||||
|
testContext.apiWrapper.setup(x => x.showWarningMessage(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
|
||||||
|
|
||||||
|
// setup test files
|
||||||
|
const folderPath = await testUtils.generateTestFolderPath();
|
||||||
|
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.openProjectFileBaseline, folderPath);
|
||||||
|
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||||
|
|
||||||
|
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||||
|
|
||||||
|
const project = await projController.openProject(vscode.Uri.file(sqlProjPath)); // no error thrown
|
||||||
|
|
||||||
|
should(project.importedTargets.length).equal(3); // additional target should exist by default
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should not update project and no backup file should be created when update to project is rejected', async function (): Promise<void> {
|
||||||
|
testContext.apiWrapper.setup(x => x.showWarningMessage(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(constants.noString));
|
||||||
|
|
||||||
|
// setup test files
|
||||||
|
const folderPath = await testUtils.generateTestFolderPath();
|
||||||
|
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||||
|
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||||
|
|
||||||
|
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||||
|
|
||||||
|
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||||
|
|
||||||
|
should(await exists(sqlProjPath+'_backup')).equal(false); // backup file should not be generated
|
||||||
|
should(project.importedTargets.length).equal(2); // additional target should not be added by updateProjectForRoundTrip method
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should load Project and associated import targets when update to project is accepted', async function (): Promise<void> {
|
||||||
|
testContext.apiWrapper.setup(x => x.showWarningMessage(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(constants.yesString));
|
||||||
|
|
||||||
|
// setup test files
|
||||||
|
const folderPath = await testUtils.generateTestFolderPath();
|
||||||
|
const sqlProjPath = await testUtils.createTestSqlProjFile(baselines.SSDTProjectFileBaseline, folderPath);
|
||||||
|
await testUtils.createTestDataSources(baselines.openDataSourcesBaseline, folderPath);
|
||||||
|
|
||||||
|
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
|
||||||
|
|
||||||
|
const project = await projController.openProject(vscode.Uri.file(sqlProjPath));
|
||||||
|
|
||||||
|
should(await exists(sqlProjPath+'_backup')).equal(true); // backup file should be generated before the project is updated
|
||||||
|
should(project.importedTargets.length).equal(3); // additional target added by updateProjectForRoundTrip method
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user