mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Task/script refactor (#446)
* scripting working with race conditions * new service works with no race conditions * use new scripting service and commented out tests * refactored peek definition to use mssql-scripter * fixed peek definition tests * removed auto gen comment * fixed peek definition highlighting bug * made scripting async and fixed event handlers * fixed tests (without cancel and plan notifs) * removed dead code * added nuget package * CR comments + select script service implementation * minor fixes and added test * CR comments and script select * added unit tests * code review comments and cleanup
This commit is contained in:
@@ -3,15 +3,17 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Metadata.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
||||
using Moq;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
||||
using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
{
|
||||
@@ -26,6 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
private const string DatabaseName = "test-db";
|
||||
private const string StoredProcName = "test-sp";
|
||||
private string[] objects = new string[5] {"Table", "View", "Schema", "Database", "SProc"};
|
||||
private string[] selectObjects = new string[2] { "Table", "View" };
|
||||
|
||||
private LiveConnectionHelper.TestConnectionResult GetLiveAutoCompleteTestObjects()
|
||||
{
|
||||
@@ -44,118 +47,39 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ObjectMetadata GenerateMetadata(string objectType)
|
||||
{
|
||||
var metadata = new ObjectMetadata()
|
||||
{
|
||||
Schema = SchemaName,
|
||||
Name = objectType
|
||||
};
|
||||
switch(objectType)
|
||||
{
|
||||
case("Table"):
|
||||
metadata.MetadataType = MetadataType.Table;
|
||||
metadata.Name = TableName;
|
||||
break;
|
||||
case("View"):
|
||||
metadata.MetadataType = MetadataType.View;
|
||||
metadata.Name = ViewName;
|
||||
break;
|
||||
case("Database"):
|
||||
metadata.MetadataType = MetadataType.Database;
|
||||
metadata.Name = DatabaseName;
|
||||
break;
|
||||
case("Schema"):
|
||||
metadata.MetadataType = MetadataType.Schema;
|
||||
metadata.MetadataTypeName = SchemaName;
|
||||
break;
|
||||
case("SProc"):
|
||||
metadata.MetadataType = MetadataType.SProc;
|
||||
metadata.MetadataTypeName = StoredProcName;
|
||||
break;
|
||||
default:
|
||||
metadata.MetadataType = MetadataType.Table;
|
||||
metadata.Name = TableName;
|
||||
break;
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
private async Task<Mock<RequestContext<ScriptingScriptAsResult>>> SendAndValidateScriptRequest(ScriptOperation operation, string objectType)
|
||||
private async Task<Mock<RequestContext<ScriptingResult>>> SendAndValidateScriptRequest(bool isSelectScript)
|
||||
{
|
||||
var result = GetLiveAutoCompleteTestObjects();
|
||||
var requestContext = new Mock<RequestContext<ScriptingScriptAsResult>>();
|
||||
requestContext.Setup(x => x.SendResult(It.IsAny<ScriptingScriptAsResult>())).Returns(Task.FromResult(new object()));
|
||||
var requestContext = new Mock<RequestContext<ScriptingResult>>();
|
||||
requestContext.Setup(x => x.SendResult(It.IsAny<ScriptingResult>())).Returns(Task.FromResult(new object()));
|
||||
|
||||
var scriptingParams = new ScriptingScriptAsParams
|
||||
var scriptingParams = new ScriptingParams
|
||||
{
|
||||
OwnerUri = result.ConnectionInfo.OwnerUri,
|
||||
Operation = operation,
|
||||
Metadata = GenerateMetadata(objectType)
|
||||
OwnerUri = ConnectionService.BuildConnectionString(result.ConnectionInfo.ConnectionDetails)
|
||||
};
|
||||
|
||||
await ScriptingService.HandleScriptingScriptAsRequest(scriptingParams, requestContext.Object);
|
||||
if (isSelectScript)
|
||||
{
|
||||
scriptingParams.ScriptOptions = new ScriptOptions { ScriptCreateDrop = "ScriptSelect" };
|
||||
List<ScriptingObject> scriptingObjects = new List<ScriptingObject>();
|
||||
scriptingObjects.Add(new ScriptingObject { Type = "View", Name = "sysobjects", Schema = "sys" });
|
||||
scriptingParams.ScriptingObjects = scriptingObjects;
|
||||
}
|
||||
ScriptingService service = new ScriptingService();
|
||||
await service.HandleScriptExecuteRequest(scriptingParams, requestContext.Object);
|
||||
|
||||
return requestContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the script as select request
|
||||
/// Verify the script object request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ScriptingScriptAsSelect()
|
||||
public async void ScriptingScript()
|
||||
{
|
||||
foreach (string obj in objects)
|
||||
{
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(ScriptOperation.Select, obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the script as create request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ScriptingScriptAsCreate()
|
||||
{
|
||||
foreach (string obj in objects)
|
||||
{
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(ScriptOperation.Create, obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the script as insert request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ScriptingScriptAsInsert()
|
||||
{
|
||||
foreach (string obj in objects)
|
||||
{
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(ScriptOperation.Insert, obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the script as update request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ScriptingScriptAsUpdate()
|
||||
{
|
||||
foreach (string obj in objects)
|
||||
{
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(ScriptOperation.Select, obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify the script as delete request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void ScriptingScriptAsDelete()
|
||||
{
|
||||
foreach (string obj in objects)
|
||||
{
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(ScriptOperation.Select, obj));
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(false));
|
||||
Assert.NotNull(await SendAndValidateScriptRequest(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user