mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Task/script refactor (#478)
* 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 * fixed failing scripting tests * fixed failing scripting tests * fixed select script test * code review comments
This commit is contained in:
@@ -117,10 +117,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
|||||||
// if a connection string wasn't provided as a parameter then
|
// if a connection string wasn't provided as a parameter then
|
||||||
// use the owner uri property to lookup its associated ConnectionInfo
|
// use the owner uri property to lookup its associated ConnectionInfo
|
||||||
// and then build a connection string out of that
|
// and then build a connection string out of that
|
||||||
ConnectionInfo connInfo;
|
ConnectionInfo connInfo = null;
|
||||||
ScriptingService.ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
if (parameters.ConnectionString == null || parameters.ScriptOptions.ScriptCreateDrop == "ScriptSelect")
|
||||||
if (parameters.ConnectionString == null)
|
|
||||||
{
|
{
|
||||||
|
ScriptingService.ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||||
if (connInfo != null)
|
if (connInfo != null)
|
||||||
{
|
{
|
||||||
parameters.ConnectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
|
parameters.ConnectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
ScriptingResult result = await testService.Script(requestParams);
|
ScriptingResult result = await testService.Script(requestParams);
|
||||||
ScriptingPlanNotificationParams planEvent = await testService.Driver.WaitForEvent(ScriptingPlanNotificationEvent.Type, TimeSpan.FromSeconds(30));
|
ScriptingPlanNotificationParams planEvent = await testService.Driver.WaitForEvent(ScriptingPlanNotificationEvent.Type, TimeSpan.FromSeconds(1));
|
||||||
ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
||||||
Assert.True(parameters.Success);
|
Assert.True(parameters.Success);
|
||||||
Assert.Equal<int>(1, planEvent.Count);
|
Assert.Equal<int>(1, planEvent.Count);
|
||||||
@@ -284,6 +284,36 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ScriptSelectTable()
|
||||||
|
{
|
||||||
|
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||||
|
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||||
|
{
|
||||||
|
await testService.Connect(tempFile.FilePath, testService.TestConnectionService.GetConnectionParameters(serverType: TestServerType.OnPrem));
|
||||||
|
ScriptingParams requestParams = new ScriptingParams
|
||||||
|
{
|
||||||
|
ScriptDestination = "ToEditor",
|
||||||
|
OwnerUri = tempFile.FilePath,
|
||||||
|
ScriptOptions = new ScriptOptions
|
||||||
|
{
|
||||||
|
ScriptCreateDrop = "ScriptSelect"
|
||||||
|
},
|
||||||
|
ScriptingObjects = new List<ScriptingObject>
|
||||||
|
{
|
||||||
|
new ScriptingObject
|
||||||
|
{
|
||||||
|
Type = "Table",
|
||||||
|
Schema = "dbo",
|
||||||
|
Name = "Customers",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ScriptingResult result = await testService.Script(requestParams);
|
||||||
|
Assert.True(result.Script.Contains("SELECT"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void AssertSchemaInFile(string filePath, bool assert = true)
|
private static void AssertSchemaInFile(string filePath, bool assert = true)
|
||||||
{
|
{
|
||||||
AssertFileContainsString(
|
AssertFileContainsString(
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Scripting
|
|||||||
ScriptingObject scriptingObject1 = new ScriptingObject { Type = "Table", Schema = "test", Name = "test_table" };
|
ScriptingObject scriptingObject1 = new ScriptingObject { Type = "Table", Schema = "test", Name = "test_table" };
|
||||||
ScriptingObject scriptingObject2 = new ScriptingObject { Type = "Table", Schema = "test", Name = "test_table" };
|
ScriptingObject scriptingObject2 = new ScriptingObject { Type = "Table", Schema = "test", Name = "test_table" };
|
||||||
ScriptingObject scriptingObject3 = null;
|
ScriptingObject scriptingObject3 = null;
|
||||||
Assert.Equal(scriptingObject1, scriptingObject2);
|
Assert.True(scriptingObject1.Equals(scriptingObject2));
|
||||||
Assert.False(scriptingObject1.Equals(scriptingObject3));
|
Assert.False(scriptingObject1.Equals(scriptingObject3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user