mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 01:25:40 -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:
@@ -9,9 +9,12 @@ using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
@@ -30,6 +33,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
/// </summary>
|
||||
public class ReliableConnectionTests
|
||||
{
|
||||
private TestConnectionProfileService connectionProfileService = new TestConnectionProfileService();
|
||||
|
||||
internal class TestDataTransferErrorDetectionStrategy : DataTransferErrorDetectionStrategy
|
||||
{
|
||||
public bool InvokeCanRetrySqlException(SqlException exception)
|
||||
@@ -230,11 +235,23 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
/// <summary>
|
||||
/// Helper method to create an integrated auth connection builder for testing.
|
||||
/// </summary>
|
||||
private SqlConnectionStringBuilder CreateTestConnectionStringBuilder()
|
||||
private async Task<SqlConnectionStringBuilder> CreateTestConnectionStringBuilder()
|
||||
{
|
||||
ConnectParams connectParams = await this.connectionProfileService.GetConnectionParametersAsync();
|
||||
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
|
||||
csb.DataSource = TestServerName;
|
||||
csb.IntegratedSecurity = true;
|
||||
csb.DataSource = connectParams.Connection.ServerName;
|
||||
csb.IntegratedSecurity = connectParams.Connection.AuthenticationType == AuthenticationType.Integrated.ToString();
|
||||
if (connectParams.Connection.UserName != null)
|
||||
{
|
||||
csb.UserID = connectParams.Connection.UserName;
|
||||
}
|
||||
if (connectParams.Connection.Password != null)
|
||||
{
|
||||
csb.Password = connectParams.Connection.Password;
|
||||
}
|
||||
csb.ConnectTimeout = connectParams.Connection.ConnectTimeout.HasValue ? connectParams.Connection.ConnectTimeout.Value: 30;
|
||||
csb.Encrypt = connectParams.Connection.Encrypt.HasValue ? connectParams.Connection.Encrypt.Value : false;
|
||||
csb.TrustServerCertificate = connectParams.Connection.TrustServerCertificate.HasValue ? connectParams.Connection.TrustServerCertificate.Value : false;
|
||||
|
||||
return csb;
|
||||
}
|
||||
@@ -242,9 +259,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
/// <summary>
|
||||
/// Helper method to create an integrated auth reliable connection for testing.
|
||||
/// </summary>
|
||||
private DbConnection CreateTestConnection()
|
||||
private async Task<DbConnection> CreateTestConnection()
|
||||
{
|
||||
SqlConnectionStringBuilder csb = CreateTestConnectionStringBuilder();
|
||||
SqlConnectionStringBuilder csb = await CreateTestConnectionStringBuilder();
|
||||
|
||||
RetryPolicy connectionRetryPolicy = RetryPolicyFactory.CreateDefaultConnectionRetryPolicy();
|
||||
RetryPolicy commandRetryPolicy = RetryPolicyFactory.CreateDefaultConnectionRetryPolicy();
|
||||
@@ -257,64 +274,59 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
/// Test ReliableConnectionHelper.GetDefaultDatabaseFilePath()
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestGetDefaultDatabaseFilePath()
|
||||
public async Task TestGetDefaultDatabaseFilePath()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
{
|
||||
var connectionBuilder = CreateTestConnectionStringBuilder();
|
||||
Assert.NotNull(connectionBuilder);
|
||||
|
||||
string filePath = string.Empty;
|
||||
string logPath = string.Empty;
|
||||
var connectionBuilder = await CreateTestConnectionStringBuilder();
|
||||
Assert.NotNull(connectionBuilder);
|
||||
|
||||
ReliableConnectionHelper.OpenConnection(
|
||||
connectionBuilder,
|
||||
usingConnection: (conn) =>
|
||||
{
|
||||
filePath = ReliableConnectionHelper.GetDefaultDatabaseFilePath(conn);
|
||||
logPath = ReliableConnectionHelper.GetDefaultDatabaseLogPath(conn);
|
||||
},
|
||||
catchException: null,
|
||||
useRetry: false);
|
||||
string filePath = string.Empty;
|
||||
string logPath = string.Empty;
|
||||
|
||||
Assert.False(string.IsNullOrWhiteSpace(filePath));
|
||||
Assert.False(string.IsNullOrWhiteSpace(logPath));
|
||||
});
|
||||
ReliableConnectionHelper.OpenConnection(
|
||||
connectionBuilder,
|
||||
usingConnection: (conn) =>
|
||||
{
|
||||
filePath = ReliableConnectionHelper.GetDefaultDatabaseFilePath(conn);
|
||||
logPath = ReliableConnectionHelper.GetDefaultDatabaseLogPath(conn);
|
||||
},
|
||||
catchException: null,
|
||||
useRetry: false);
|
||||
|
||||
Assert.False(string.IsNullOrWhiteSpace(filePath));
|
||||
Assert.False(string.IsNullOrWhiteSpace(logPath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test ReliableConnectionHelper.GetServerVersion()
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestGetServerVersion()
|
||||
public async Task TestGetServerVersion()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
using (var connection = await CreateTestConnection())
|
||||
{
|
||||
using (var connection = CreateTestConnection())
|
||||
Assert.NotNull(connection);
|
||||
connection.Open();
|
||||
|
||||
ReliableConnectionHelper.ServerInfo serverInfo = ReliableConnectionHelper.GetServerVersion(connection);
|
||||
ReliableConnectionHelper.ServerInfo serverInfo2;
|
||||
using (var connection2 = await CreateTestConnection())
|
||||
{
|
||||
Assert.NotNull(connection);
|
||||
connection.Open();
|
||||
|
||||
ReliableConnectionHelper.ServerInfo serverInfo = ReliableConnectionHelper.GetServerVersion(connection);
|
||||
ReliableConnectionHelper.ServerInfo serverInfo2;
|
||||
using (var connection2 = CreateTestConnection())
|
||||
{
|
||||
connection2.Open();
|
||||
serverInfo2 = ReliableConnectionHelper.GetServerVersion(connection);
|
||||
}
|
||||
|
||||
Assert.NotNull(serverInfo);
|
||||
Assert.NotNull(serverInfo2);
|
||||
Assert.True(serverInfo.ServerMajorVersion != 0);
|
||||
Assert.True(serverInfo.ServerMajorVersion == serverInfo2.ServerMajorVersion);
|
||||
Assert.True(serverInfo.ServerMinorVersion == serverInfo2.ServerMinorVersion);
|
||||
Assert.True(serverInfo.ServerReleaseVersion == serverInfo2.ServerReleaseVersion);
|
||||
Assert.True(serverInfo.ServerEdition == serverInfo2.ServerEdition);
|
||||
Assert.True(serverInfo.IsCloud == serverInfo2.IsCloud);
|
||||
Assert.True(serverInfo.AzureVersion == serverInfo2.AzureVersion);
|
||||
Assert.True(serverInfo.IsAzureV1 == serverInfo2.IsAzureV1);
|
||||
connection2.Open();
|
||||
serverInfo2 = ReliableConnectionHelper.GetServerVersion(connection);
|
||||
}
|
||||
});
|
||||
|
||||
Assert.NotNull(serverInfo);
|
||||
Assert.NotNull(serverInfo2);
|
||||
Assert.True(serverInfo.ServerMajorVersion != 0);
|
||||
Assert.True(serverInfo.ServerMajorVersion == serverInfo2.ServerMajorVersion);
|
||||
Assert.True(serverInfo.ServerMinorVersion == serverInfo2.ServerMinorVersion);
|
||||
Assert.True(serverInfo.ServerReleaseVersion == serverInfo2.ServerReleaseVersion);
|
||||
Assert.True(serverInfo.ServerEdition == serverInfo2.ServerEdition);
|
||||
Assert.True(serverInfo.IsCloud == serverInfo2.IsCloud);
|
||||
Assert.True(serverInfo.AzureVersion == serverInfo2.AzureVersion);
|
||||
Assert.True(serverInfo.IsAzureV1 == serverInfo2.IsAzureV1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -334,9 +346,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
/// Tests ReliableConnectionHelper.IsDatabaseReadonly()
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestIsDatabaseReadonly()
|
||||
public async Task TestIsDatabaseReadonly()
|
||||
{
|
||||
var connectionBuilder = CreateTestConnectionStringBuilder();
|
||||
var connectionBuilder = await CreateTestConnectionStringBuilder();
|
||||
Assert.NotNull(connectionBuilder);
|
||||
|
||||
bool isReadOnly = ReliableConnectionHelper.IsDatabaseReadonly(connectionBuilder);
|
||||
@@ -350,22 +362,19 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
public void TestIsDatabaseReadonlyWithNullBuilder()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => ReliableConnectionHelper.IsDatabaseReadonly(null));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify ANSI_NULL and QUOTED_IDENTIFIER settings can be set and retrieved for a session
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void VerifyAnsiNullAndQuotedIdentifierSettingsReplayed()
|
||||
public async Task VerifyAnsiNullAndQuotedIdentifierSettingsReplayed()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
using (ReliableSqlConnection conn = (ReliableSqlConnection) ReliableConnectionHelper.OpenConnection(await CreateTestConnectionStringBuilder(), useRetry: true))
|
||||
{
|
||||
using (ReliableSqlConnection conn = (ReliableSqlConnection)ReliableConnectionHelper.OpenConnection(CreateTestConnectionStringBuilder(), useRetry: true))
|
||||
{
|
||||
VerifySessionSettings(conn, true);
|
||||
VerifySessionSettings(conn, false);
|
||||
}
|
||||
});
|
||||
VerifySessionSettings(conn, true);
|
||||
VerifySessionSettings(conn, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void VerifySessionSettings(ReliableSqlConnection conn, bool expectedSessionValue)
|
||||
@@ -468,73 +477,62 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
/// ReliableConnectionHelper.IsCloud() should be false for a local server
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestIsCloudIsFalseForLocalServer()
|
||||
public async Task TestIsCloudIsFalseForLocalServer()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
using (var connection = await CreateTestConnection())
|
||||
{
|
||||
using (var connection = CreateTestConnection())
|
||||
{
|
||||
Assert.NotNull(connection);
|
||||
Assert.NotNull(connection);
|
||||
|
||||
connection.Open();
|
||||
Assert.False(ReliableConnectionHelper.IsCloud(connection));
|
||||
}
|
||||
});
|
||||
connection.Open();
|
||||
Assert.False(ReliableConnectionHelper.IsCloud(connection));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that ReliableConnectionHelper.OpenConnection() opens a connection if it is closed
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestOpenConnectionOpensConnection()
|
||||
public async Task TestOpenConnectionOpensConnection()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
using (var connection = await CreateTestConnection())
|
||||
{
|
||||
using (var connection = CreateTestConnection())
|
||||
{
|
||||
Assert.NotNull(connection);
|
||||
Assert.NotNull(connection);
|
||||
|
||||
Assert.True(connection.State == ConnectionState.Closed);
|
||||
ReliableConnectionHelper.OpenConnection(connection);
|
||||
Assert.True(connection.State == ConnectionState.Open);
|
||||
}
|
||||
});
|
||||
Assert.True(connection.State == ConnectionState.Closed);
|
||||
ReliableConnectionHelper.OpenConnection(connection);
|
||||
Assert.True(connection.State == ConnectionState.Open);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that ReliableConnectionHelper.ExecuteNonQuery() runs successfully
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestExecuteNonQuery()
|
||||
public async Task TestExecuteNonQuery()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
{
|
||||
var result = ReliableConnectionHelper.ExecuteNonQuery(
|
||||
CreateTestConnectionStringBuilder(),
|
||||
"SET NOCOUNT ON; SET NOCOUNT OFF;",
|
||||
ReliableConnectionHelper.SetCommandTimeout,
|
||||
null,
|
||||
true
|
||||
var result = ReliableConnectionHelper.ExecuteNonQuery(
|
||||
await CreateTestConnectionStringBuilder(),
|
||||
"SET NOCOUNT ON; SET NOCOUNT OFF;",
|
||||
ReliableConnectionHelper.SetCommandTimeout,
|
||||
null,
|
||||
true
|
||||
);
|
||||
Assert.NotNull(result);
|
||||
});
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that TryGetServerVersion() gets server information
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestTryGetServerVersion()
|
||||
public async Task TestTryGetServerVersion()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
{
|
||||
ReliableConnectionHelper.ServerInfo info = null;
|
||||
Assert.True(ReliableConnectionHelper.TryGetServerVersion(CreateTestConnectionStringBuilder().ConnectionString, out info));
|
||||
ReliableConnectionHelper.ServerInfo info = null;
|
||||
var connBuilder = await CreateTestConnectionStringBuilder();
|
||||
Assert.True(ReliableConnectionHelper.TryGetServerVersion(connBuilder.ConnectionString, out info));
|
||||
|
||||
Assert.NotNull(info);
|
||||
Assert.NotNull(info.ServerVersion);
|
||||
Assert.NotEmpty(info.ServerVersion);
|
||||
});
|
||||
Assert.NotNull(info);
|
||||
Assert.NotNull(info.ServerVersion);
|
||||
Assert.NotEmpty(info.ServerVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -683,10 +681,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReliableConnectionHelperTest()
|
||||
public async Task ReliableConnectionHelperTest()
|
||||
{
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
|
||||
Assert.True(ReliableConnectionHelper.IsAuthenticatingDatabaseMaster(connInfo.SqlConnection));
|
||||
|
||||
@@ -699,7 +697,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
|
||||
Assert.NotNull(ReliableConnectionHelper.GetAsSqlConnection(connInfo.SqlConnection));
|
||||
|
||||
ServerInfo info = ReliableConnectionHelper.GetServerVersion(connInfo.SqlConnection);
|
||||
ReliableConnectionHelper.ServerInfo info = ReliableConnectionHelper.GetServerVersion(connInfo.SqlConnection);
|
||||
Assert.NotNull(ReliableConnectionHelper.IsVersionGreaterThan2012RTM(info));
|
||||
}
|
||||
|
||||
@@ -726,10 +724,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitReliableSqlConnectionTest()
|
||||
public async Task InitReliableSqlConnectionTest()
|
||||
{
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
|
||||
var connection = connInfo.SqlConnection as ReliableSqlConnection;
|
||||
var command = new ReliableSqlConnection.ReliableSqlCommand(connection);
|
||||
@@ -742,10 +740,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
Assert.True(connection.ConnectionTimeout > 0);
|
||||
connection.ClearPool();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ThrottlingReasonTests()
|
||||
{
|
||||
{
|
||||
var reason = RetryPolicy.ThrottlingReason.Unknown;
|
||||
Assert.NotNull(reason.ThrottlingMode);
|
||||
Assert.NotNull(reason.ThrottledResources);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
@@ -15,14 +16,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt
|
||||
{
|
||||
public class StorageDataReaderTests
|
||||
{
|
||||
private StorageDataReader GetTestStorageDataReader(out DbDataReader reader, string query)
|
||||
private async Task<StorageDataReader> GetTestStorageDataReader(string query)
|
||||
{
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
var result = await TestObjects.InitLiveConnectionInfo();
|
||||
|
||||
var command = connInfo.SqlConnection.CreateCommand();
|
||||
var command = result.ConnectionInfo.SqlConnection.CreateCommand();
|
||||
command.CommandText = query;
|
||||
reader = command.ExecuteReader();
|
||||
DbDataReader reader = command.ExecuteReader();
|
||||
|
||||
return new StorageDataReader(reader);
|
||||
}
|
||||
@@ -31,12 +31,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt
|
||||
/// Validate GetBytesWithMaxCapacity
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetBytesWithMaxCapacityTest()
|
||||
public async Task GetBytesWithMaxCapacityTest()
|
||||
{
|
||||
DbDataReader reader;
|
||||
var storageReader = GetTestStorageDataReader(
|
||||
out reader,
|
||||
var storageReader = await GetTestStorageDataReader(
|
||||
"SELECT CAST([name] as TEXT) As TextName FROM sys.all_columns");
|
||||
DbDataReader reader = storageReader.DbDataReader;
|
||||
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
@@ -49,12 +48,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt
|
||||
/// Validate GetCharsWithMaxCapacity
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetCharsWithMaxCapacityTest()
|
||||
public async Task GetCharsWithMaxCapacityTest()
|
||||
{
|
||||
DbDataReader reader;
|
||||
var storageReader = GetTestStorageDataReader(
|
||||
out reader,
|
||||
var storageReader = await GetTestStorageDataReader(
|
||||
"SELECT name FROM sys.all_columns");
|
||||
DbDataReader reader = storageReader.DbDataReader;
|
||||
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
@@ -72,12 +70,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt
|
||||
/// Validate GetXmlWithMaxCapacity
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetXmlWithMaxCapacityTest()
|
||||
public async Task GetXmlWithMaxCapacityTest()
|
||||
{
|
||||
DbDataReader reader;
|
||||
var storageReader = GetTestStorageDataReader(
|
||||
out reader,
|
||||
var storageReader = await GetTestStorageDataReader(
|
||||
"SELECT CAST('<xml>Test XML context</xml>' AS XML) As XmlColumn");
|
||||
DbDataReader reader = storageReader.DbDataReader;
|
||||
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
|
||||
Reference in New Issue
Block a user