Adding project property support to SqlProj service (#1883)

* Nuget update

* Updating nuget

* implementation

* GetProperties test

* Adding SetDatabaseSource

* adding comment

* Nuget update

* PR feedback

* Fixing cross-plat path tests

* Updating to signed nuget

* fixing None test
This commit is contained in:
Benjin Dubishar
2023-02-28 18:27:42 -08:00
committed by GitHub
parent c83f380b8e
commit 68ac1e01fc
8 changed files with 175 additions and 10 deletions

View File

@@ -161,7 +161,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
// Validate moving a SQL object script
string movedScriptRelativePath = @"SubPath\MyRenamedTable.sql";
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), movedScriptRelativePath);
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), FileUtils.NormalizePath(movedScriptRelativePath));
Directory.CreateDirectory(Path.GetDirectoryName(movedScriptAbsolutePath)!);
requestMock = new();
@@ -254,7 +254,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
// Validate moving a None script
string movedScriptRelativePath = @"SubPath\RenamedNoneIncludeFile.json";
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), movedScriptRelativePath);
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), FileUtils.NormalizePath(movedScriptRelativePath));
Directory.CreateDirectory(Path.GetDirectoryName(movedScriptAbsolutePath)!);
requestMock = new();
@@ -343,7 +343,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
// Validate moving a pre-deployment object script
string movedScriptRelativePath = @"SubPath\RenamedPreDeploymentScript.sql";
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), movedScriptRelativePath);
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), FileUtils.NormalizePath(movedScriptRelativePath));
Directory.CreateDirectory(Path.GetDirectoryName(movedScriptAbsolutePath)!);
requestMock = new();
@@ -432,7 +432,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
// Validate moving a post-deployment object script
string movedScriptRelativePath = @"SubPath\RenamedPostDeploymentScript.sql";
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), movedScriptRelativePath);
string movedScriptAbsolutePath = Path.Join(Path.GetDirectoryName(projectUri), FileUtils.NormalizePath(movedScriptRelativePath));
Directory.CreateDirectory(Path.GetDirectoryName(movedScriptAbsolutePath)!);
requestMock = new();
@@ -823,6 +823,53 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
Assert.IsTrue(((GetCrossPlatformCompatibilityResult)getRequestMock.Result).IsCrossPlatformCompatible, "Input file should be cross-platform compatible after conversion");
}
[Test]
public async Task TestProjectProperties()
{
SqlProjectsService service = new();
string projectUri = await service.CreateSqlProject();
MockRequest<GetProjectPropertiesResult> mock = new();
await service.HandleGetProjectPropertiesRequest(new SqlProjectParams()
{
ProjectUri = projectUri
}, mock.Object);
mock.AssertSuccess(nameof(service.HandleGetProjectPropertiesRequest));
Assert.IsTrue(Guid.TryParse(mock.Result.ProjectGuid, out _), $"{mock.Result.ProjectGuid} should be set");
Assert.AreEqual("AnyCPU", mock.Result.Platform);
Assert.AreEqual("Debug", mock.Result.Configuration);
Assert.AreEqual(@"bin\Debug\", mock.Result.OutputPath); // default value is normalized to Windows slashes
Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", mock.Result.DefaultCollation);
Assert.IsNull(mock.Result.DatabaseSource, nameof(mock.Result.DatabaseSource)); // validate DatabaseSource is null when the tag isn't present
// Validate that DatabaseSource can be set when the tag doesn't exist
MockRequest<ResultStatus> setSourceMock = new();
await service.HandleSetDatabaseSourceRequest(new SetDatabaseSourceParams()
{
ProjectUri = projectUri,
DatabaseSource = "TestSource"
}, setSourceMock.Object);
setSourceMock.AssertSuccess(nameof(service.HandleSetDatabaseSourceRequest));
Assert.AreEqual("TestSource", service.Projects[projectUri].Properties.DatabaseSource);
// Validate DatabaseSource is read when it has a value
mock = new();
await service.HandleGetProjectPropertiesRequest(new SqlProjectParams()
{
ProjectUri = projectUri
}, mock.Object);
mock.AssertSuccess(nameof(service.HandleGetProjectPropertiesRequest));
Assert.AreEqual("TestSource", mock.Result.DatabaseSource);
}
#region Helpers
private async Task<(SqlProjectsService Service, string ProjectUri, SqlCmdVariable DatabaseVar, SqlCmdVariable ServerVar)> SetUpDatabaseReferenceTest()

View File

@@ -80,13 +80,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
}
/// <summary>
/// Normalizes Windows, Unix, and mixed paths to the same slash direction, specified by <paramref name="separatorType"/>
/// Normalizes Windows, Unix, and mixed paths to the same slash direction, specified by <paramref name="separatorType"/>.
/// </summary>
/// <param name="path"></param>
/// <param name="separatorType">Win32NT for \, Unix for /</param>
/// <param name="separatorType">Win32NT for \, Unix for /. If not set, path will be normalized to the current platform.</param>
/// <returns></returns>
public static string NormalizePath(string path, PlatformID separatorType)
public static string NormalizePath(string path, PlatformID? separatorType = null)
{
separatorType ??= Environment.OSVersion.Platform;
return separatorType switch
{
PlatformID.Win32NT => path.Contains('/')