mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-27 09:35:38 -05:00
Isolate Shared Test Code (#252)
The goal of this make sure that test code is correctly organized to ensure that test suites aren't dependent on each other.
* UnitTests get their own project now (renaming Microsoft.SqlTools.ServiceLayer.Test to Microsoft.SqlTools.ServiceLayer.UnitTests) which is about 90% of the changes to the files.
* IntegrationTests no longer depends on UnitTests, only Test.Common
* Any shared components from TestObjects that spins up a "live" connection has been moved to IntegrationTests Utility/LiveConnectionHelper.cs
* The dictionary-based mock file stream factory has been moved to Test.Common since it is used by UnitTests and IntegrationTests
* Added a overload that doesn't take a dictionary for when we don't care about monitoring the storage (about 90% of the time)
* The RunIf* wrapper methods have been moved to Test.Common
* OwnerUri and StandardQuery constants have been moved to Test.Common Constants file
* Updating to latest SDK version available at https://www.microsoft.com/net/core#windowscmd
* Moving unit tests to unit test folder
* Changing namespaces to UnitTests
* Moving some constants and shared functionality into common project, making the UnitTests reference it
* Unit tests are working!
* Integration tests are working
* Updating automated test runs
* Fixing one last broken unit test
* Exposing internals for other projects
* Moving edit data tests to UnitTest project
* Applying refactor fixes to unit tests
* Fixing flaky test that wasn't awaiting completion
This commit is contained in:
@@ -3,17 +3,14 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Xunit;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
{
|
||||
@@ -30,7 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
service.OwnerToConnectionMap.Clear();
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connectionInfo = result.ConnectionInfo;
|
||||
string uri = connectionInfo.OwnerUri;
|
||||
|
||||
@@ -39,8 +36,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
Assert.Equal(1, service.OwnerToConnectionMap.Count);
|
||||
|
||||
// If we run a query
|
||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
Query query = new Query(Common.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
Query query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
query.Execute();
|
||||
query.ExecutionTask.Wait();
|
||||
|
||||
@@ -48,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
Assert.Equal(2, connectionInfo.CountConnections);
|
||||
|
||||
// If we run another query
|
||||
query = new Query(Common.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
query.Execute();
|
||||
query.ExecutionTask.Wait();
|
||||
|
||||
@@ -69,7 +66,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
{
|
||||
// If we make a connection to a live database
|
||||
ConnectionService service = ConnectionService.Instance;
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connectionInfo = result.ConnectionInfo;
|
||||
ConnectionDetails details = connectionInfo.ConnectionDetails;
|
||||
string uri = connectionInfo.OwnerUri;
|
||||
@@ -78,8 +75,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
string changeDatabaseQuery = "use " + newDatabaseName;
|
||||
|
||||
// Then run any query to create a query DbConnection
|
||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
Query query = new Query(Common.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
Query query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
query.Execute();
|
||||
query.ExecutionTask.Wait();
|
||||
|
||||
|
||||
@@ -9,16 +9,11 @@ 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.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.ReliableConnectionHelper;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy;
|
||||
@@ -451,7 +446,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
[Fact]
|
||||
public void RetryPolicyFactoryConstructsPoliciesSuccessfully()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
RunIfWrapper.RunIfWindows(() =>
|
||||
{
|
||||
Assert.NotNull(RetryPolicyFactory.CreateColumnEncryptionTransferRetryPolicy());
|
||||
Assert.NotNull(RetryPolicyFactory.CreateDatabaseCommandRetryPolicy());
|
||||
@@ -539,7 +534,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
[Fact]
|
||||
public void TestTryGetServerVersionInvalidConnectionString()
|
||||
{
|
||||
TestUtils.RunIfWindows(() =>
|
||||
RunIfWrapper.RunIfWindows(() =>
|
||||
{
|
||||
ReliableConnectionHelper.ServerInfo info = null;
|
||||
Assert.False(ReliableConnectionHelper.TryGetServerVersion("this is not a valid connstr", out info));
|
||||
@@ -681,7 +676,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
[Fact]
|
||||
public void ReliableConnectionHelperTest()
|
||||
{
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
DbConnection connection = connInfo.ConnectionTypeToConnectionMap[ConnectionType.Default];
|
||||
|
||||
@@ -726,7 +721,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||
[Fact]
|
||||
public void InitReliableSqlConnectionTest()
|
||||
{
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
DbConnection dbConnection;
|
||||
connInfo.TryGetConnection(ConnectionType.Default, out dbConnection);
|
||||
|
||||
@@ -5,14 +5,11 @@
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
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;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
@@ -22,11 +19,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
/// </summary>
|
||||
public class LanguageServiceTests
|
||||
{
|
||||
private TestConnectionResult GetLiveAutoCompleteTestObjects()
|
||||
private LiveConnectionHelper.TestConnectionResult GetLiveAutoCompleteTestObjects()
|
||||
{
|
||||
var textDocument = new TextDocumentPosition
|
||||
{
|
||||
TextDocument = new TextDocumentIdentifier { Uri = TestObjects.ScriptUri },
|
||||
TextDocument = new TextDocumentIdentifier { Uri = Constants.OwnerUri },
|
||||
Position = new Position
|
||||
{
|
||||
Line = 0,
|
||||
@@ -34,7 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
}
|
||||
};
|
||||
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
result.TextDocumentPosition = textDocument;
|
||||
return result;
|
||||
}
|
||||
@@ -66,7 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
[Fact]
|
||||
public void PrepopulateCommonMetadata()
|
||||
{
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
var connInfo = result.ConnectionInfo;
|
||||
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||
@@ -104,7 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
{
|
||||
// When we make a connection to a live database
|
||||
Hosting.ServiceHost.SendEventIgnoreExceptions = true;
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
|
||||
// And we place the cursor after a function that should prompt for signature help
|
||||
string queryWithFunction = "EXEC sys.fn_isrolemember ";
|
||||
@@ -142,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||
[Fact]
|
||||
public void OverwriteBindingContext()
|
||||
{
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
|
||||
// add a new connection context
|
||||
var connectionKey = LanguageService.Instance.BindingQueue.AddConnectionContext(result.ConnectionInfo, overwrite: true);
|
||||
|
||||
@@ -6,14 +6,13 @@ using System;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using ConnectionType = Microsoft.SqlTools.ServiceLayer.Connection.ConnectionType;
|
||||
@@ -86,8 +85,8 @@ GO";
|
||||
public void GetValidTableDefinitionTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "spt_monitor";
|
||||
@@ -108,8 +107,8 @@ GO";
|
||||
public void GetTableDefinitionInvalidObjectTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "test_invalid";
|
||||
@@ -128,8 +127,8 @@ GO";
|
||||
public void GetTableDefinitionWithSchemaTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "spt_monitor";
|
||||
@@ -147,10 +146,10 @@ GO";
|
||||
/// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetUnsupportedDefinitionErrorTest()
|
||||
public void GetUnsupportedDefinitionErrorTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "objects";
|
||||
@@ -168,8 +167,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDefinitionWithNoResultsFoundError()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "from";
|
||||
@@ -226,7 +225,7 @@ GO";
|
||||
Character = 20
|
||||
}
|
||||
};
|
||||
TestConnectionResult connectionResult = TestObjects.InitLiveConnectionInfo();
|
||||
LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ScriptFile scriptFile = connectionResult.ScriptFile;
|
||||
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
||||
scriptFile.Contents = "select * from dbo.func ()";
|
||||
@@ -250,8 +249,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetValidViewDefinitionTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "objects";
|
||||
@@ -270,8 +269,8 @@ GO";
|
||||
public void GetViewDefinitionInvalidObjectTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "objects";
|
||||
@@ -289,8 +288,8 @@ GO";
|
||||
public void GetStoredProcedureDefinitionTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "sp_MSrepl_startup";
|
||||
@@ -310,8 +309,8 @@ GO";
|
||||
public void GetStoredProcedureDefinitionFailureTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "SP2";
|
||||
@@ -329,8 +328,8 @@ GO";
|
||||
public void GetStoredProcedureDefinitionWithoutSchemaTest()
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "sp_MSrepl_startup";
|
||||
@@ -369,8 +368,8 @@ GO";
|
||||
private void ValidatePeekTest(string databaseName, string objectName, string objectType, string schemaName, bool shouldReturnValidResult)
|
||||
{
|
||||
// Get live connectionInfo and serverConnection
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition(databaseName);
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition(databaseName);
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
|
||||
@@ -571,8 +570,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDefinitionUsingDeclarationTypeWithValidObjectTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "objects";
|
||||
@@ -593,8 +592,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDefinitionUsingDeclarationTypeWithNonexistentObjectTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "doesNotExist";
|
||||
@@ -612,8 +611,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDefinitionUsingQuickInfoTextWithValidObjectTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "objects";
|
||||
@@ -635,8 +634,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDefinitionUsingQuickInfoTextWithNonexistentObjectTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||
string objectName = "doesNotExist";
|
||||
@@ -656,8 +655,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDatabaseWithNoQueryConnectionTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
DbConnection connection;
|
||||
//Check if query connection is present
|
||||
Assert.False(connInfo.TryGetConnection(ConnectionType.Query, out connection));
|
||||
@@ -675,8 +674,8 @@ GO";
|
||||
[Fact]
|
||||
public void GetDatabaseWithQueryConnectionTest()
|
||||
{
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
//Mock a query connection object
|
||||
var mockQueryConnection = new Mock<DbConnection> { CallBase = true };
|
||||
mockQueryConnection.SetupGet(x => x.Database).Returns("testdb");
|
||||
|
||||
@@ -5,11 +5,9 @@
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataStorage
|
||||
@@ -18,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt
|
||||
{
|
||||
private StorageDataReader GetTestStorageDataReader(string query)
|
||||
{
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
DbConnection connection;
|
||||
result.ConnectionInfo.TryGetConnection(ConnectionType.Default, out connection);
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
@@ -22,9 +19,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
const string refactorText = "ROLLBACK TRANSACTION";
|
||||
|
||||
// Given a connection to a live database
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
|
||||
// If I run a "ROLLBACK TRANSACTION" query
|
||||
Query query = new Query(refactorText, connInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||
@@ -42,9 +39,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
const string rollbackText = "ROLLBACK TRANSACTION";
|
||||
|
||||
// Given a connection to a live database
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
|
||||
// If I run a "BEGIN TRANSACTION" query
|
||||
CreateAndExecuteQuery(beginText, connInfo, fileStreamFactory);
|
||||
@@ -61,9 +58,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
const string insertTempText = "INSERT INTO #someTempTable VALUES(1)";
|
||||
|
||||
// Given a connection to a live database
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
|
||||
// If I run a query creating a temp table
|
||||
CreateAndExecuteQuery(createTempText, connInfo, fileStreamFactory);
|
||||
@@ -81,12 +78,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||
const string useQuery = "USE {0}";
|
||||
|
||||
// Given a connection to a live database
|
||||
var result = TestObjects.InitLiveConnectionInfo();
|
||||
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||
DbConnection connection;
|
||||
connInfo.TryGetConnection(ConnectionType.Default, out connection);
|
||||
|
||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||
|
||||
// If I use master, the current database should be master
|
||||
CreateAndExecuteQuery(string.Format(useQuery, master), connInfo, fileStreamFactory);
|
||||
|
||||
@@ -10,8 +10,8 @@ using System.Data.SqlClient;
|
||||
using System.Threading;
|
||||
using Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.TSQLExecutionEngine
|
||||
@@ -46,7 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.TSQLExecutionEngine
|
||||
private SqlConnection SetUpConnection(string name)
|
||||
{
|
||||
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, name);
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition(testDb.DatabaseName);
|
||||
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition(testDb.DatabaseName);
|
||||
string connectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
|
||||
SqlConnection resultConnection = new SqlConnection(connectionString);
|
||||
resultConnection.Open();
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
{
|
||||
public class LiveConnectionHelper
|
||||
{
|
||||
public static string GetTestSqlFile()
|
||||
{
|
||||
string filePath = Path.Combine(
|
||||
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
|
||||
"sqltest.sql");
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
File.WriteAllText(filePath, "SELECT * FROM sys.objects\n");
|
||||
return filePath;
|
||||
|
||||
}
|
||||
|
||||
public static TestConnectionResult InitLiveConnectionInfo()
|
||||
{
|
||||
string sqlFilePath = GetTestSqlFile();
|
||||
ScriptFile scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(sqlFilePath);
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem);
|
||||
|
||||
string ownerUri = scriptFile.ClientFilePath;
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = connectParams.Connection
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
return new TestConnectionResult() { ConnectionInfo = connInfo, ScriptFile = scriptFile };
|
||||
}
|
||||
|
||||
public static ConnectionInfo InitLiveConnectionInfoForDefinition(string databaseName = null)
|
||||
{
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
const string ScriptUriTemplate = "file://some/{0}.sql";
|
||||
string ownerUri = string.Format(CultureInfo.InvariantCulture, ScriptUriTemplate, string.IsNullOrEmpty(databaseName) ? "file" : databaseName);
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = connectParams.Connection
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
|
||||
Assert.NotNull(connInfo);
|
||||
return connInfo;
|
||||
}
|
||||
|
||||
public static ServerConnection InitLiveServerConnectionForDefinition(ConnectionInfo connInfo)
|
||||
{
|
||||
SqlConnection sqlConn = new SqlConnection(ConnectionService.BuildConnectionString(connInfo.ConnectionDetails));
|
||||
return new ServerConnection(sqlConn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a test sql connection factory instance
|
||||
/// </summary>
|
||||
public static ISqlConnectionFactory GetLiveTestSqlConnectionFactory()
|
||||
{
|
||||
// connect to a real server instance
|
||||
return ConnectionService.Instance.ConnectionFactory;
|
||||
}
|
||||
|
||||
public static ConnectionService GetLiveTestConnectionService()
|
||||
{
|
||||
// connect to a real server instance
|
||||
return ConnectionService.Instance;
|
||||
}
|
||||
|
||||
public class TestConnectionResult
|
||||
{
|
||||
public ConnectionInfo ConnectionInfo { get; set; }
|
||||
|
||||
public ScriptFile ScriptFile { get; set; }
|
||||
|
||||
public TextDocumentPosition TextDocumentPosition { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@
|
||||
"target": "project"
|
||||
},
|
||||
"Moq": "4.6.36-alpha",
|
||||
"Microsoft.SqlTools.ServiceLayer.Test": "1.0.0-*"
|
||||
"Microsoft.SqlTools.ServiceLayer.Test.Common": "1.0.0-*"
|
||||
},
|
||||
"testRunner": "xunit",
|
||||
"frameworks": {
|
||||
|
||||
Reference in New Issue
Block a user