mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Removing script as feature from service layer to sqlcore (#2189)
This commit is contained in:
@@ -7,9 +7,8 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.CoreSql.ObjectExplorer;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
|
||||
using Microsoft.SqlTools.SqlCore.ObjectExplorer;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// 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.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.SqlCore.Scripting;
|
||||
using Microsoft.SqlTools.SqlCore.Scripting.Contracts;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
{
|
||||
public class AsyncScriptAsScriptingOperationTests
|
||||
{
|
||||
public static IEnumerable<TestCaseData> ScriptAsTestCases
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
"CREATE TABLE testTable1 (c1 int)",
|
||||
new ScriptingParams()
|
||||
{
|
||||
ScriptDestination = "ToEditor",
|
||||
ScriptingObjects = new List<ScriptingObject>()
|
||||
{
|
||||
new ScriptingObject()
|
||||
{
|
||||
Name = "testTable1",
|
||||
Schema = "dbo",
|
||||
Type = "Table",
|
||||
|
||||
}
|
||||
},
|
||||
Operation = ScriptingOperationType.Select,
|
||||
ScriptOptions = new ScriptOptions()
|
||||
{
|
||||
ScriptCreateDrop = "ScriptSelect"
|
||||
}
|
||||
},
|
||||
new List<string>() { "SELECT TOP (1000) [c1]" });
|
||||
|
||||
yield return new TestCaseData(
|
||||
"CREATE TABLE testTable1 (c1 int)",
|
||||
new ScriptingParams()
|
||||
{
|
||||
ScriptDestination = "ToEditor",
|
||||
ScriptingObjects = new List<ScriptingObject>()
|
||||
{
|
||||
new ScriptingObject()
|
||||
{
|
||||
Name = "testTable1",
|
||||
Schema = "dbo",
|
||||
Type = "Table"
|
||||
}
|
||||
},
|
||||
Operation = ScriptingOperationType.Delete,
|
||||
ScriptOptions = new ScriptOptions()
|
||||
{
|
||||
ScriptCreateDrop = "ScriptDrop"
|
||||
}
|
||||
},
|
||||
new List<string> { "DROP TABLE [dbo].[testTable1]" }
|
||||
);
|
||||
|
||||
yield return new TestCaseData(
|
||||
@"CREATE TABLE testTable1 (c1 int)
|
||||
GO
|
||||
CREATE CLUSTERED INDEX [ClusteredIndex-1] ON [dbo].[testTable1]
|
||||
(
|
||||
[c1] ASC
|
||||
)
|
||||
GO
|
||||
",
|
||||
new ScriptingParams()
|
||||
{
|
||||
ScriptDestination = "ToEditor",
|
||||
ScriptingObjects = new List<ScriptingObject>()
|
||||
{
|
||||
new ScriptingObject()
|
||||
{
|
||||
Name = "testTable1",
|
||||
Schema = "dbo",
|
||||
Type = "Table"
|
||||
}
|
||||
},
|
||||
Operation = ScriptingOperationType.Create,
|
||||
ScriptOptions = new ScriptOptions()
|
||||
{
|
||||
ScriptCreateDrop = "ScriptCreate"
|
||||
}
|
||||
},
|
||||
new List<string> { "CREATE TABLE [dbo].[testTable1]", "CREATE CLUSTERED INDEX [ClusteredIndex-1] ON [dbo].[testTable1]" }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCaseSource("ScriptAsTestCases")]
|
||||
public async Task TestCommonScenarios(
|
||||
string query, ScriptingParams scriptingParams, List<string> expectedScriptContents)
|
||||
{
|
||||
var testDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, query, "ScriptingTests");
|
||||
scriptingParams.ConnectionString = testDb.ConnectionString;
|
||||
|
||||
var actualScript = await AsyncScriptAsScriptingOperation.GetScriptAsScript(scriptingParams, null);
|
||||
|
||||
foreach(var expectedStr in expectedScriptContents)
|
||||
{
|
||||
Assert.That(actualScript, Does.Contain(expectedStr));
|
||||
}
|
||||
|
||||
await testDb.CleanupAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
|
||||
using Microsoft.SqlTools.SqlCore.Scripting.Contracts;
|
||||
using Microsoft.SqlTools.SqlCore.Scripting;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user