mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 17:23:52 -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:
@@ -10,14 +10,13 @@ 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.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
@@ -29,7 +28,6 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
/// </summary>
|
||||
public class TestObjects
|
||||
{
|
||||
private static bool hasInitServices = false;
|
||||
public const string ScriptUri = "file://some/file.sql";
|
||||
|
||||
/// <summary>
|
||||
@@ -74,23 +72,10 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
{
|
||||
return new ConnectionDetails()
|
||||
{
|
||||
UserName = "sa",
|
||||
Password = "...",
|
||||
DatabaseName = "master",
|
||||
ServerName = "localhost"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a ConnectionDetails for connecting to localhost with integrated auth
|
||||
/// </summary>
|
||||
public static ConnectionDetails GetIntegratedTestConnectionDetails()
|
||||
{
|
||||
return new ConnectionDetails()
|
||||
{
|
||||
DatabaseName = "master",
|
||||
ServerName = "localhost",
|
||||
AuthenticationType = "Integrated"
|
||||
UserName = "user",
|
||||
Password = "password",
|
||||
DatabaseName = "databaseName",
|
||||
ServerName = "serverName"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -121,38 +106,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
return ConnectionService.Instance.ConnectionFactory;
|
||||
}
|
||||
|
||||
public static void InitializeTestServices()
|
||||
{
|
||||
if (TestObjects.hasInitServices)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TestObjects.hasInitServices = true;
|
||||
|
||||
const string hostName = "SQ Tools Test Service Host";
|
||||
const string hostProfileId = "SQLToolsTestService";
|
||||
Version hostVersion = new Version(1,0);
|
||||
|
||||
// set up the host details and profile paths
|
||||
var hostDetails = new HostDetails(hostName, hostProfileId, hostVersion);
|
||||
SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);
|
||||
|
||||
// Grab the instance of the service host
|
||||
ServiceHost serviceHost = ServiceHost.Instance;
|
||||
|
||||
// Start the service
|
||||
serviceHost.Start().Wait();
|
||||
|
||||
// Initialize the services that will be hosted here
|
||||
WorkspaceService<SqlToolsSettings>.Instance.InitializeService(serviceHost);
|
||||
LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext);
|
||||
ConnectionService.Instance.InitializeService(serviceHost);
|
||||
CredentialService.Instance.InitializeService(serviceHost);
|
||||
QueryExecutionService.Instance.InitializeService(serviceHost);
|
||||
|
||||
serviceHost.Initialize();
|
||||
}
|
||||
|
||||
|
||||
public static string GetTestSqlFile()
|
||||
{
|
||||
@@ -170,12 +124,14 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public static ConnectionInfo InitLiveConnectionInfo(out ScriptFile scriptFile)
|
||||
public static async Task<TestConnectionResult> InitLiveConnectionInfo()
|
||||
{
|
||||
TestObjects.InitializeTestServices();
|
||||
TestServiceProvider.InitializeTestServices();
|
||||
|
||||
string sqlFilePath = GetTestSqlFile();
|
||||
scriptFile = WorkspaceService<SqlToolsSettings>.Instance.Workspace.GetFile(sqlFilePath);
|
||||
string sqlFilePath = GetTestSqlFile();
|
||||
ScriptFile scriptFile = WorkspaceService<SqlToolsSettings>.Instance.Workspace.GetFile(sqlFilePath);
|
||||
TestConnectionProfileService connectionProfileService = new TestConnectionProfileService();
|
||||
ConnectParams connectParams = await connectionProfileService.GetConnectionParametersAsync();
|
||||
|
||||
string ownerUri = scriptFile.ClientFilePath;
|
||||
var connectionService = TestObjects.GetLiveTestConnectionService();
|
||||
@@ -184,19 +140,21 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
.Connect(new ConnectParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetIntegratedTestConnectionDetails()
|
||||
Connection = connectParams.Connection
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
return connInfo;
|
||||
return new TestConnectionResult () { ConnectionInfo = connInfo, ScriptFile = scriptFile };
|
||||
}
|
||||
|
||||
public static ConnectionInfo InitLiveConnectionInfoForDefinition()
|
||||
public static async Task<ConnectionInfo> InitLiveConnectionInfoForDefinition()
|
||||
{
|
||||
TestObjects.InitializeTestServices();
|
||||
TestServiceProvider.InitializeTestServices();
|
||||
TestConnectionProfileService connectionProfileService = new TestConnectionProfileService();
|
||||
ConnectParams connectParams = await connectionProfileService.GetConnectionParametersAsync();
|
||||
|
||||
string ownerUri = ScriptUri;
|
||||
var connectionService = TestObjects.GetLiveTestConnectionService();
|
||||
@@ -205,7 +163,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
.Connect(new ConnectParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetIntegratedTestConnectionDetails()
|
||||
Connection = connectParams.Connection
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
@@ -351,4 +309,13 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class TestConnectionResult
|
||||
{
|
||||
public ConnectionInfo ConnectionInfo { get; set; }
|
||||
|
||||
public ScriptFile ScriptFile { get; set; }
|
||||
|
||||
public TextDocumentPosition TextDocumentPosition { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user