diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs index 4090e3a4..819c6312 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs @@ -698,113 +698,122 @@ GO"; // Temporily commented out until a fix is pushed. /// - /// Get Definition for a object with no definition. Expect a error result + /// Get Definition for a object by putting the cursor on 3 different + /// objects /// - // [Fact] - // public async void GetDefinitionFromChildrenAndParents() - // { - // string queryString = "select * from master.sys.objects"; + [Fact] + public async void GetDefinitionFromChildrenAndParents() + { + string queryString = "select * from master.sys.objects"; - // // place the cursor on every token + // place the cursor on every token - // //cursor on objects - // TextDocumentPosition objectDocument = CreateTextDocPositionWithCursor(26, OwnerUri); - - // //cursor on sys - // TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri); - // LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(); - // ScriptFile scriptFile = connectionResult.ScriptFile; - // ConnectionInfo connInfo = connectionResult.ConnectionInfo; - // connInfo.RemoveAllConnections(); - // var bindingQueue = new ConnectedBindingQueue(); - // bindingQueue.AddConnectionContext(connInfo); - // scriptFile.Contents = queryString; + //cursor on objects + TextDocumentPosition objectDocument = CreateTextDocPositionWithCursor(26, OwnerUri); - // var service = new LanguageService(); - // service.BindingQueue = bindingQueue; - // await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo); - // Thread.Sleep(2000); + //cursor on sys + TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri); - // ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; - // scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo); - // service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo); + //cursor on master + TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(17, OwnerUri); - // // When I call the language service - // var objectResult = service.GetDefinition(objectDocument, scriptFile, connInfo); - // var sysResult = service.GetDefinition(sysDocument, scriptFile, connInfo); - // var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo); + LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(null, OwnerUri); + ScriptFile scriptFile = connectionResult.ScriptFile; + ConnectionInfo connInfo = connectionResult.ConnectionInfo; + connInfo.RemoveAllConnections(); + var bindingQueue = new ConnectedBindingQueue(); + bindingQueue.AddConnectionContext(connInfo); + scriptFile.Contents = queryString; - // // Then I expect the results to be non-null - // Assert.NotNull(objectResult); - // Assert.NotNull(sysResult); - // Assert.NotNull(masterResult); + var service = new LanguageService(); + service.RemoveScriptParseInfo(OwnerUri); + service.BindingQueue = bindingQueue; + await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo); + Thread.Sleep(2000); - // // And I expect the all results to be the same - // Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations)); - // Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations)); + ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; + service.ParseAndBind(scriptFile, connInfo); + scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo); + service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo); - // Cleanup(objectResult.Locations); - // Cleanup(sysResult.Locations); - // Cleanup(masterResult.Locations); - // service.ScriptParseInfoMap.Remove(OwnerUri); - // connInfo.RemoveAllConnections(); - // } + // When I call the language service + var objectResult = service.GetDefinition(objectDocument, scriptFile, connInfo); + var sysResult = service.GetDefinition(sysDocument, scriptFile, connInfo); + var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo); - // [Fact] - // public async void GetDefinitionFromProcedures() - // { + // Then I expect the results to be non-null + Assert.NotNull(objectResult); + Assert.NotNull(sysResult); + Assert.NotNull(masterResult); - // string queryString = "EXEC master.dbo.sp_MSrepl_startup"; + // And I expect the all results to be the same + Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations)); + Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations)); - // // place the cursor on every token + Cleanup(objectResult.Locations); + Cleanup(sysResult.Locations); + Cleanup(masterResult.Locations); + service.ScriptParseInfoMap.Remove(OwnerUri); + connInfo.RemoveAllConnections(); + } - // //cursor on objects - // TextDocumentPosition fnDocument = CreateTextDocPositionWithCursor(30, TestUri); + [Fact] + public async void GetDefinitionFromProcedures() + { - // //cursor on sys - // TextDocumentPosition dboDocument = CreateTextDocPositionWithCursor(14, TestUri); + string queryString = "EXEC master.dbo.sp_MSrepl_startup"; - // //cursor on master - // TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(10, TestUri); + // place the cursor on every token - // LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(); - // ScriptFile scriptFile = connectionResult.ScriptFile; - // ConnectionInfo connInfo = connectionResult.ConnectionInfo; - // connInfo.RemoveAllConnections(); - // var bindingQueue = new ConnectedBindingQueue(); - // bindingQueue.AddConnectionContext(connInfo); - // scriptFile.Contents = queryString; + //cursor on objects + TextDocumentPosition fnDocument = CreateTextDocPositionWithCursor(30, TestUri); - // var service = new LanguageService(); - // service.BindingQueue = bindingQueue; - // await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo); - // Thread.Sleep(2000); + //cursor on sys + TextDocumentPosition dboDocument = CreateTextDocPositionWithCursor(14, TestUri); - // ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; - // scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo); - // service.ScriptParseInfoMap.Add(TestUri, scriptInfo); + //cursor on master + TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(10, TestUri); - // // When I call the language service - // var fnResult = service.GetDefinition(fnDocument, scriptFile, connInfo); - // var sysResult = service.GetDefinition(dboDocument, scriptFile, connInfo); - // var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo); + LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(null, TestUri); + ScriptFile scriptFile = connectionResult.ScriptFile; + ConnectionInfo connInfo = connectionResult.ConnectionInfo; + connInfo.RemoveAllConnections(); + var bindingQueue = new ConnectedBindingQueue(); + bindingQueue.AddConnectionContext(connInfo); + scriptFile.Contents = queryString; - // // Then I expect the results to be non-null - // Assert.NotNull(fnResult); - // Assert.NotNull(sysResult); - // Assert.NotNull(masterResult); + var service = new LanguageService(); + service.RemoveScriptParseInfo(OwnerUri); + service.BindingQueue = bindingQueue; + await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo); + Thread.Sleep(2000); - // // And I expect the all results to be the same - // Assert.True(CompareLocations(fnResult.Locations, sysResult.Locations)); - // Assert.True(CompareLocations(fnResult.Locations, masterResult.Locations)); + ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; + service.ParseAndBind(scriptFile, connInfo); + scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo); + service.ScriptParseInfoMap.Add(TestUri, scriptInfo); - // Cleanup(fnResult.Locations); - // Cleanup(sysResult.Locations); - // Cleanup(masterResult.Locations); - // service.ScriptParseInfoMap.Remove(TestUri); - // connInfo.RemoveAllConnections(); - // } + // When I call the language service + var fnResult = service.GetDefinition(fnDocument, scriptFile, connInfo); + var sysResult = service.GetDefinition(dboDocument, scriptFile, connInfo); + var masterResult = service.GetDefinition(masterDocument, scriptFile, connInfo); + + // Then I expect the results to be non-null + Assert.NotNull(fnResult); + Assert.NotNull(sysResult); + Assert.NotNull(masterResult); + + // And I expect the all results to be the same + Assert.True(CompareLocations(fnResult.Locations, sysResult.Locations)); + Assert.True(CompareLocations(fnResult.Locations, masterResult.Locations)); + + Cleanup(fnResult.Locations); + Cleanup(sysResult.Locations); + Cleanup(masterResult.Locations); + service.ScriptParseInfoMap.Remove(TestUri); + connInfo.RemoveAllConnections(); + } /// diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs index c634c079..9ffaf18f 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Utility/LiveConnectionHelper.cs @@ -16,21 +16,27 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility { public class LiveConnectionHelper { - public static string GetTestSqlFile() + public static string GetTestSqlFile(string fileName = null) { - string filePath = Path.Combine( - Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - "sqltest.sql"); + string filePath = null; + if (string.IsNullOrEmpty(fileName)) + { + filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "sqltest.sql"); + } + else + { + filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), fileName + ".sql"); + } + if (File.Exists(filePath)) { File.Delete(filePath); } File.WriteAllText(filePath, "SELECT * FROM sys.objects\n"); return filePath; - } - public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null) + public static TestConnectionResult InitLiveConnectionInfo(string databaseName = null, string fileName = null) { string sqlFilePath = GetTestSqlFile(); ScriptFile scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(sqlFilePath);