mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 01:25:42 -05:00
Add Scripter class and use it in the ScriptingService (#286)
* Initial scripting commit * Fix the script CREATE integration test * Use language service binding queue for scripting * Update scripting service to have methods for each operation * Add scripter class * Fix build break. * Fix a few bugs * Use scripter class instead of PeekDefinition class. * Fix scripting test break * Fix header incorrectly saying file is generated. * Add localization tests to address a large block of code not covered by automation. * Moving system usings to top of using list
This commit is contained in:
@@ -18,13 +18,14 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Scripting;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Moq;
|
||||
using GlobalCommon = Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Xunit;
|
||||
using GlobalCommon = Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Location = Microsoft.SqlTools.ServiceLayer.Workspace.Contracts.Location;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
@@ -138,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
public void GetLocationFromFileForValidFilePathTest()
|
||||
{
|
||||
string filePath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\test\\script.sql" : "/test/script.sql";
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
Location[] locations = peekDefinition.GetLocationFromFile(filePath, 0);
|
||||
|
||||
string expectedFilePath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "file:///C:/test/script.sql" : "file:/test/script.sql";
|
||||
@@ -151,7 +152,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetSchemaFromDatabaseQualifiedNameWithValidNameTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string validDatabaseQualifiedName = "master.test.test_table";
|
||||
string objectName = "test_table";
|
||||
string expectedSchemaName = "test";
|
||||
@@ -167,7 +168,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetSchemaFromDatabaseQualifiedNameWithNoSchemaTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string validDatabaseQualifiedName = "test_table";
|
||||
string objectName = "test_table";
|
||||
string expectedSchemaName = "dbo";
|
||||
@@ -182,7 +183,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetSchemaFromDatabaseQualifiedNameWithInvalidNameTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string validDatabaseQualifiedName = "x.y.z";
|
||||
string objectName = "test_table";
|
||||
string expectedSchemaName = "dbo";
|
||||
@@ -197,7 +198,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void DeletePeekDefinitionScriptsTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
var languageService = LanguageService.Instance;
|
||||
Assert.True(Directory.Exists(FileUtilities.PeekDefinitionTempFolder));
|
||||
languageService.DeletePeekDefinitionScripts();
|
||||
@@ -211,7 +212,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
public void DeletePeekDefinitionScriptsWhenFolderDoesNotExistTest()
|
||||
{
|
||||
var languageService = LanguageService.Instance;
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
FileUtilities.SafeDirectoryDelete(FileUtilities.PeekDefinitionTempFolder, true);
|
||||
Assert.False(Directory.Exists(FileUtilities.PeekDefinitionTempFolder));
|
||||
// Expected not to throw any exception
|
||||
@@ -226,7 +227,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetFullObjectNameFromQuickInfoWithValidStringsTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "testTable";
|
||||
string quickInfoText = "table master.dbo.testTable";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
@@ -242,7 +243,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetFullObjectNameFromQuickInfoWithValidStringsandIgnoreCaseTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "testtable";
|
||||
string quickInfoText = "table master.dbo.testTable";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.OrdinalIgnoreCase);
|
||||
@@ -258,7 +259,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetFullObjectNameFromQuickInfoWithNullStringsTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string expected = null;
|
||||
|
||||
string objectName = null;
|
||||
@@ -285,7 +286,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetFullObjectNameFromQuickInfoWithIncorrectObjectNameTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "test";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetFullObjectNameFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
@@ -301,7 +302,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetTokenTypeFromQuickInfoWithValidStringsTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "tableName";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
@@ -318,7 +319,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetTokenTypeFromQuickInfoWithValidStringsandIgnoreCaseTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "tablename";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.OrdinalIgnoreCase);
|
||||
@@ -334,7 +335,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetTokenTypeFromQuickInfoWithNullStringsTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string expected = null;
|
||||
|
||||
string objectName = null;
|
||||
@@ -361,7 +362,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetTokenTypeFromQuickInfoWithIncorrectObjectNameTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "test";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
string result = peekDefinition.GetTokenTypeFromQuickInfo(quickInfoText, objectName, StringComparison.Ordinal);
|
||||
@@ -376,7 +377,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetDefinitionUsingQuickInfoWithoutConnectionTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "tableName";
|
||||
string quickInfoText = "table master.dbo.tableName";
|
||||
DefinitionResult result = peekDefinition.GetDefinitionUsingQuickInfoText(quickInfoText, objectName, null);
|
||||
@@ -391,7 +392,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||
[Fact]
|
||||
public void GetDefinitionUsingDeclarationItemWithoutConnectionTest()
|
||||
{
|
||||
PeekDefinition peekDefinition = new PeekDefinition(null, null);
|
||||
Scripter peekDefinition = new Scripter(null, null);
|
||||
string objectName = "tableName";
|
||||
string fullObjectName = "master.dbo.tableName";
|
||||
DefinitionResult result = peekDefinition.GetDefinitionUsingDeclarationType(DeclarationType.Table, fullObjectName, objectName, null);
|
||||
|
||||
@@ -3,8 +3,11 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Globalization;
|
||||
using Xunit;
|
||||
|
||||
using ServiceLayerSr = Microsoft.SqlTools.ServiceLayer.Localization.sr;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||
{
|
||||
public class SrTests
|
||||
@@ -15,10 +18,114 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||
[Fact]
|
||||
public void SrPropertiesTest()
|
||||
{
|
||||
Assert.NotNull(ServiceLayer.SR.QueryServiceSubsetBatchNotCompleted);
|
||||
Assert.NotNull(ServiceLayer.SR.QueryServiceFileWrapperWriteOnly);
|
||||
Assert.NotNull(ServiceLayer.SR.QueryServiceFileWrapperNotInitialized);
|
||||
Assert.NotNull(ServiceLayer.SR.QueryServiceColumnNull);
|
||||
Assert.NotNull(SR.QueryServiceSubsetBatchNotCompleted);
|
||||
Assert.NotNull(SR.QueryServiceFileWrapperWriteOnly);
|
||||
Assert.NotNull(SR.QueryServiceFileWrapperNotInitialized);
|
||||
Assert.NotNull(SR.QueryServiceColumnNull);
|
||||
|
||||
var sr = new ServiceLayerSr();
|
||||
Assert.NotNull(ServiceLayerSr.ResourceManager);
|
||||
ServiceLayerSr.Culture = CultureInfo.CurrentCulture;
|
||||
Assert.NotNull(ServiceLayerSr.Culture);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParser_CircularReference);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParser_CommentNotTerminated);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParser_IncorrectSyntax);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParser_StringNotTerminated);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParser_VariableNotDefined);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParserWrapperExecutionEngineBatchCancelling);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParserWrapperExecutionEngineBatchMessage);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParserWrapperExecutionEngineBatchResultSetFinished);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParserWrapperExecutionEngineBatchResultSetProcessing);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParserWrapperExecutionEngineError);
|
||||
Assert.NotNull(ServiceLayerSr.BatchParserWrapperExecutionError);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionParamsValidateNullConnection);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionParamsValidateNullOwnerUri);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionParamsValidateNullServerName);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionParamsValidateNullSqlAuth);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceConnectErrorNullParams);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceConnectionCanceled);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceConnStringInvalidAuthType);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceConnStringInvalidIntent);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceDbErrorDefaultNotConnected);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceListDbErrorNotConnected);
|
||||
Assert.NotNull(ServiceLayerSr.ConnectionServiceListDbErrorNullOwnerUri);
|
||||
Assert.Null(ServiceLayerSr.CredentialServiceWin32CredentialDisposed);
|
||||
Assert.Null(ServiceLayerSr.CredentialsServiceInvalidCriticalHandle);
|
||||
Assert.Null(ServiceLayerSr.CredentialsServicePasswordLengthExceeded);
|
||||
Assert.Null(ServiceLayerSr.CredentialsServiceTargetForDelete);
|
||||
Assert.Null(ServiceLayerSr.CredentialsServiceTargetForLookup);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchError_Exception);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchExecutionError_Halting);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchExecutionError_Ignoring);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchExecutionInfo_RowsAffected);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchSqlMessageNoLineInfo);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchSqlMessageNoProcedureInfo);
|
||||
Assert.NotNull(ServiceLayerSr.EE_BatchSqlMessageWithProcedureInfo);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ExecutionError_CommandNotSupported);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ExecutionError_VariableNotFound);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ExecutionInfo_FinalizingLoop);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ExecutionInfo_InitilizingLoop);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ExecutionInfo_QueryCancelledbyUser);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ExecutionNotYetCompleteError);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ScriptError_Error);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ScriptError_FatalError);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ScriptError_ParsingSyntax);
|
||||
Assert.NotNull(ServiceLayerSr.EE_ScriptError_Warning);
|
||||
Assert.NotNull(ServiceLayerSr.ErrorEmptyStringReplacement);
|
||||
Assert.NotNull(ServiceLayerSr.ErrorUnexpectedCodeObjectType);
|
||||
Assert.Null(ServiceLayerSr.HostingHeaderMissingColon);
|
||||
Assert.Null(ServiceLayerSr.HostingHeaderMissingContentLengthHeader);
|
||||
Assert.Null(ServiceLayerSr.HostingHeaderMissingContentLengthValue);
|
||||
Assert.Null(ServiceLayerSr.HostingUnexpectedEndOfStream);
|
||||
Assert.Null(ServiceLayerSr.IncompatibleServiceForExtensionLoader);
|
||||
Assert.Null(ServiceLayerSr.MultipleServicesFound);
|
||||
Assert.NotNull(ServiceLayerSr.PeekDefinitionAzureError);
|
||||
Assert.NotNull(ServiceLayerSr.PeekDefinitionDatabaseError);
|
||||
Assert.NotNull(ServiceLayerSr.PeekDefinitionError);
|
||||
Assert.NotNull(ServiceLayerSr.PeekDefinitionNoResultsError);
|
||||
Assert.NotNull(ServiceLayerSr.PeekDefinitionNotConnectedError);
|
||||
Assert.NotNull(ServiceLayerSr.PeekDefinitionTimedoutError);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceAffectedOneRow);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceAffectedRows);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceCancelAlreadyCompleted);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceCancelDisposeFailed);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceColumnNull);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceCompletedSuccessfully);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceDataReaderByteCountInvalid);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceDataReaderCharCountInvalid);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceDataReaderXmlCountInvalid);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceErrorFormat);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceExecutionPlanNotFound);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceFileWrapperNotInitialized);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceFileWrapperReadOnly);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceFileWrapperWriteOnly);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceMessageSenderNotSql);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceQueryCancelled);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceQueryFailed);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceQueryInProgress);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceQueryInvalidOwnerUri);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceRequestsNoQuery);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceResultSetNoColumnSchema);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceResultSetNotRead);
|
||||
Assert.Null(ServiceLayerSr.QueryServiceResultSetReaderNull);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceResultSetRowCountOutOfRange);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceResultSetStartRowOutOfRange);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSaveAsFail);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSaveAsInProgress);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSaveAsMiscStartingError);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSaveAsResultSetNotComplete);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSubsetBatchNotCompleted);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSubsetBatchOutOfRange);
|
||||
Assert.NotNull(ServiceLayerSr.QueryServiceSubsetResultSetOutOfRange);
|
||||
Assert.Null(ServiceLayerSr.ServiceAlreadyRegistered);
|
||||
Assert.Null(ServiceLayerSr.ServiceNotFound);
|
||||
Assert.Null(ServiceLayerSr.ServiceNotOfExpectedType);
|
||||
Assert.Null(ServiceLayerSr.ServiceProviderNotSet);
|
||||
Assert.NotNull(ServiceLayerSr.TestLocalizationConstant);
|
||||
Assert.NotNull(ServiceLayerSr.TroubleshootingAssistanceMessage);
|
||||
Assert.NotNull(ServiceLayerSr.WorkspaceServiceBufferPositionOutOfOrder);
|
||||
Assert.NotNull(ServiceLayerSr.WorkspaceServicePositionColumnOutOfRange);
|
||||
Assert.NotNull(ServiceLayerSr.WorkspaceServicePositionLineOutOfRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user