mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:35:43 -05:00
* 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
87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// Tests for the scripting service component
|
|
/// </summary>
|
|
public class ScriptingServiceTests
|
|
{
|
|
private const string SchemaName = "dbo";
|
|
private const string TableName = "spt_monitor";
|
|
private const string ViewName = "test";
|
|
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()
|
|
{
|
|
var textDocument = new TextDocumentPosition
|
|
{
|
|
TextDocument = new TextDocumentIdentifier { Uri = Test.Common.Constants.OwnerUri },
|
|
Position = new Position
|
|
{
|
|
Line = 0,
|
|
Character = 0
|
|
}
|
|
};
|
|
|
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
|
result.TextDocumentPosition = textDocument;
|
|
return result;
|
|
}
|
|
|
|
private async Task<Mock<RequestContext<ScriptingResult>>> SendAndValidateScriptRequest(bool isSelectScript)
|
|
{
|
|
var result = GetLiveAutoCompleteTestObjects();
|
|
var requestContext = new Mock<RequestContext<ScriptingResult>>();
|
|
requestContext.Setup(x => x.SendResult(It.IsAny<ScriptingResult>())).Returns(Task.FromResult(new object()));
|
|
|
|
var scriptingParams = new ScriptingParams
|
|
{
|
|
OwnerUri = ConnectionService.BuildConnectionString(result.ConnectionInfo.ConnectionDetails)
|
|
};
|
|
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 object request
|
|
/// </summary>
|
|
[Fact]
|
|
public async void ScriptingScript()
|
|
{
|
|
foreach (string obj in objects)
|
|
{
|
|
Assert.NotNull(await SendAndValidateScriptRequest(false));
|
|
Assert.NotNull(await SendAndValidateScriptRequest(true));
|
|
}
|
|
}
|
|
}
|
|
}
|