mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 09:35:37 -05:00
New test common project for database connections using the settings.json (#210)
* moved test driver tests and test common classes to separate projects
This commit is contained in:
@@ -3,11 +3,13 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
@@ -19,12 +21,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
/// </summary>
|
||||
public class LanguageServiceTests
|
||||
{
|
||||
private static void GetLiveAutoCompleteTestObjects(
|
||||
out TextDocumentPosition textDocument,
|
||||
out ScriptFile scriptFile,
|
||||
out ConnectionInfo connInfo)
|
||||
private async static Task<TestConnectionResult> GetLiveAutoCompleteTestObjects()
|
||||
{
|
||||
textDocument = new TextDocumentPosition
|
||||
var textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier { Uri = TestObjects.ScriptUri },
|
||||
Position = new Position
|
||||
@@ -34,7 +33,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
}
|
||||
};
|
||||
|
||||
connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
result.TextDocumentPosition = textDocument;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
{
|
||||
try
|
||||
{
|
||||
TestObjects.InitializeTestServices();
|
||||
TestServiceProvider.InitializeTestServices();
|
||||
}
|
||||
catch (System.ArgumentException)
|
||||
{
|
||||
@@ -61,10 +62,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
/// Test the service initialization code path and verify nothing throws
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PrepopulateCommonMetadata()
|
||||
public async Task PrepopulateCommonMetadata()
|
||||
{
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
var connInfo = result.ConnectionInfo;
|
||||
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||
|
||||
@@ -75,21 +76,18 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
// 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()
|
||||
public async Task AutoCompleteFindCompletions()
|
||||
{
|
||||
TextDocumentPosition textDocument;
|
||||
ConnectionInfo connInfo;
|
||||
ScriptFile scriptFile;
|
||||
GetLiveAutoCompleteTestObjects(out textDocument, out scriptFile, out connInfo);
|
||||
var result = await GetLiveAutoCompleteTestObjects();
|
||||
|
||||
textDocument.Position.Character = 7;
|
||||
scriptFile.Contents = "select ";
|
||||
result.TextDocumentPosition.Position.Character = 7;
|
||||
result.ScriptFile.Contents = "select ";
|
||||
|
||||
var autoCompleteService = LanguageService.Instance;
|
||||
var completions = autoCompleteService.GetCompletionItems(
|
||||
textDocument,
|
||||
scriptFile,
|
||||
connInfo);
|
||||
result.TextDocumentPosition,
|
||||
result.ScriptFile,
|
||||
result.ConnectionInfo);
|
||||
|
||||
Assert.True(completions.Length > 0);
|
||||
}
|
||||
@@ -100,21 +98,20 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
/// provide signature help.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
|
||||
public async Task GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
|
||||
{
|
||||
// When we make a connection to a live database
|
||||
ScriptFile scriptFile;
|
||||
Hosting.ServiceHost.SendEventIgnoreExceptions = true;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
|
||||
// And we place the cursor after a function that should prompt for signature help
|
||||
string queryWithFunction = "EXEC sys.fn_isrolemember ";
|
||||
scriptFile.Contents = queryWithFunction;
|
||||
result.ScriptFile.Contents = queryWithFunction;
|
||||
TextDocumentPosition textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier
|
||||
{
|
||||
Uri = scriptFile.ClientFilePath
|
||||
Uri = result.ScriptFile.ClientFilePath
|
||||
},
|
||||
Position = new Position
|
||||
{
|
||||
@@ -125,14 +122,14 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
|
||||
// If the SQL has already been parsed
|
||||
var service = LanguageService.Instance;
|
||||
await service.UpdateLanguageServiceOnConnection(connInfo);
|
||||
await service.UpdateLanguageServiceOnConnection(result.ConnectionInfo);
|
||||
|
||||
// We should get back a non-null ScriptParseInfo
|
||||
ScriptParseInfo parseInfo = service.GetScriptParseInfo(scriptFile.ClientFilePath);
|
||||
ScriptParseInfo parseInfo = service.GetScriptParseInfo(result.ScriptFile.ClientFilePath);
|
||||
Assert.NotNull(parseInfo);
|
||||
|
||||
// And we should get back a non-null SignatureHelp
|
||||
SignatureHelp signatureHelp = service.GetSignatureHelp(textDocument, scriptFile);
|
||||
SignatureHelp signatureHelp = service.GetSignatureHelp(textDocument, result.ScriptFile);
|
||||
Assert.NotNull(signatureHelp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,32 +35,16 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// </summary>
|
||||
public class PeekDefinitionTests
|
||||
{
|
||||
private const int TaskTimeout = 30000;
|
||||
|
||||
private readonly string testScriptUri = TestObjects.ScriptUri;
|
||||
|
||||
private readonly string testConnectionKey = "testdbcontextkey";
|
||||
|
||||
private Mock<ConnectedBindingQueue> bindingQueue;
|
||||
|
||||
private Mock<WorkspaceService<SqlToolsSettings>> workspaceService;
|
||||
|
||||
private Mock<RequestContext<Location[]>> requestContext;
|
||||
|
||||
private Mock<IBinder> binder;
|
||||
|
||||
private TextDocumentPosition textDocument;
|
||||
|
||||
private const string OwnerUri = "testFile1";
|
||||
|
||||
/// <summary>
|
||||
/// Test get definition for a table object with active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetValidTableDefinitionTest()
|
||||
public async Task GetValidTableDefinitionTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -79,10 +63,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for a invalid table object with active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetTableDefinitionInvalidObjectTest()
|
||||
public async Task GetTableDefinitionInvalidObjectTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -99,10 +83,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for a valid table object with schema and active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetTableDefinitionWithSchemaTest()
|
||||
public async Task GetTableDefinitionWithSchemaTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -121,9 +105,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetUnsupportedDefinitionErrorTest()
|
||||
public async Task GetUnsupportedDefinitionErrorTest()
|
||||
{
|
||||
ScriptFile scriptFile;
|
||||
TextDocumentPosition textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
|
||||
@@ -134,14 +117,14 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
Character = 16
|
||||
}
|
||||
};
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
scriptFile.Contents = "select * from dbo.func ()";
|
||||
TestConnectionResult connectionResult = await TestObjects.InitLiveConnectionInfo();
|
||||
connectionResult.ScriptFile.Contents = "select * from dbo.func ()";
|
||||
var languageService = new LanguageService();
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||
languageService.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
|
||||
|
||||
// When I call the language service
|
||||
var result = languageService.GetDefinition(textDocument, scriptFile, connInfo);
|
||||
var result = languageService.GetDefinition(textDocument, connectionResult.ScriptFile, connectionResult.ConnectionInfo);
|
||||
|
||||
// Then I expect null locations and an error to be reported
|
||||
Assert.NotNull(result);
|
||||
@@ -152,9 +135,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Get Definition for a object with no definition. Expect a error result
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetDefinitionWithNoResultsFoundError()
|
||||
public async Task GetDefinitionWithNoResultsFoundError()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -172,7 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test GetDefinition with a forced timeout. Expect a error result.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetDefinitionTimeoutTest()
|
||||
public async Task GetDefinitionTimeoutTest()
|
||||
{
|
||||
// Given a binding queue that will automatically time out
|
||||
var languageService = new LanguageService();
|
||||
@@ -198,7 +181,6 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
})
|
||||
.Returns(() => itemMock.Object);
|
||||
|
||||
ScriptFile scriptFile;
|
||||
TextDocumentPosition textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
|
||||
@@ -208,7 +190,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
Character = 20
|
||||
}
|
||||
};
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
TestConnectionResult connectionResult = await TestObjects.InitLiveConnectionInfo();
|
||||
ScriptFile scriptFile = connectionResult.ScriptFile;
|
||||
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
||||
scriptFile.Contents = "select * from dbo.func ()";
|
||||
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||
@@ -228,9 +212,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for a view object with active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetValidViewDefinitionTest()
|
||||
public async Task GetValidViewDefinitionTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -247,10 +231,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for an invalid view object with no schema name and with active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetViewDefinitionInvalidObjectTest()
|
||||
public async Task GetViewDefinitionInvalidObjectTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -266,10 +250,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for a stored procedure object with active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetStoredProcedureDefinitionTest()
|
||||
public async Task GetStoredProcedureDefinitionTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -287,10 +271,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for a stored procedure object that does not exist with active connection
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetStoredProcedureDefinitionFailureTest()
|
||||
public async Task GetStoredProcedureDefinitionFailureTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
@@ -306,10 +290,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
|
||||
/// Test get definition for a stored procedure object with active connection and no schema
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetStoredProcedureDefinitionWithoutSchemaTest()
|
||||
public async Task GetStoredProcedureDefinitionWithoutSchemaTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ConnectionInfo connInfo = await TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
|
||||
Reference in New Issue
Block a user