Adds support for checking and updating cross-compatibility for SQL Projects (#1847)

* Adding cross-platform check and update

* Checkpoint

* checkpoint

* Updating for latest nuget package

* Correctly typing the result object
This commit is contained in:
Benjin Dubishar
2023-02-07 19:06:13 -08:00
committed by GitHub
parent 8d119876d9
commit 19935552b1
9 changed files with 249 additions and 30 deletions

View File

@@ -57,5 +57,8 @@
</ItemGroup>
<ItemGroup>
<None Include="SchemaCompare\SqlProjects\emptyTemplate.sqlproj" />
<None Include="SqlProjects\Inputs\SSDTProject.sqlproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,67 @@
<?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>TestProjectLegacyNetFramework</Name>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>4.1</ProjectVersion>
<ProjectGuid>{BA5EBA11-C0DE-5EA7-ACED-BABB1E70A575}</ProjectGuid>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider</DSP>
<OutputType>Database</OutputType>
<RootPath>
</RootPath>
<RootNamespace>TestProjectLegacyNetFramework</RootNamespace>
<AssemblyName>TestProjectLegacyNetFramework</AssemblyName>
<ModelCollation>1033, CI</ModelCollation>
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
<DeployToDatabase>True</DeployToDatabase>
<TargetFrameworkVersion>v4.7.2</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" />
</ItemGroup>
<ItemGroup>
<ArtifactReference Include="$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\150\SqlSchemas\master.dacpac">
<HintPath>$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\150\SqlSchemas\master.dacpac</HintPath>
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
<DatabaseVariableLiteralValue>master</DatabaseVariableLiteralValue>
</ArtifactReference>
</ItemGroup>
</Project>

View File

@@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#nullable disable
using System;
using System.IO;
using System.Linq;
@@ -192,7 +190,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
Assert.AreEqual(1, service.Projects[projectUri].DatabaseReferences.Count, "Database references after adding system db reference");
SystemDatabaseReference systemDbRef = (SystemDatabaseReference)service.Projects[projectUri].DatabaseReferences.First(x => x is SystemDatabaseReference);
Assert.AreEqual(SystemDatabase.MSDB, systemDbRef.SystemDb, "Referenced system DB");
Assert.AreEqual("$(EmEssDeeBee)", systemDbRef.DatabaseVariable);
Assert.AreEqual("$(EmEssDeeBee)", systemDbRef.DatabaseVariableLiteralName);
Assert.IsFalse(systemDbRef.SuppressMissingDependencies, nameof(systemDbRef.SuppressMissingDependencies));
// Validate adding a dacpac reference
@@ -212,8 +210,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
Assert.AreEqual(2, service.Projects[projectUri].DatabaseReferences.Count, "Database references after adding dacpac reference");
DacpacReference dacpacRef = (DacpacReference)service.Projects[projectUri].DatabaseReferences.First(x => x is DacpacReference);
Assert.AreEqual(FileUtils.NormalizePath(mockReferencePath, PlatformID.Win32NT), dacpacRef.DacpacPath, "Referenced dacpac");
Assert.AreEqual(databaseVar.Name, dacpacRef.DatabaseVariable);
Assert.AreEqual(serverVar.Name, dacpacRef.ServerVariable);
Assert.AreEqual(databaseVar.Name, dacpacRef.DatabaseVariable.VarName);
Assert.AreEqual(serverVar.Name, dacpacRef.ServerVariable.VarName);
Assert.IsFalse(dacpacRef.SuppressMissingDependencies, nameof(dacpacRef.SuppressMissingDependencies));
// Validate adding a project reference
@@ -235,8 +233,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
SqlProjectReference projectRef = (SqlProjectReference)service.Projects[projectUri].DatabaseReferences.First(x => x is SqlProjectReference);
Assert.AreEqual(mockReferencePath, projectRef.ProjectPath, "Referenced project");
Assert.AreEqual(TEST_GUID, projectRef.ProjectGuid, "Referenced project GUID");
Assert.AreEqual(databaseVar.Name, projectRef.DatabaseVariable);
Assert.AreEqual(serverVar.Name, projectRef.ServerVariable);
Assert.AreEqual(databaseVar.Name, projectRef.DatabaseVariable.VarName);
Assert.AreEqual(serverVar.Name, projectRef.ServerVariable.VarName);
Assert.IsFalse(projectRef.SuppressMissingDependencies, nameof(projectRef.SuppressMissingDependencies));
// Validate deleting a reference
@@ -337,6 +335,46 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
requestMock.AssertSuccess(nameof(service.HandleDeleteSqlCmdVariableRequest));
Assert.AreEqual(0, service.Projects[projectUri].SqlCmdVariables.Count, "Number of SQLCMD variables after deletion not as expected");
}
[Test]
public async Task TestCrossPlatformUpdates()
{
string inputProjectPath = Path.Join(Path.GetDirectoryName(typeof(SqlProjectsServiceTests).Assembly.Location), "SqlProjects", "Inputs", "SSDTProject.sqlproj");
string projectPath = Path.Join(TestContext.CurrentContext.GetTestWorkingFolder(), "SSDTProject.sqlproj");
Directory.CreateDirectory(Path.GetDirectoryName(projectPath)!);
File.Copy(inputProjectPath, projectPath);
SqlProjectsService service = new();
/// Validate that the cross-platform status can be fetched
MockRequest<GetCrossPlatformCompatiblityResult> getRequestMock = new();
await service.HandleGetCrossPlatformCompatibilityRequest(new SqlProjectParams()
{
ProjectUri = projectPath
}, getRequestMock.Object);
getRequestMock.AssertSuccess(nameof(service.HandleGetCrossPlatformCompatibilityRequest));
Assert.IsFalse(getRequestMock.Result.IsCrossPlatformCompatible, "Input file should not be cross-platform compatible before conversion");
// Validate that the project can be updated
MockRequest<ResultStatus> updateRequestMock = new();
await service.HandleUpdateProjectForCrossPlatformRequest(new SqlProjectParams()
{
ProjectUri = projectPath,
}, updateRequestMock.Object);
updateRequestMock.AssertSuccess(nameof(service.HandleUpdateProjectForCrossPlatformRequest));
// Validate that the cross-platform status has changed
getRequestMock = new();
await service.HandleGetCrossPlatformCompatibilityRequest(new SqlProjectParams()
{
ProjectUri = projectPath
}, getRequestMock.Object);
getRequestMock.AssertSuccess(nameof(service.HandleGetCrossPlatformCompatibilityRequest));
Assert.IsTrue(((GetCrossPlatformCompatiblityResult)getRequestMock.Result).IsCrossPlatformCompatible, "Input file should be cross-platform compatible after conversion");
}
}
internal static class SqlProjectsExtensions