diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/RetryPolicy.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/RetryPolicy.cs index a2eb03fe..23159d3e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/RetryPolicy.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ReliableConnection/RetryPolicy.cs @@ -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; } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index 10ac39cc..efaa4135 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -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 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); } /// diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/AssemblyInfo.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/AssemblyInfo.cs new file mode 100644 index 00000000..70421c18 --- /dev/null +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/AssemblyInfo.cs @@ -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)] diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs index 24a2f39c..18867612 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs @@ -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 /// 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); + } + /// /// Environment variable that stores the name of the test server hosting the SQL Server instance. /// @@ -338,6 +444,90 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection Assert.NotEmpty(info.ServerVersion); }); } + + + /// + /// Validate ambient static settings + /// + [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); + } + } + + /// + /// Validate ambient settings populate + /// + [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 settings = new Dictionary(); + settings.Add("LockTimeoutMilliSeconds", 10000); + data.PopulateSettings(settings); + data.TraceSettings(); + } } } #endif // LIVE_CONNECTION_TESTS diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs index 6790efbb..bc976498 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs @@ -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.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.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 diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/DataStorage/StorageDataReaderTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/DataStorage/StorageDataReaderTests.cs new file mode 100644 index 00000000..9ba5c0b9 --- /dev/null +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/DataStorage/StorageDataReaderTests.cs @@ -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); + } + + /// + /// Validate GetBytesWithMaxCapacity + /// + [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); + } + + /// + /// Validate GetCharsWithMaxCapacity + /// + [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); + } + + /// + /// Validate GetXmlWithMaxCapacity + /// + [Fact] + public void GetXmlWithMaxCapacityTest() + { + DbDataReader reader; + var storageReader = GetTestStorageDataReader( + out reader, + "SELECT CAST('Test XML context' AS XML) As XmlColumn"); + + reader.Read(); + Assert.False(storageReader.IsDBNull(0)); + + string shortXml = storageReader.GetXmlWithMaxCapacity(0, 2); + Assert.True(shortXml.Length == 3); + } + } +} + +#endif \ No newline at end of file diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs index 36db2994..01707778 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs @@ -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 /// public class TestObjects { + private static bool hasInitServices = false; public const string ScriptUri = "file://some/file.sql"; /// @@ -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.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.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; + } } /// diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/ConnectionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/ConnectionTests.cs index 171649d3..8a6f3f95 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/ConnectionTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/ConnectionTests.cs @@ -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 /// /// Try to connect with invalid credentials /// - //[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(); + } + } + + /// + /// Validate list databases request + /// + [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 diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs index 5480db11..48d4c118 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/LanguageServiceTests.cs @@ -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 /// public class LanguageServiceTests : TestBase { + /// /// Validate hover tooltip scenarios /// @@ -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(); } } + + /// + /// Validate the configuration change event + /// + [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 configParams = new DidChangeConfigurationParams() + { + Settings = settings + }; + + await RequestChangeConfigurationNotification(configParams); + + Thread.Sleep(2000); + + await Disconnect(ownerUri); + } + finally + { + WaitForExit(); + } + } + } } diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/QueryExecutionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/QueryExecutionTests.cs index d6d3113c..05146a05 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/QueryExecutionTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/QueryExecutionTests.cs @@ -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 diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs index 7681b429..f6d10b33 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs @@ -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 /// /// True if the connection completed successfully - protected async Task Connect(string ownerUri, ConnectParams connectParams) + protected async Task 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; } + /// + /// Request a cancel connect + /// + protected async Task CancelConnect(string ownerUri) + { + var cancelParams = new CancelConnectParams(); + cancelParams.OwnerUri = ownerUri; + + return await Driver.SendRequest(CancelConnectRequest.Type, cancelParams); + } + + /// + /// Request a cancel connect + /// + protected async Task ListDatabases(string ownerUri) + { + var listParams = new ListDatabasesParams(); + listParams.OwnerUri = ownerUri; + + return await Driver.SendRequest(ListDatabasesRequest.Type, listParams); + } + + /// + /// Request the active SQL script is parsed for errors + /// + protected async Task RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams) + { + return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams); + } + /// /// Request the active SQL script is parsed for errors /// @@ -108,6 +139,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams); } + /// + /// Request a configuration change notification + /// + protected async Task RequestChangeConfigurationNotification(DidChangeConfigurationParams configParams) + { + await Driver.SendEvent(DidChangeConfigurationNotification.Type, configParams); + } + /// /// /// Request the active SQL script is parsed for errors ///