mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 01:25:42 -05:00
Add more test cases for code coverage (#127)
Next round of code coverage test cases. Please review the commit for next iteration. * Add connection retry tests * More test coverage * Update diagnostics end-to-end test
This commit is contained in:
@@ -533,7 +533,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||
return new RetryStateEx { TotalRetryTime = TimeSpan.Zero };
|
||||
}
|
||||
|
||||
private sealed class RetryStateEx : RetryState
|
||||
internal sealed class RetryStateEx : RetryState
|
||||
{
|
||||
public TimeSpan TotalRetryTime { get; set; }
|
||||
}
|
||||
|
||||
@@ -196,11 +196,14 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
public void InitializeService(ServiceHost serviceHost, SqlToolsContext context)
|
||||
{
|
||||
// Register the requests that this service will handle
|
||||
serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest);
|
||||
serviceHost.SetRequestHandler(ReferencesRequest.Type, HandleReferencesRequest);
|
||||
|
||||
// turn off until needed (10/28/2016)
|
||||
// serviceHost.SetRequestHandler(DefinitionRequest.Type, HandleDefinitionRequest);
|
||||
// serviceHost.SetRequestHandler(ReferencesRequest.Type, HandleReferencesRequest);
|
||||
// serviceHost.SetRequestHandler(SignatureHelpRequest.Type, HandleSignatureHelpRequest);
|
||||
// serviceHost.SetRequestHandler(DocumentHighlightRequest.Type, HandleDocumentHighlightRequest);
|
||||
|
||||
serviceHost.SetRequestHandler(CompletionResolveRequest.Type, HandleCompletionResolveRequest);
|
||||
serviceHost.SetRequestHandler(SignatureHelpRequest.Type, HandleSignatureHelpRequest);
|
||||
serviceHost.SetRequestHandler(DocumentHighlightRequest.Type, HandleDocumentHighlightRequest);
|
||||
serviceHost.SetRequestHandler(HoverRequest.Type, HandleHoverRequest);
|
||||
serviceHost.SetRequestHandler(CompletionRequest.Type, HandleCompletionRequest);
|
||||
|
||||
@@ -290,6 +293,8 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
}
|
||||
}
|
||||
|
||||
// turn off this code until needed (10/28/2016)
|
||||
#if false
|
||||
private static async Task HandleDefinitionRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<Location[]> requestContext)
|
||||
@@ -317,6 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
{
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
private static async Task HandleHoverRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
@@ -361,7 +367,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
eventContext);
|
||||
}
|
||||
|
||||
await Task.FromResult(true);
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Xunit;
|
||||
|
||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||
@@ -6,12 +6,15 @@
|
||||
#if LIVE_CONNECTION_TESTS
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Xunit;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy.TimeBasedRetryPolicy;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
{
|
||||
@@ -21,6 +24,109 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
/// </summary>
|
||||
public class ReliableConnectionTests
|
||||
{
|
||||
internal class TestFixedDelayPolicy : FixedDelayPolicy
|
||||
{
|
||||
public TestFixedDelayPolicy(
|
||||
IErrorDetectionStrategy strategy,
|
||||
int maxRetryCount,
|
||||
TimeSpan intervalBetweenRetries)
|
||||
: base(strategy,
|
||||
maxRetryCount,
|
||||
intervalBetweenRetries)
|
||||
{
|
||||
}
|
||||
|
||||
public bool InvokeShouldRetryImpl(RetryState retryStateObj)
|
||||
{
|
||||
return ShouldRetryImpl(retryStateObj);
|
||||
}
|
||||
}
|
||||
|
||||
internal class TestProgressiveRetryPolicy : ProgressiveRetryPolicy
|
||||
{
|
||||
public TestProgressiveRetryPolicy(
|
||||
IErrorDetectionStrategy strategy,
|
||||
int maxRetryCount,
|
||||
TimeSpan initialInterval,
|
||||
TimeSpan increment)
|
||||
: base(strategy,
|
||||
maxRetryCount,
|
||||
initialInterval,
|
||||
increment)
|
||||
{
|
||||
}
|
||||
|
||||
public bool InvokeShouldRetryImpl(RetryState retryStateObj)
|
||||
{
|
||||
return ShouldRetryImpl(retryStateObj);
|
||||
}
|
||||
}
|
||||
|
||||
internal class TestTimeBasedRetryPolicy : TimeBasedRetryPolicy
|
||||
{
|
||||
public TestTimeBasedRetryPolicy(
|
||||
IErrorDetectionStrategy strategy,
|
||||
TimeSpan minTotalRetryTimeLimit,
|
||||
TimeSpan maxTotalRetryTimeLimit,
|
||||
double totalRetryTimeLimitRate,
|
||||
TimeSpan minInterval,
|
||||
TimeSpan maxInterval,
|
||||
double intervalFactor)
|
||||
: base(
|
||||
strategy,
|
||||
minTotalRetryTimeLimit,
|
||||
maxTotalRetryTimeLimit,
|
||||
totalRetryTimeLimitRate,
|
||||
minInterval,
|
||||
maxInterval,
|
||||
intervalFactor)
|
||||
{
|
||||
}
|
||||
|
||||
public bool InvokeShouldRetryImpl(RetryState retryStateObj)
|
||||
{
|
||||
return ShouldRetryImpl(retryStateObj);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FixedDelayPolicyTest()
|
||||
{
|
||||
TestFixedDelayPolicy policy = new TestFixedDelayPolicy(
|
||||
strategy: new NetworkConnectivityErrorDetectionStrategy(),
|
||||
maxRetryCount: 3,
|
||||
intervalBetweenRetries: TimeSpan.FromMilliseconds(100));
|
||||
bool shouldRety = policy.InvokeShouldRetryImpl(new RetryStateEx());
|
||||
Assert.True(shouldRety);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProgressiveRetryPolicyTest()
|
||||
{
|
||||
TestProgressiveRetryPolicy policy = new TestProgressiveRetryPolicy(
|
||||
strategy: new NetworkConnectivityErrorDetectionStrategy(),
|
||||
maxRetryCount: 3,
|
||||
initialInterval: TimeSpan.FromMilliseconds(100),
|
||||
increment: TimeSpan.FromMilliseconds(100));
|
||||
bool shouldRety = policy.InvokeShouldRetryImpl(new RetryStateEx());
|
||||
Assert.True(shouldRety);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeBasedRetryPolicyTest()
|
||||
{
|
||||
TestTimeBasedRetryPolicy policy = new TestTimeBasedRetryPolicy(
|
||||
strategy: new NetworkConnectivityErrorDetectionStrategy(),
|
||||
minTotalRetryTimeLimit: TimeSpan.FromMilliseconds(100),
|
||||
maxTotalRetryTimeLimit: TimeSpan.FromMilliseconds(100),
|
||||
totalRetryTimeLimitRate: 100,
|
||||
minInterval: TimeSpan.FromMilliseconds(100),
|
||||
maxInterval: TimeSpan.FromMilliseconds(100),
|
||||
intervalFactor: 1);
|
||||
bool shouldRety = policy.InvokeShouldRetryImpl(new RetryStateEx());
|
||||
Assert.True(shouldRety);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Environment variable that stores the name of the test server hosting the SQL Server instance.
|
||||
/// </summary>
|
||||
@@ -338,6 +444,90 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
Assert.NotEmpty(info.ServerVersion);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validate ambient static settings
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AmbientSettingsStaticPropertiesTest()
|
||||
{
|
||||
var defaultSettings = AmbientSettings.DefaultSettings;
|
||||
Assert.NotNull(defaultSettings);
|
||||
var masterReferenceFilePath = AmbientSettings.MasterReferenceFilePath;
|
||||
var maxDataReaderDegreeOfParallelism = AmbientSettings.MaxDataReaderDegreeOfParallelism;
|
||||
var tableProgressUpdateInterval = AmbientSettings.TableProgressUpdateInterval;
|
||||
var traceRowCountFailure = AmbientSettings.TraceRowCountFailure;
|
||||
var useOfflineDataReader = AmbientSettings.UseOfflineDataReader;
|
||||
var streamBackingStoreForOfflineDataReading = AmbientSettings.StreamBackingStoreForOfflineDataReading;
|
||||
var disableIndexesForDataPhase = AmbientSettings.DisableIndexesForDataPhase;
|
||||
var reliableDdlEnabled = AmbientSettings.ReliableDdlEnabled;
|
||||
var importModelDatabase = AmbientSettings.ImportModelDatabase;
|
||||
var supportAlwaysEncrypted = AmbientSettings.SupportAlwaysEncrypted;
|
||||
var alwaysEncryptedWizardMigration = AmbientSettings.AlwaysEncryptedWizardMigration;
|
||||
var skipObjectTypeBlocking =AmbientSettings.SkipObjectTypeBlocking;
|
||||
var doNotSerializeQueryStoreSettings = AmbientSettings.DoNotSerializeQueryStoreSettings;
|
||||
var lockTimeoutMilliSeconds = AmbientSettings.LockTimeoutMilliSeconds;
|
||||
var queryTimeoutSeconds = AmbientSettings.QueryTimeoutSeconds;
|
||||
var longRunningQueryTimeoutSeconds = AmbientSettings.LongRunningQueryTimeoutSeconds;
|
||||
var alwaysRetryOnTransientFailure = AmbientSettings.AlwaysRetryOnTransientFailure;
|
||||
var connectionRetryMessageHandler = AmbientSettings.ConnectionRetryMessageHandler;
|
||||
|
||||
using (var settingsContext = AmbientSettings.CreateSettingsContext())
|
||||
{
|
||||
var settings = settingsContext.Settings;
|
||||
Assert.NotNull(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate ambient settings populate
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AmbientSettingsPopulateTest()
|
||||
{
|
||||
var data = new AmbientSettings.AmbientData();
|
||||
|
||||
var masterReferenceFilePath = data.MasterReferenceFilePath;
|
||||
data.MasterReferenceFilePath = masterReferenceFilePath;
|
||||
var lockTimeoutMilliSeconds = data.LockTimeoutMilliSeconds;
|
||||
data.LockTimeoutMilliSeconds = lockTimeoutMilliSeconds;
|
||||
var queryTimeoutSeconds = data.QueryTimeoutSeconds;
|
||||
data.QueryTimeoutSeconds = queryTimeoutSeconds;
|
||||
var longRunningQueryTimeoutSeconds = data.LongRunningQueryTimeoutSeconds;
|
||||
data.LongRunningQueryTimeoutSeconds = longRunningQueryTimeoutSeconds;
|
||||
var alwaysRetryOnTransientFailure = data.AlwaysRetryOnTransientFailure;
|
||||
data.AlwaysRetryOnTransientFailure = alwaysRetryOnTransientFailure;
|
||||
var connectionRetryMessageHandler = data.ConnectionRetryMessageHandler;
|
||||
data.ConnectionRetryMessageHandler = connectionRetryMessageHandler;
|
||||
var traceRowCountFailure = data.TraceRowCountFailure;
|
||||
data.TraceRowCountFailure = traceRowCountFailure;
|
||||
var tableProgressUpdateInterval = data.TableProgressUpdateInterval;
|
||||
data.TableProgressUpdateInterval = tableProgressUpdateInterval;
|
||||
var useOfflineDataReader = data.UseOfflineDataReader;
|
||||
data.UseOfflineDataReader = useOfflineDataReader;
|
||||
var streamBackingStoreForOfflineDataReading = data.StreamBackingStoreForOfflineDataReading;
|
||||
data.StreamBackingStoreForOfflineDataReading = streamBackingStoreForOfflineDataReading;
|
||||
var disableIndexesForDataPhase = data.DisableIndexesForDataPhase;
|
||||
data.DisableIndexesForDataPhase = disableIndexesForDataPhase;
|
||||
var reliableDdlEnabled = data.ReliableDdlEnabled;
|
||||
data.ReliableDdlEnabled = reliableDdlEnabled;
|
||||
var importModelDatabase = data.ImportModelDatabase;
|
||||
data.ImportModelDatabase = importModelDatabase;
|
||||
var supportAlwaysEncrypted = data.SupportAlwaysEncrypted;
|
||||
data.SupportAlwaysEncrypted = supportAlwaysEncrypted;
|
||||
var alwaysEncryptedWizardMigration = data.AlwaysEncryptedWizardMigration;
|
||||
data.AlwaysEncryptedWizardMigration = alwaysEncryptedWizardMigration;
|
||||
var skipObjectTypeBlocking = data.SkipObjectTypeBlocking;
|
||||
data.SkipObjectTypeBlocking = skipObjectTypeBlocking;
|
||||
var doNotSerializeQueryStoreSettings = data.DoNotSerializeQueryStoreSettings;
|
||||
data.DoNotSerializeQueryStoreSettings = doNotSerializeQueryStoreSettings;
|
||||
|
||||
Dictionary<string, object> settings = new Dictionary<string, object>();
|
||||
settings.Add("LockTimeoutMilliSeconds", 10000);
|
||||
data.PopulateSettings(settings);
|
||||
data.TraceSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // LIVE_CONNECTION_TESTS
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
{
|
||||
try
|
||||
{
|
||||
InitializeTestServices();
|
||||
TestObjects.InitializeTestServices();
|
||||
}
|
||||
catch (System.ArgumentException)
|
||||
{
|
||||
@@ -175,26 +175,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
[Fact]
|
||||
public void PrepopulateCommonMetadata()
|
||||
{
|
||||
InitializeTestServices();
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
|
||||
string sqlFilePath = GetTestSqlFile();
|
||||
ScriptFile scriptFile = WorkspaceService<SqlToolsSettings>.Instance.Workspace.GetFile(sqlFilePath);
|
||||
|
||||
string ownerUri = scriptFile.ClientFilePath;
|
||||
var connectionService = TestObjects.GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetIntegratedTestConnectionDetails()
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
|
||||
ScriptParseInfo scriptInfo = new ScriptParseInfo();
|
||||
scriptInfo.IsConnected = true;
|
||||
|
||||
@@ -226,48 +209,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
|
||||
#endif
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private void InitializeTestServices()
|
||||
{
|
||||
const string hostName = "SQL Tools Service Host";
|
||||
const string hostProfileId = "SQLToolsService";
|
||||
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
|
||||
Hosting.ServiceHost serviceHost = Hosting.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();
|
||||
}
|
||||
|
||||
private Hosting.ServiceHost GetTestServiceHost()
|
||||
{
|
||||
// set up the host details and profile paths
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
#if LIVE_CONNECTION_TESTS
|
||||
|
||||
using System.Data.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
||||
{
|
||||
public class StorageDataReaderTests
|
||||
{
|
||||
private StorageDataReader GetTestStorageDataReader(out DbDataReader reader, string query)
|
||||
{
|
||||
ScriptFile scriptFile;
|
||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
|
||||
|
||||
var command = connInfo.SqlConnection.CreateCommand();
|
||||
command.CommandText = query;
|
||||
reader = command.ExecuteReader();
|
||||
|
||||
return new StorageDataReader(reader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate GetBytesWithMaxCapacity
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetBytesWithMaxCapacityTest()
|
||||
{
|
||||
DbDataReader reader;
|
||||
var storageReader = GetTestStorageDataReader(
|
||||
out reader,
|
||||
"SELECT CAST([name] as TEXT) As TextName FROM sys.all_columns");
|
||||
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
|
||||
byte[] bytes = storageReader.GetBytesWithMaxCapacity(0, 100);
|
||||
Assert.NotNull(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate GetCharsWithMaxCapacity
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetCharsWithMaxCapacityTest()
|
||||
{
|
||||
DbDataReader reader;
|
||||
var storageReader = GetTestStorageDataReader(
|
||||
out reader,
|
||||
"SELECT name FROM sys.all_columns");
|
||||
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
|
||||
string shortName = storageReader.GetCharsWithMaxCapacity(0, 2);
|
||||
Assert.True(shortName.Length == 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate GetXmlWithMaxCapacity
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetXmlWithMaxCapacityTest()
|
||||
{
|
||||
DbDataReader reader;
|
||||
var storageReader = GetTestStorageDataReader(
|
||||
out reader,
|
||||
"SELECT CAST('<xml>Test XML context</xml>' AS XML) As XmlColumn");
|
||||
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
|
||||
string shortXml = storageReader.GetXmlWithMaxCapacity(0, 2);
|
||||
Assert.True(shortXml.Length == 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -7,10 +7,18 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
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.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.Test.Utility
|
||||
{
|
||||
@@ -19,6 +27,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
/// </summary>
|
||||
public class TestObjects
|
||||
{
|
||||
private static bool hasInitServices = false;
|
||||
public const string ScriptUri = "file://some/file.sql";
|
||||
|
||||
/// <summary>
|
||||
@@ -109,6 +118,79 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
// connect to a real server instance
|
||||
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()
|
||||
{
|
||||
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 ConnectionInfo InitLiveConnectionInfo(out ScriptFile scriptFile)
|
||||
{
|
||||
TestObjects.InitializeTestServices();
|
||||
|
||||
string sqlFilePath = GetTestSqlFile();
|
||||
scriptFile = WorkspaceService<SqlToolsSettings>.Instance.Workspace.GetFile(sqlFilePath);
|
||||
|
||||
string ownerUri = scriptFile.ClientFilePath;
|
||||
var connectionService = TestObjects.GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetIntegratedTestConnectionDetails()
|
||||
});
|
||||
|
||||
connectionResult.Wait();
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
return connInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,15 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
@@ -24,15 +18,44 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
/// <summary>
|
||||
/// Try to connect with invalid credentials
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
[Fact]
|
||||
public async Task InvalidConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
string ownerUri = System.IO.Path.GetTempFileName();
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.InvalidConnection);
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.InvalidConnection, 300000);
|
||||
Assert.False(connected, "Invalid connection is failed to connect");
|
||||
|
||||
await Connect(ownerUri, ConnectionTestUtils.InvalidConnection, 300000);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
await CancelConnect(ownerUri);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate list databases request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ListDatabasesTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
string ownerUri = System.IO.Path.GetTempFileName();
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection successful");
|
||||
|
||||
var listDatabaseResult = await ListDatabases(ownerUri);
|
||||
Assert.True(listDatabaseResult.DatabaseNames.Length > 0);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
@@ -21,6 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
/// </summary>
|
||||
public class LanguageServiceTests : TestBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Validate hover tooltip scenarios
|
||||
/// </summary>
|
||||
@@ -168,7 +170,74 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
|
||||
await RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(5000);
|
||||
Thread.Sleep(100);
|
||||
|
||||
var contentChanges = new TextDocumentChangeEvent[1];
|
||||
contentChanges[0] = new TextDocumentChangeEvent()
|
||||
{
|
||||
Range = new Range()
|
||||
{
|
||||
Start = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = 5
|
||||
},
|
||||
End = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = 6
|
||||
}
|
||||
},
|
||||
RangeLength = 1,
|
||||
Text = "z"
|
||||
};
|
||||
|
||||
DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams()
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier()
|
||||
{
|
||||
Version = 2,
|
||||
Uri = ownerUri
|
||||
}
|
||||
};
|
||||
|
||||
await RequestChangeTextDocumentNotification(changeParams);
|
||||
|
||||
Thread.Sleep(100);
|
||||
|
||||
contentChanges[0] = new TextDocumentChangeEvent()
|
||||
{
|
||||
Range = new Range()
|
||||
{
|
||||
Start = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = 5
|
||||
},
|
||||
End = new Position()
|
||||
{
|
||||
Line = 0,
|
||||
Character = 6
|
||||
}
|
||||
},
|
||||
RangeLength = 1,
|
||||
Text = "t"
|
||||
};
|
||||
|
||||
changeParams = new DidChangeTextDocumentParams()
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier()
|
||||
{
|
||||
Version = 3,
|
||||
Uri = ownerUri
|
||||
}
|
||||
};
|
||||
|
||||
await RequestChangeTextDocumentNotification(changeParams);
|
||||
|
||||
Thread.Sleep(2500);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
@@ -177,5 +246,39 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the configuration change event
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ChangeConfigurationTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
string ownerUri = System.IO.Path.GetTempFileName();
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
var settings = new SqlToolsSettings();
|
||||
settings.SqlTools.IntelliSense.EnableIntellisense = false;
|
||||
DidChangeConfigurationParams<SqlToolsSettings> configParams = new DidChangeConfigurationParams<SqlToolsSettings>()
|
||||
{
|
||||
Settings = settings
|
||||
};
|
||||
|
||||
await RequestChangeConfigurationNotification(configParams);
|
||||
|
||||
Thread.Sleep(2000);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
@@ -28,7 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
string query = "SELECT * FROM sys.objects";
|
||||
string query = "SELECT * FROM sys.all_columns c";
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||
{
|
||||
@@ -48,6 +49,27 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.NotNull(queryResult.BatchSummaries);
|
||||
|
||||
foreach (var batchSummary in queryResult.BatchSummaries)
|
||||
{
|
||||
foreach (var resultSetSummary in batchSummary.ResultSetSummaries)
|
||||
{
|
||||
Assert.True(resultSetSummary.RowCount > 0);
|
||||
}
|
||||
}
|
||||
|
||||
var subsetRequest = new QueryExecuteSubsetParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
BatchIndex = 0,
|
||||
ResultSetIndex = 0,
|
||||
RowsStartIndex = 0,
|
||||
RowsCount = 100,
|
||||
};
|
||||
|
||||
var querySubset = await RequestQueryExecuteSubset(subsetRequest);
|
||||
Assert.NotNull(querySubset);
|
||||
Assert.True(querySubset.ResultSubset.RowCount == 100);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
|
||||
@@ -73,13 +74,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
/// Request a new connection to be created
|
||||
/// </summary>
|
||||
/// <returns>True if the connection completed successfully</returns>
|
||||
protected async Task<bool> Connect(string ownerUri, ConnectParams connectParams)
|
||||
protected async Task<bool> Connect(string ownerUri, ConnectParams connectParams, int timeout = 15000)
|
||||
{
|
||||
connectParams.OwnerUri = ownerUri;
|
||||
var connectResult = await Driver.SendRequest(ConnectionRequest.Type, connectParams);
|
||||
if (connectResult)
|
||||
{
|
||||
var completeEvent = await Driver.WaitForEvent(ConnectionCompleteNotification.Type);
|
||||
var completeEvent = await Driver.WaitForEvent(ConnectionCompleteNotification.Type, timeout);
|
||||
return !string.IsNullOrEmpty(completeEvent.ConnectionId);
|
||||
}
|
||||
else
|
||||
@@ -100,6 +101,36 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
return disconnectResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
protected async Task<bool> CancelConnect(string ownerUri)
|
||||
{
|
||||
var cancelParams = new CancelConnectParams();
|
||||
cancelParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(CancelConnectRequest.Type, cancelParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
protected async Task<ListDatabasesResponse> ListDatabases(string ownerUri)
|
||||
{
|
||||
var listParams = new ListDatabasesParams();
|
||||
listParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(ListDatabasesRequest.Type, listParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
protected async Task<QueryExecuteSubsetResult> RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams)
|
||||
{
|
||||
return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
@@ -108,6 +139,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a configuration change notification
|
||||
/// </summary>
|
||||
protected async Task RequestChangeConfigurationNotification(DidChangeConfigurationParams<SqlToolsSettings> configParams)
|
||||
{
|
||||
await Driver.SendEvent(DidChangeConfigurationNotification<SqlToolsSettings>.Type, configParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user