mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-14 03:58:35 -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:
@@ -75,7 +75,7 @@ CREATE SYNONYM [dbo].[pd_testTable] FOR master.dbo.spt_monitor
|
||||
GO";
|
||||
|
||||
private const string TableValuedFunctionTypeName = "TableValuedFunction";
|
||||
private const string ScalarValuedFunctionTypeName = "ScalarValuedFunction";
|
||||
private const string ScalarValuedFunctionTypeName = "UserDefinedFunction";
|
||||
private const string UserDefinedDataTypeTypeName = "UserDefinedDataType";
|
||||
private const string UserDefinedTableTypeTypeName = "UserDefinedTableType";
|
||||
private const string SynonymTypeName = "Synonym";
|
||||
@@ -100,7 +100,7 @@ GO";
|
||||
string objectType = "TABLE";
|
||||
|
||||
// Get locations for valid table object
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetTableScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.NotNull(locations);
|
||||
Cleanup(locations);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ GO";
|
||||
string objectType = "TABLE";
|
||||
|
||||
// Get locations for invalid table object
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetTableScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.Null(locations);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ GO";
|
||||
string objectType = "TABLE";
|
||||
|
||||
// Get locations for valid table object with schema name
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetTableScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.NotNull(locations);
|
||||
Cleanup(locations);
|
||||
}
|
||||
@@ -262,7 +262,7 @@ GO";
|
||||
string schemaName = "sys";
|
||||
string objectType = "VIEW";
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetViewScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.NotNull(locations);
|
||||
Cleanup(locations);
|
||||
}
|
||||
@@ -282,7 +282,7 @@ GO";
|
||||
string schemaName = null;
|
||||
string objectType = "VIEW";
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetViewScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.Null(locations);
|
||||
}
|
||||
|
||||
@@ -300,9 +300,9 @@ GO";
|
||||
string objectName = "sp_columns";
|
||||
|
||||
string schemaName = "sys";
|
||||
string objectType = "PROCEDURE";
|
||||
string objectType = "StoredProcedure";
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetStoredProcedureScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.NotNull(locations);
|
||||
Cleanup(locations);
|
||||
}
|
||||
@@ -322,7 +322,7 @@ GO";
|
||||
string schemaName = "dbo";
|
||||
string objectType = "PROCEDURE";
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetStoredProcedureScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.Null(locations);
|
||||
}
|
||||
|
||||
@@ -339,9 +339,9 @@ GO";
|
||||
Scripter scripter = new Scripter(serverConnection, connInfo);
|
||||
string objectName = "sp_MSrepl_startup";
|
||||
string schemaName = null;
|
||||
string objectType = "PROCEDURE";
|
||||
string objectType = "StoredProcedure";
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetStoredProcedureScripts, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
Assert.NotNull(locations);
|
||||
Cleanup(locations);
|
||||
}
|
||||
@@ -377,40 +377,7 @@ GO";
|
||||
|
||||
Scripter scripter = new Scripter(serverConnection, connInfo);
|
||||
|
||||
Scripter.ScriptGetter sqlScriptGetter = null;
|
||||
switch (objectType)
|
||||
{
|
||||
case SynonymTypeName:
|
||||
sqlScriptGetter = scripter.GetSynonymScripts;
|
||||
break;
|
||||
case ScalarValuedFunctionTypeName:
|
||||
sqlScriptGetter = scripter.GetScalarValuedFunctionScripts;
|
||||
objectType = "Function";
|
||||
break;
|
||||
case TableValuedFunctionTypeName:
|
||||
sqlScriptGetter = scripter.GetTableValuedFunctionScripts;
|
||||
objectType = "Function";
|
||||
break;
|
||||
case TableTypeName:
|
||||
sqlScriptGetter = scripter.GetTableScripts;
|
||||
break;
|
||||
case ViewTypeName:
|
||||
sqlScriptGetter = scripter.GetViewScripts;
|
||||
break;
|
||||
case StoredProcedureTypeName:
|
||||
sqlScriptGetter = scripter.GetStoredProcedureScripts;
|
||||
break;
|
||||
case UserDefinedDataTypeTypeName:
|
||||
sqlScriptGetter = scripter.GetUserDefinedDataTypeScripts;
|
||||
objectType = "Type";
|
||||
break;
|
||||
case UserDefinedTableTypeTypeName:
|
||||
sqlScriptGetter = scripter.GetUserDefinedTableTypeScripts;
|
||||
objectType = "Type";
|
||||
break;
|
||||
}
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(sqlScriptGetter, objectName, schemaName, objectType);
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(objectName, schemaName, objectType);
|
||||
if (shouldReturnValidResult)
|
||||
{
|
||||
Assert.NotNull(locations);
|
||||
|
||||
@@ -27,11 +27,12 @@
|
||||
<ProjectReference Include="..\Microsoft.SqlTools.ServiceLayer.UnitTests\Microsoft.SqlTools.ServiceLayer.UnitTests.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.5" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.5" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Scripts/CreateTestDatabaseObjects.sql" />
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Scripting.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
@@ -49,11 +48,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptDatabaseSchema()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
@@ -62,14 +60,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
};
|
||||
|
||||
ScriptingResult result = await testService.Script(requestParams);
|
||||
ScriptingPlanNotificationParams planEvent = await testService.Driver.WaitForEvent(ScriptingPlanNotificationEvent.Type, TimeSpan.FromSeconds(30));
|
||||
ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
||||
Assert.True(parameters.Success);
|
||||
Assert.Equal<int>(ScriptingFixture.ObjectCountWithDatabase, planEvent.Count);
|
||||
Assert.True(File.Exists(tempFile.FilePath));
|
||||
Assert.True(new FileInfo(tempFile.FilePath).Length > 0);
|
||||
AssertSchemaInFile(tempFile.FilePath, assert: true);
|
||||
AssertTableDataInFile(tempFile.FilePath, assert: false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +69,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptDatabaseSchemaAndData()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
@@ -90,14 +81,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
};
|
||||
|
||||
ScriptingResult result = await testService.Script(requestParams);
|
||||
ScriptingPlanNotificationParams planEvent = await testService.Driver.WaitForEvent(ScriptingPlanNotificationEvent.Type, TimeSpan.FromSeconds(30));
|
||||
ScriptingCompleteParams completeParameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
||||
Assert.True(completeParameters.Success);
|
||||
Assert.Equal<int>(ScriptingFixture.ObjectCountWithDatabase, planEvent.Count);
|
||||
Assert.True(File.Exists(tempFile.FilePath));
|
||||
Assert.True(new FileInfo(tempFile.FilePath).Length > 0);
|
||||
AssertSchemaInFile(tempFile.FilePath, assert: true);
|
||||
AssertTableDataInFile(tempFile.FilePath, assert: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,15 +90,15 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptTable()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
TypeOfDataToScript = "SchemaOnly",
|
||||
|
||||
},
|
||||
ScriptingObjects = new List<ScriptingObject>
|
||||
{
|
||||
@@ -131,8 +116,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
||||
Assert.True(parameters.Success);
|
||||
Assert.Equal<int>(1, planEvent.Count);
|
||||
Assert.True(File.Exists(tempFile.FilePath));
|
||||
Assert.True(new FileInfo(tempFile.FilePath).Length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,11 +123,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptTableUsingIncludeFilter()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
@@ -166,8 +148,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
||||
Assert.True(parameters.Success);
|
||||
Assert.Equal<int>(1, planEvent.Count);
|
||||
Assert.True(File.Exists(tempFile.FilePath));
|
||||
Assert.True(new FileInfo(tempFile.FilePath).Length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,11 +155,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptTableAndData()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
@@ -201,8 +180,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));
|
||||
Assert.True(parameters.Success);
|
||||
Assert.Equal<int>(1, planEvent.Count);
|
||||
Assert.True(File.Exists(tempFile.FilePath));
|
||||
Assert.True(new FileInfo(tempFile.FilePath).Length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,15 +187,15 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptTableDoesNotExist()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
TypeOfDataToScript = "SchemaOnly",
|
||||
ContinueScriptingOnError = false
|
||||
},
|
||||
ScriptingObjects = new List<ScriptingObject>
|
||||
{
|
||||
@@ -243,11 +220,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptSchemaCancel()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = this.Northwind.ConnectionString,
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
@@ -267,11 +243,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
public async Task ScriptSchemaInvalidConnectionString()
|
||||
{
|
||||
using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
|
||||
using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ScriptingParams requestParams = new ScriptingParams
|
||||
{
|
||||
FilePath = tempFile.FilePath,
|
||||
ScriptDestination = "ToEditor",
|
||||
ConnectionString = "I'm an invalid connection string",
|
||||
ScriptOptions = new ScriptOptions
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.5" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/Microsoft.SqlTools.Hosting/Microsoft.SqlTools.Hosting.csproj" />
|
||||
|
||||
@@ -312,9 +312,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "tableName";
|
||||
string fullObjectName = "master.dbo.tableName";
|
||||
DefinitionResult result = peekDefinition.GetDefinitionUsingDeclarationType(DeclarationType.Table, fullObjectName, objectName, null);
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result.IsErrorResult);
|
||||
Assert.Throws<NullReferenceException>(() => peekDefinition.GetDefinitionUsingDeclarationType(DeclarationType.Table, fullObjectName, objectName, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.5" />
|
||||
<PackageReference Include="Microsoft.SqlServer.Smo" Version="140.2.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
|
||||
@@ -408,5 +408,50 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Scripting
|
||||
|
||||
Assert.Equal<int>(2, results.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ScriptingObjectEquality()
|
||||
{
|
||||
ScriptingObject scriptingObject1 = new ScriptingObject { Type = "Table", Schema = "test", Name = "test_table" };
|
||||
ScriptingObject scriptingObject2 = new ScriptingObject { Type = "Table", Schema = "test", Name = "test_table" };
|
||||
ScriptingObject scriptingObject3 = null;
|
||||
Assert.Equal(scriptingObject1, scriptingObject2);
|
||||
Assert.False(scriptingObject1.Equals(scriptingObject3));
|
||||
}
|
||||
}
|
||||
|
||||
public class ScriptingUtilsTests
|
||||
{
|
||||
private static string[] TestObjects = new string[]
|
||||
{
|
||||
"Table",
|
||||
"Table]",
|
||||
"]Table",
|
||||
"Tab]le",
|
||||
"",
|
||||
"]",
|
||||
"view"
|
||||
};
|
||||
|
||||
private static string[] ExpectedObjects = new string[]
|
||||
{
|
||||
"Table",
|
||||
"Table]]",
|
||||
"]]Table",
|
||||
"Tab]]le",
|
||||
"",
|
||||
"]]",
|
||||
"view"
|
||||
};
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestQuoteObjectName()
|
||||
{
|
||||
for (int i = 0; i < TestObjects.Length; i++)
|
||||
{
|
||||
Assert.Equal(Scripter.ScriptingUtils.QuoteObjectName(TestObjects[i]), ExpectedObjects[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user