Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        private void InitializeTestObjects()
        {
            // initial cursor position in the script file
            textDocument = new TextDocumentPosition
            {
                TextDocument = new TextDocumentIdentifier {
                    Uri = this.testScriptUri
                },
                Position = new Position
                {
                    Line      = 0,
                    Character = 0
                }
            };

            // default settings are stored in the workspace service
            WorkspaceService <SqlToolsSettings> .Instance.CurrentSettings = new SqlToolsSettings();

            // set up file for returning the query
            scriptFile = new Mock <ScriptFile>();
            scriptFile.SetupGet(file => file.Contents).Returns(QueryExecution.Common.StandardQuery);
            scriptFile.SetupGet(file => file.ClientFilePath).Returns(this.testScriptUri);

            // set up workspace mock
            workspaceService = new Mock <WorkspaceService <SqlToolsSettings> >();
            workspaceService.Setup(service => service.Workspace.GetFile(It.IsAny <string>()))
            .Returns(scriptFile.Object);

            // setup binding queue mock
            bindingQueue = new Mock <ConnectedBindingQueue>();
            bindingQueue.Setup(q => q.AddConnectionContext(It.IsAny <ConnectionInfo>(), It.IsAny <bool>()))
            .Returns(this.testConnectionKey);

            // inject mock instances into the Language Service
            LanguageService.WorkspaceServiceInstance  = workspaceService.Object;
            LanguageService.ConnectionServiceInstance = TestObjects.GetTestConnectionService();
            ConnectionInfo connectionInfo = TestObjects.GetTestConnectionInfo();

            LanguageService.ConnectionServiceInstance.OwnerToConnectionMap.Add(this.testScriptUri, connectionInfo);
            LanguageService.Instance.BindingQueue = bindingQueue.Object;

            // setup the mock for SendResult
            requestContext = new Mock <RequestContext <CompletionItem[]> >();
            requestContext.Setup(rc => rc.SendResult(It.IsAny <CompletionItem[]>()))
            .Returns(Task.FromResult(0));

            // setup the IBinder mock
            binder = new Mock <IBinder>();
            binder.Setup(b => b.Bind(
                             It.IsAny <IEnumerable <ParseResult> >(),
                             It.IsAny <string>(),
                             It.IsAny <BindMode>()));

            scriptParseInfo = new ScriptParseInfo();
            LanguageService.Instance.AddOrUpdateScriptParseInfo(this.testScriptUri, scriptParseInfo);
            scriptParseInfo.IsConnected   = true;
            scriptParseInfo.ConnectionKey = LanguageService.Instance.BindingQueue.AddConnectionContext(connectionInfo);

            // setup the binding context object
            ConnectedBindingContext bindingContext = new ConnectedBindingContext();

            bindingContext.Binder = binder.Object;
            bindingContext.MetadataDisplayInfoProvider = new MetadataDisplayInfoProvider();
            LanguageService.Instance.BindingQueue.BindingContextMap.Add(scriptParseInfo.ConnectionKey, bindingContext);
        }