public async void GetDefinitionFromChildrenAndParents() { string queryString = "select * from master.sys.objects"; // place the cursor on every token //cursor on objects TextDocumentPosition objectDocument = CreateTextDocPositionWithCursor(26, OwnerUri); //cursor on sys TextDocumentPosition sysDocument = CreateTextDocPositionWithCursor(22, OwnerUri); //cursor on master TextDocumentPosition masterDocument = CreateTextDocPositionWithCursor(17, OwnerUri); LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo(null); ScriptFile scriptFile = connectionResult.ScriptFile; ConnectionInfo connInfo = connectionResult.ConnectionInfo; connInfo.RemoveAllConnections(); var bindingQueue = new ConnectedBindingQueue(); bindingQueue.AddConnectionContext(connInfo); scriptFile.Contents = queryString; var service = new LanguageService(); service.RemoveScriptParseInfo(OwnerUri); service.BindingQueue = bindingQueue; await service.UpdateLanguageServiceOnConnection(connectionResult.ConnectionInfo); Thread.Sleep(2000); ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; service.ParseAndBind(scriptFile, connInfo); scriptInfo.ConnectionKey = bindingQueue.AddConnectionContext(connInfo); service.ScriptParseInfoMap.Add(OwnerUri, scriptInfo); // 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); // Then I expect the results to be non-null Assert.NotNull(objectResult); Assert.NotNull(sysResult); Assert.NotNull(masterResult); // And I expect the all results to be the same Assert.True(CompareLocations(objectResult.Locations, sysResult.Locations)); Assert.True(CompareLocations(objectResult.Locations, masterResult.Locations)); Cleanup(objectResult.Locations); Cleanup(sysResult.Locations); Cleanup(masterResult.Locations); service.ScriptParseInfoMap.Remove(OwnerUri); connInfo.RemoveAllConnections(); }
public ObjectExplorerServiceTests() { connectionServiceMock = new Mock <ConnectionService>(); serviceHostMock = new Mock <IProtocolEndpoint>(); service = CreateOEService(connectionServiceMock.Object); connectionServiceMock.Setup(x => x.RegisterConnectedQueue(It.IsAny <string>(), It.IsAny <IConnectedBindingQueue>())); service.InitializeService(serviceHostMock.Object); ConnectedBindingContext connectedBindingContext = new ConnectedBindingContext(); connectedBindingContext.ServerConnection = new ServerConnection(new SqlConnection(fakeConnectionString)); connectedBindingQueue = new ConnectedBindingQueue(false); connectedBindingQueue.BindingContextMap.Add($"{details.ServerName}_{details.DatabaseName}_{details.UserName}_NULL", connectedBindingContext); service.ConnectedBindingQueue = connectedBindingQueue; }
private string LookupUriFromQueueKey(string queueKey) { foreach (var session in this.sessionMap.Values) { var connInfo = session.ConnectionInfo; if (connInfo != null) { string currentKey = ConnectedBindingQueue.GetConnectionContextKey(connInfo.ConnectionDetails); if (queueKey == currentKey) { return(session.Uri); } } } return(string.Empty); }
// Disable flaky test (mairvine - 3/15/2018) // [Fact] public void CompletionItemsShouldCreatedUsingSqlParserIfTheProcessDoesNotTimeout() { ConnectedBindingQueue bindingQueue = new ConnectedBindingQueue(); ScriptDocumentInfo docInfo = CreateScriptDocumentInfo(); CompletionService completionService = new CompletionService(bindingQueue); ConnectionInfo connectionInfo = new ConnectionInfo(null, null, null); bool useLowerCaseSuggestions = true; CompletionItem[] defaultCompletionList = AutoCompleteHelper.GetDefaultCompletionItems(docInfo, useLowerCaseSuggestions); List <Declaration> declarations = new List <Declaration>(); var sqlParserWrapper = new Mock <ISqlParserWrapper>(); sqlParserWrapper.Setup(x => x.FindCompletions(docInfo.ScriptParseInfo.ParseResult, docInfo.ParserLine, docInfo.ParserColumn, It.IsAny <IMetadataDisplayInfoProvider>())).Returns(declarations); completionService.SqlParserWrapper = sqlParserWrapper.Object; AutoCompletionResult result = completionService.CreateCompletions(connectionInfo, docInfo, useLowerCaseSuggestions); Assert.NotNull(result); Assert.NotEqual(result.CompletionItems == null ? 0 : result.CompletionItems.Count(), defaultCompletionList.Count()); }
public void CompletionItemsShouldCreatedUsingDefaultListIfTheSqlParserProcessTimesout() { ConnectedBindingQueue bindingQueue = new ConnectedBindingQueue(); ScriptDocumentInfo docInfo = CreateScriptDocumentInfo(); CompletionService completionService = new CompletionService(bindingQueue); ConnectionInfo connectionInfo = new ConnectionInfo(null, null, null); bool useLowerCaseSuggestions = true; List <Declaration> declarations = new List <Declaration>(); CompletionItem[] defaultCompletionList = AutoCompleteHelper.GetDefaultCompletionItems(docInfo, useLowerCaseSuggestions); var sqlParserWrapper = new Mock <ISqlParserWrapper>(); sqlParserWrapper.Setup(x => x.FindCompletions(docInfo.ScriptParseInfo.ParseResult, docInfo.ParserLine, docInfo.ParserColumn, It.IsAny <IMetadataDisplayInfoProvider>())).Callback(() => Thread.Sleep(LanguageService.BindingTimeout + 100)).Returns(declarations); completionService.SqlParserWrapper = sqlParserWrapper.Object; AutoCompletionResult result = completionService.CreateCompletions(connectionInfo, docInfo, useLowerCaseSuggestions); Assert.NotNull(result); Assert.Equal(result.CompletionItems.Count(), defaultCompletionList.Count()); Thread.Sleep(3000); Assert.True(connectionInfo.IntellisenseMetrics.Quantile.Any()); }
/// <summary> /// Generates a URI for object explorer using a similar pattern to Mongo DB (which has URI-based database definition) /// as this should ensure uniqueness /// </summary> /// <param name="details"></param> /// <returns>string representing a URI</returns> /// <remarks>Internal for testing purposes only</remarks> internal static string GenerateUri(ConnectionDetails details) { return(ConnectedBindingQueue.GetConnectionContextKey(details)); }
/// <summary> /// Created new instance given binding queue /// </summary> public CompletionService(ConnectedBindingQueue bindingQueue) { BindingQueue = bindingQueue; }