mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Merge pull request #34 from Microsoft/feature/testSmo
Enable SMO-based autocomplete
This commit is contained in:
55
test/CodeCoverage/ReplaceText.vbs
Normal file
55
test/CodeCoverage/ReplaceText.vbs
Normal file
@@ -0,0 +1,55 @@
|
||||
' ReplaceText.vbs
|
||||
' Copied from answer at http://stackoverflow.com/questions/1115508/batch-find-and-edit-lines-in-txt-file
|
||||
|
||||
Option Explicit
|
||||
|
||||
Const ForAppending = 8
|
||||
Const TristateFalse = 0 ' the value for ASCII
|
||||
Const Overwrite = True
|
||||
|
||||
Const WindowsFolder = 0
|
||||
Const SystemFolder = 1
|
||||
Const TemporaryFolder = 2
|
||||
|
||||
Dim FileSystem
|
||||
Dim Filename, OldText, NewText
|
||||
Dim OriginalFile, TempFile, Line
|
||||
Dim TempFilename
|
||||
|
||||
If WScript.Arguments.Count = 3 Then
|
||||
Filename = WScript.Arguments.Item(0)
|
||||
OldText = WScript.Arguments.Item(1)
|
||||
NewText = WScript.Arguments.Item(2)
|
||||
Else
|
||||
Wscript.Echo "Usage: ReplaceText.vbs <Filename> <OldText> <NewText>"
|
||||
Wscript.Quit
|
||||
End If
|
||||
|
||||
Set FileSystem = CreateObject("Scripting.FileSystemObject")
|
||||
Dim tempFolder: tempFolder = FileSystem.GetSpecialFolder(TemporaryFolder)
|
||||
TempFilename = FileSystem.GetTempName
|
||||
|
||||
If FileSystem.FileExists(TempFilename) Then
|
||||
FileSystem.DeleteFile TempFilename
|
||||
End If
|
||||
|
||||
Set TempFile = FileSystem.CreateTextFile(TempFilename, Overwrite, TristateFalse)
|
||||
Set OriginalFile = FileSystem.OpenTextFile(Filename)
|
||||
|
||||
Do Until OriginalFile.AtEndOfStream
|
||||
Line = OriginalFile.ReadLine
|
||||
|
||||
If InStr(Line, OldText) > 0 Then
|
||||
Line = Replace(Line, OldText, NewText)
|
||||
End If
|
||||
|
||||
TempFile.WriteLine(Line)
|
||||
Loop
|
||||
|
||||
OriginalFile.Close
|
||||
TempFile.Close
|
||||
|
||||
FileSystem.DeleteFile Filename
|
||||
FileSystem.MoveFile TempFilename, Filename
|
||||
|
||||
Wscript.Quit
|
||||
25
test/CodeCoverage/codecoverage.bat
Normal file
25
test/CodeCoverage/codecoverage.bat
Normal file
@@ -0,0 +1,25 @@
|
||||
SET WORKINGDIR=%~dp0
|
||||
|
||||
REM clean-up results from previous run
|
||||
RMDIR %WORKINGDIR%reports\ /S /Q
|
||||
DEL %WORKINGDIR%coverage.xml
|
||||
MKDIR reports
|
||||
|
||||
REM backup current project.json
|
||||
COPY /Y %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json.BAK
|
||||
|
||||
REM switch PDB type to Full since that is required by OpenCover for now
|
||||
REM we should remove this step on OpenCover supports portable PDB
|
||||
cscript /nologo ReplaceText.vbs %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json portable full
|
||||
|
||||
REM rebuild the SqlToolsService project
|
||||
dotnet build %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json
|
||||
|
||||
REM run the tests through OpenCover and generate a report
|
||||
"%WORKINGDIR%packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\project.json" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\bin\Debug\netcoreapp1.0
|
||||
"%WORKINGDIR%packages\ReportGenerator.2.4.5.0\tools\ReportGenerator.exe" "-reports:coverage.xml" "-targetdir:%WORKINGDIR%\reports"
|
||||
|
||||
REM restore original project.json
|
||||
COPY /Y %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json.BAK %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json
|
||||
DEL %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json.BAK
|
||||
EXIT
|
||||
107
test/CodeCoverage/gulpfile.js
Normal file
107
test/CodeCoverage/gulpfile.js
Normal file
@@ -0,0 +1,107 @@
|
||||
var gulp = require('gulp');
|
||||
var del = require('del');
|
||||
var request = require('request');
|
||||
var fs = require('fs');
|
||||
var gutil = require('gulp-util');
|
||||
var through = require('through2');
|
||||
var cproc = require('child_process');
|
||||
var os = require('os');
|
||||
|
||||
function nugetRestoreArgs(nupkg, options) {
|
||||
var args = new Array();
|
||||
if (os.platform() != 'win32') {
|
||||
args.push('./nuget.exe');
|
||||
}
|
||||
args.push('restore');
|
||||
args.push(nupkg);
|
||||
|
||||
var withValues = [
|
||||
'source',
|
||||
'configFile',
|
||||
'packagesDirectory',
|
||||
'solutionDirectory',
|
||||
'msBuildVersion'
|
||||
];
|
||||
|
||||
var withoutValues = [
|
||||
'noCache',
|
||||
'requireConsent',
|
||||
'disableParallelProcessing'
|
||||
];
|
||||
|
||||
withValues.forEach(function(prop) {
|
||||
var value = options[prop];
|
||||
if(value) {
|
||||
args.push('-' + prop);
|
||||
args.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
withoutValues.forEach(function(prop) {
|
||||
var value = options[prop];
|
||||
if(value) {
|
||||
args.push('-' + prop);
|
||||
}
|
||||
});
|
||||
|
||||
args.push('-noninteractive');
|
||||
|
||||
return args;
|
||||
};
|
||||
|
||||
function nugetRestore(options) {
|
||||
options = options || {};
|
||||
options.nuget = options.nuget || './nuget.exe';
|
||||
if (os.platform() != 'win32') {
|
||||
options.nuget = 'mono';
|
||||
}
|
||||
|
||||
return through.obj(function(file, encoding, done) {
|
||||
var args = nugetRestoreArgs(file.path, options);
|
||||
cproc.execFile(options.nuget, args, function(err, stdout) {
|
||||
if (err) {
|
||||
throw new gutil.PluginError('gulp-nuget', err);
|
||||
}
|
||||
|
||||
gutil.log(stdout.trim());
|
||||
done(null, file);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
gulp.task('ext:nuget-download', function(done) {
|
||||
if(fs.existsSync('nuget.exe')) {
|
||||
return done();
|
||||
}
|
||||
|
||||
request.get('http://nuget.org/nuget.exe')
|
||||
.pipe(fs.createWriteStream('nuget.exe'))
|
||||
.on('close', done);
|
||||
});
|
||||
|
||||
gulp.task('ext:nuget-restore', function() {
|
||||
|
||||
var options = {
|
||||
configFile: './nuget.config',
|
||||
packagesDirectory: './packages'
|
||||
};
|
||||
|
||||
return gulp.src('./packages.config')
|
||||
.pipe(nugetRestore(options));
|
||||
});
|
||||
|
||||
|
||||
gulp.task('ext:code-coverage', function(done) {
|
||||
cproc.execFile('cmd.exe', [ '/c', 'codecoverage.bat' ], function(err, stdout) {
|
||||
if (err) {
|
||||
throw new gutil.PluginError('ext:code-coverage', err);
|
||||
}
|
||||
|
||||
gutil.log(stdout.trim());
|
||||
});
|
||||
return done();
|
||||
});
|
||||
|
||||
gulp.task('test', gulp.series('ext:nuget-download', 'ext:nuget-restore', 'ext:code-coverage'));
|
||||
|
||||
gulp.task('default', gulp.series('test'));
|
||||
8
test/CodeCoverage/nuget.config
Normal file
8
test/CodeCoverage/nuget.config
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration >
|
||||
<packageSources>
|
||||
<add key="https://www.nuget.org/api/v2/" value="https://www.nuget.org/api/v2/" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
|
||||
16
test/CodeCoverage/package.json
Normal file
16
test/CodeCoverage/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "sqltoolsservice",
|
||||
"version": "0.1.0",
|
||||
"description": "SQL Tools Service Layer",
|
||||
"main": "gulpfile.js",
|
||||
"dependencies": {
|
||||
"gulp": "github:gulpjs/gulp#4.0",
|
||||
"del": "^2.2.1",
|
||||
"gulp-hub": "frankwallis/gulp-hub#registry-init",
|
||||
"gulp-install": "^0.6.0",
|
||||
"request": "^2.73.0"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"author": "Microsoft",
|
||||
"license": "MIT"
|
||||
}
|
||||
5
test/CodeCoverage/packages.config
Normal file
5
test/CodeCoverage/packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenCover" version="4.6.519" />
|
||||
<package id="ReportGenerator" version="2.4.5" />
|
||||
</packages>
|
||||
@@ -3,13 +3,26 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.SmoMetadataProvider;
|
||||
using Microsoft.SqlServer.Management.SqlParser;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Binder;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
||||
using Microsoft.SqlServer.Management.SqlParser.MetadataProvider;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
@@ -137,6 +150,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
|
||||
#region "Autocomplete Tests"
|
||||
|
||||
// This test currently requires a live database connection to initialize
|
||||
// SMO connected metadata provider. Since we don't want a live DB dependency
|
||||
// in the CI unit tests this scenario is currently disabled.
|
||||
//[Fact]
|
||||
public void AutoCompleteFindCompletions()
|
||||
{
|
||||
TextDocumentPosition textDocument;
|
||||
ConnectionInfo connInfo;
|
||||
ScriptFile scriptFile;
|
||||
Common.GetAutoCompleteTestObjects(out textDocument, out scriptFile, out connInfo);
|
||||
|
||||
textDocument.Position.Character = 7;
|
||||
scriptFile.Contents = "select ";
|
||||
|
||||
var autoCompleteService = AutoCompleteService.Instance;
|
||||
var completions = autoCompleteService.GetCompletionItems(
|
||||
textDocument,
|
||||
scriptFile,
|
||||
connInfo);
|
||||
|
||||
Assert.True(completions.Length > 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mock db command that returns a predefined result set
|
||||
/// </summary>
|
||||
@@ -164,160 +200,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
return connectionMock.Object;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the autocomplete service returns tables for the current connection as suggestions
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TablesAreReturnedAsAutocompleteSuggestions()
|
||||
{
|
||||
// Result set for the query of database tables
|
||||
Dictionary<string, string>[] data =
|
||||
{
|
||||
new Dictionary<string, string> { {"name", "master" } },
|
||||
new Dictionary<string, string> { {"name", "model" } }
|
||||
};
|
||||
|
||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||
mockFactory.Setup(factory => factory.CreateSqlConnection(It.IsAny<string>()))
|
||||
.Returns(CreateMockDbConnection(new[] {data}));
|
||||
|
||||
var connectionService = new ConnectionService(mockFactory.Object);
|
||||
var autocompleteService = new AutoCompleteService();
|
||||
autocompleteService.ConnectionServiceInstance = connectionService;
|
||||
autocompleteService.InitializeService(Microsoft.SqlTools.ServiceLayer.Hosting.ServiceHost.Instance);
|
||||
|
||||
// Open a connection
|
||||
// The cache should get updated as part of this
|
||||
ConnectParams connectionRequest = TestObjects.GetTestConnectionParams();
|
||||
var connectionResult = connectionService.Connect(connectionRequest);
|
||||
Assert.NotEmpty(connectionResult.ConnectionId);
|
||||
|
||||
// Check that there is one cache created in the auto complete service
|
||||
Assert.Equal(1, autocompleteService.GetCacheCount());
|
||||
|
||||
// Check that we get table suggestions for an autocomplete request
|
||||
TextDocumentPosition position = new TextDocumentPosition();
|
||||
position.TextDocument = new TextDocumentIdentifier();
|
||||
position.TextDocument.Uri = connectionRequest.OwnerUri;
|
||||
position.Position = new Position();
|
||||
position.Position.Line = 1;
|
||||
position.Position.Character = 1;
|
||||
var items = autocompleteService.GetCompletionItems(position);
|
||||
Assert.Equal(2, items.Length);
|
||||
Assert.Equal("master", items[0].Label);
|
||||
Assert.Equal("model", items[1].Label);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that only one intellisense cache is created for two documents using
|
||||
/// the autocomplete service when they share a common connection.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OnlyOneCacheIsCreatedForTwoDocumentsWithSameConnection()
|
||||
{
|
||||
var connectionService = new ConnectionService(TestObjects.GetTestSqlConnectionFactory());
|
||||
var autocompleteService = new AutoCompleteService();
|
||||
autocompleteService.ConnectionServiceInstance = connectionService;
|
||||
autocompleteService.InitializeService(Microsoft.SqlTools.ServiceLayer.Hosting.ServiceHost.Instance);
|
||||
|
||||
// Open two connections
|
||||
ConnectParams connectionRequest1 = TestObjects.GetTestConnectionParams();
|
||||
connectionRequest1.OwnerUri = "file:///my/first/file.sql";
|
||||
ConnectParams connectionRequest2 = TestObjects.GetTestConnectionParams();
|
||||
connectionRequest2.OwnerUri = "file:///my/second/file.sql";
|
||||
var connectionResult1 = connectionService.Connect(connectionRequest1);
|
||||
Assert.NotEmpty(connectionResult1.ConnectionId);
|
||||
var connectionResult2 = connectionService.Connect(connectionRequest2);
|
||||
Assert.NotEmpty(connectionResult2.ConnectionId);
|
||||
|
||||
// Verify that only one intellisense cache is created to service both URI's
|
||||
Assert.Equal(1, autocompleteService.GetCacheCount());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that two different intellisense caches and corresponding autocomplete
|
||||
/// suggestions are provided for two documents with different connections.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TwoCachesAreCreatedForTwoDocumentsWithDifferentConnections()
|
||||
{
|
||||
const string testDb1 = "my_db";
|
||||
const string testDb2 = "my_other_db";
|
||||
|
||||
// Result set for the query of database tables
|
||||
Dictionary<string, string>[] data1 =
|
||||
{
|
||||
new Dictionary<string, string> { {"name", "master" } },
|
||||
new Dictionary<string, string> { {"name", "model" } }
|
||||
};
|
||||
|
||||
Dictionary<string, string>[] data2 =
|
||||
{
|
||||
new Dictionary<string, string> { {"name", "master" } },
|
||||
new Dictionary<string, string> { {"name", "my_table" } },
|
||||
new Dictionary<string, string> { {"name", "my_other_table" } }
|
||||
};
|
||||
|
||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||
mockFactory.Setup(factory => factory.CreateSqlConnection(It.Is<string>(x => x.Contains(testDb1))))
|
||||
.Returns(CreateMockDbConnection(new[] {data1}));
|
||||
mockFactory.Setup(factory => factory.CreateSqlConnection(It.Is<string>(x => x.Contains(testDb2))))
|
||||
.Returns(CreateMockDbConnection(new[] {data2}));
|
||||
|
||||
var connectionService = new ConnectionService(mockFactory.Object);
|
||||
var autocompleteService = new AutoCompleteService();
|
||||
autocompleteService.ConnectionServiceInstance = connectionService;
|
||||
autocompleteService.InitializeService(Microsoft.SqlTools.ServiceLayer.Hosting.ServiceHost.Instance);
|
||||
|
||||
// Open connections
|
||||
// The cache should get updated as part of this
|
||||
ConnectParams connectionRequest = TestObjects.GetTestConnectionParams();
|
||||
connectionRequest.OwnerUri = "file:///my/first/sql/file.sql";
|
||||
connectionRequest.Connection.DatabaseName = testDb1;
|
||||
var connectionResult = connectionService.Connect(connectionRequest);
|
||||
Assert.NotEmpty(connectionResult.ConnectionId);
|
||||
|
||||
// Check that there is one cache created in the auto complete service
|
||||
Assert.Equal(1, autocompleteService.GetCacheCount());
|
||||
|
||||
// Open second connection
|
||||
ConnectParams connectionRequest2 = TestObjects.GetTestConnectionParams();
|
||||
connectionRequest2.OwnerUri = "file:///my/second/sql/file.sql";
|
||||
connectionRequest2.Connection.DatabaseName = testDb2;
|
||||
var connectionResult2 = connectionService.Connect(connectionRequest2);
|
||||
Assert.NotEmpty(connectionResult2.ConnectionId);
|
||||
|
||||
// Check that there are now two caches in the auto complete service
|
||||
Assert.Equal(2, autocompleteService.GetCacheCount());
|
||||
|
||||
// Check that we get 2 different table suggestions for autocomplete requests
|
||||
TextDocumentPosition position = new TextDocumentPosition();
|
||||
position.TextDocument = new TextDocumentIdentifier();
|
||||
position.TextDocument.Uri = connectionRequest.OwnerUri;
|
||||
position.Position = new Position();
|
||||
position.Position.Line = 1;
|
||||
position.Position.Character = 1;
|
||||
|
||||
var items = autocompleteService.GetCompletionItems(position);
|
||||
Assert.Equal(2, items.Length);
|
||||
Assert.Equal("master", items[0].Label);
|
||||
Assert.Equal("model", items[1].Label);
|
||||
|
||||
TextDocumentPosition position2 = new TextDocumentPosition();
|
||||
position2.TextDocument = new TextDocumentIdentifier();
|
||||
position2.TextDocument.Uri = connectionRequest2.OwnerUri;
|
||||
position2.Position = new Position();
|
||||
position2.Position.Line = 1;
|
||||
position2.Position.Character = 1;
|
||||
|
||||
var items2 = autocompleteService.GetCompletionItems(position2);
|
||||
Assert.Equal(3, items2.Length);
|
||||
Assert.Equal("master", items2[0].Label);
|
||||
Assert.Equal("my_table", items2[1].Label);
|
||||
Assert.Equal("my_other_table", items2[2].Label);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,16 +7,23 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.SmoMetadataProvider;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Binder;
|
||||
using Microsoft.SqlServer.Management.SqlParser.MetadataProvider;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Moq;
|
||||
using Moq.Protected;
|
||||
|
||||
@@ -36,6 +43,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
|
||||
public const int StandardColumns = 5;
|
||||
|
||||
public static string TestServer { get; set; }
|
||||
|
||||
public static string TestDatabase { get; set; }
|
||||
|
||||
static Common()
|
||||
{
|
||||
TestServer = "sqltools11";
|
||||
TestDatabase = "master";
|
||||
}
|
||||
|
||||
public static Dictionary<string, string>[] StandardTestData
|
||||
{
|
||||
get { return GetTestData(StandardRows, StandardColumns); }
|
||||
@@ -122,8 +139,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
{
|
||||
UserName = "sa",
|
||||
Password = "Yukon900",
|
||||
DatabaseName = "AdventureWorks2016CTP3_2",
|
||||
ServerName = "sqltools11"
|
||||
DatabaseName = Common.TestDatabase,
|
||||
ServerName = Common.TestServer
|
||||
};
|
||||
|
||||
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, connDetails);
|
||||
@@ -132,7 +149,46 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
||||
#endregion
|
||||
|
||||
#region Service Mocking
|
||||
|
||||
public static void GetAutoCompleteTestObjects(
|
||||
out TextDocumentPosition textDocument,
|
||||
out ScriptFile scriptFile,
|
||||
out ConnectionInfo connInfo
|
||||
)
|
||||
{
|
||||
textDocument = new TextDocumentPosition();
|
||||
textDocument.TextDocument = new TextDocumentIdentifier();
|
||||
textDocument.TextDocument.Uri = Common.OwnerUri;
|
||||
textDocument.Position = new Position();
|
||||
textDocument.Position.Line = 0;
|
||||
textDocument.Position.Character = 0;
|
||||
|
||||
connInfo = Common.CreateTestConnectionInfo(null, false);
|
||||
|
||||
var srvConn = GetServerConnection(connInfo);
|
||||
var displayInfoProvider = new MetadataDisplayInfoProvider();
|
||||
var metadataProvider = SmoMetadataProvider.CreateConnectedProvider(srvConn);
|
||||
var binder = BinderProvider.CreateBinder(metadataProvider);
|
||||
|
||||
LanguageService.Instance.ScriptParseInfoMap.Add(textDocument.TextDocument.Uri,
|
||||
new ScriptParseInfo()
|
||||
{
|
||||
Binder = binder,
|
||||
MetadataProvider = metadataProvider,
|
||||
MetadataDisplayInfoProvider = displayInfoProvider
|
||||
});
|
||||
|
||||
scriptFile = new ScriptFile();
|
||||
scriptFile.ClientFilePath = textDocument.TextDocument.Uri;
|
||||
}
|
||||
|
||||
public static ServerConnection GetServerConnection(ConnectionInfo connection)
|
||||
{
|
||||
string connectionString = ConnectionService.BuildConnectionString(connection.ConnectionDetails);
|
||||
var sqlConnection = new SqlConnection(connectionString);
|
||||
return new ServerConnection(sqlConnection);
|
||||
}
|
||||
|
||||
public static ConnectionDetails GetTestConnectionDetails()
|
||||
{
|
||||
return new ConnectionDetails
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.1.0",
|
||||
"Microsoft.SqlServer.Smo": "140.1.5",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-192208-24",
|
||||
"moq": "4.6.36-alpha",
|
||||
|
||||
Reference in New Issue
Block a user