mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Adding SetDSP support to SqlProjects service (#1895)
* Adding SetDSP support * correcting comment
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
#nullable disable
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.SqlProjects.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for setting the DatabaseSchemaProvider property of a SQL project
|
||||
/// </summary>
|
||||
public class SetDatabaseSchemaProviderParams : SqlProjectParams
|
||||
{
|
||||
/// <summary>
|
||||
/// New DatabaseSchemaProvider value, in the form "Microsoft.Data.Tools.Schema.Sql.SqlXYZDatabaseSchemaProvider"
|
||||
/// </summary>
|
||||
public string DatabaseSchemaProvider { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the DatabaseSchemaProvider property of a SQL project
|
||||
/// </summary>
|
||||
public class SetDatabaseSchemaProviderRequest
|
||||
{
|
||||
public static readonly RequestType<SetDatabaseSchemaProviderParams, ResultStatus> Type = RequestType<SetDatabaseSchemaProviderParams, ResultStatus>.Create("sqlProjects/setDatabaseSchemaProvider");
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
|
||||
serviceHost.SetRequestHandler(UpdateProjectForCrossPlatformRequest.Type, HandleUpdateProjectForCrossPlatformRequest, isParallelProcessingSupported: false);
|
||||
serviceHost.SetRequestHandler(GetProjectPropertiesRequest.Type, HandleGetProjectPropertiesRequest, isParallelProcessingSupported: true);
|
||||
serviceHost.SetRequestHandler(SetDatabaseSourceRequest.Type, HandleSetDatabaseSourceRequest, isParallelProcessingSupported: false);
|
||||
serviceHost.SetRequestHandler(SetDatabaseSchemaProviderRequest.Type, HandleSetDatabaseSchemaProviderRequest, isParallelProcessingSupported: false);
|
||||
|
||||
// SQL object script functions
|
||||
serviceHost.SetRequestHandler(GetSqlObjectScriptsRequest.Type, HandleGetSqlObjectScriptsRequest, isParallelProcessingSupported: true);
|
||||
@@ -162,6 +163,11 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
|
||||
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).Properties.DatabaseSource = requestParams.DatabaseSource, requestContext);
|
||||
}
|
||||
|
||||
internal async Task HandleSetDatabaseSchemaProviderRequest(SetDatabaseSchemaProviderParams requestParams, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseSchemaProvider = requestParams.DatabaseSchemaProvider, requestContext);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Script/folder functions
|
||||
|
||||
@@ -846,47 +846,57 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SqlProjects
|
||||
SqlProjectsService service = new();
|
||||
string projectUri = await service.CreateSqlProject();
|
||||
|
||||
MockRequest<GetProjectPropertiesResult> mock = new();
|
||||
|
||||
MockRequest<GetProjectPropertiesResult> getMock = new();
|
||||
await service.HandleGetProjectPropertiesRequest(new SqlProjectParams()
|
||||
{
|
||||
ProjectUri = projectUri
|
||||
}, mock.Object);
|
||||
}, getMock.Object);
|
||||
|
||||
mock.AssertSuccess(nameof(service.HandleGetProjectPropertiesRequest));
|
||||
getMock.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
|
||||
Assert.AreEqual(ProjectType.SdkStyle, mock.Result.ProjectStyle);
|
||||
Assert.AreEqual("Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider", mock.Result.DatabaseSchemaProvider);
|
||||
Assert.IsTrue(Guid.TryParse(getMock.Result.ProjectGuid, out _), $"{getMock.Result.ProjectGuid} should be set");
|
||||
Assert.AreEqual("AnyCPU", getMock.Result.Platform);
|
||||
Assert.AreEqual("Debug", getMock.Result.Configuration);
|
||||
Assert.AreEqual(@"bin\Debug\", getMock.Result.OutputPath); // default value is normalized to Windows slashes
|
||||
Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", getMock.Result.DefaultCollation);
|
||||
Assert.IsNull(getMock.Result.DatabaseSource, nameof(getMock.Result.DatabaseSource)); // validate DatabaseSource is null when the tag isn't present
|
||||
Assert.AreEqual(ProjectType.SdkStyle, getMock.Result.ProjectStyle);
|
||||
Assert.AreEqual("Microsoft.Data.Tools.Schema.Sql.Sql160DatabaseSchemaProvider", getMock.Result.DatabaseSchemaProvider);
|
||||
|
||||
// Validate that DatabaseSource can be set when the tag doesn't exist
|
||||
|
||||
MockRequest<ResultStatus> setSourceMock = new();
|
||||
MockRequest<ResultStatus> setMock = new();
|
||||
await service.HandleSetDatabaseSourceRequest(new SetDatabaseSourceParams()
|
||||
{
|
||||
ProjectUri = projectUri,
|
||||
DatabaseSource = "TestSource"
|
||||
}, setSourceMock.Object);
|
||||
}, setMock.Object);
|
||||
|
||||
setSourceMock.AssertSuccess(nameof(service.HandleSetDatabaseSourceRequest));
|
||||
setMock.AssertSuccess(nameof(service.HandleSetDatabaseSourceRequest));
|
||||
Assert.AreEqual("TestSource", service.Projects[projectUri].Properties.DatabaseSource);
|
||||
|
||||
// Validate DatabaseSource is read when it has a value
|
||||
|
||||
mock = new();
|
||||
|
||||
getMock = new();
|
||||
await service.HandleGetProjectPropertiesRequest(new SqlProjectParams()
|
||||
{
|
||||
ProjectUri = projectUri
|
||||
}, mock.Object);
|
||||
}, getMock.Object);
|
||||
|
||||
mock.AssertSuccess(nameof(service.HandleGetProjectPropertiesRequest));
|
||||
Assert.AreEqual("TestSource", mock.Result.DatabaseSource);
|
||||
getMock.AssertSuccess(nameof(service.HandleGetProjectPropertiesRequest));
|
||||
Assert.AreEqual("TestSource", getMock.Result.DatabaseSource);
|
||||
|
||||
// Validate that DatabaseSchemaProvider can be set
|
||||
|
||||
setMock = new();
|
||||
await service.HandleSetDatabaseSchemaProviderRequest(new SetDatabaseSchemaProviderParams()
|
||||
{
|
||||
ProjectUri = projectUri,
|
||||
DatabaseSchemaProvider = "Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider"
|
||||
}, setMock.Object);
|
||||
|
||||
setMock.AssertSuccess(nameof(service.HandleSetDatabaseSchemaProviderRequest));
|
||||
Assert.AreEqual("Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider", service.Projects[projectUri].DatabaseSchemaProvider);
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
Reference in New Issue
Block a user