Exemplo n.º 1
0
        private async Task <bool> ExpandDatabase(TestServiceDriverProvider testService, string sessionId, NodeInfo nodeInfo, TestTimer timer)
        {
            if (nodeInfo == null)
            {
                return(false);
            }
            bool foundNode    = nodeInfo.NodePath.Contains("Database") || nodeInfo.NodeType == "Database";
            var  expandResult = await testService.CalculateRunTime(() => testService.RequestObjectExplorerExpand(new ObjectExplorer.Contracts.ExpandParams
            {
                SessionId = sessionId,
                NodePath  = nodeInfo.NodePath
            }, 50000), foundNode?timer : null);

            Assert.NotNull(expandResult);
            Assert.NotNull(expandResult.Nodes);
            Assert.False(expandResult.Nodes == null, "Nodes are not valid");
            if (!foundNode)
            {
                foreach (var node in expandResult.Nodes)
                {
                    if (await ExpandDatabase(testService, sessionId, node, timer))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                Console.WriteLine("Node Expanded " + nodeInfo.NodePath);
                return(true);
            }
        }
        public async Task FunctionSignatureCompletionReturnsCorrectParametersAtEachPosition()
        {
            string sqlText = "EXEC sys.fn_isrolemember 1, 'testing', 2";

            using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    string ownerUri = tempFile.FilePath;
                    File.WriteAllText(ownerUri, sqlText);

                    // Connect
                    await testService.Connect(TestServerType.OnPrem, ownerUri);

                    // Wait for intellisense to be ready
                    var readyParams = await testService.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);

                    Assert.NotNull(readyParams);
                    Assert.Equal(ownerUri, readyParams.OwnerUri);

                    // Verify all parameters when the cursor is inside of parameters and at separator boundaries (,)
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 25, "fn_isrolemember", 0, "@mode int");
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 26, "fn_isrolemember", 0, "@mode int");
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 27, "fn_isrolemember", 1, "@login sysname");
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 30, "fn_isrolemember", 1, "@login sysname");
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 37, "fn_isrolemember", 1, "@login sysname");
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 38, "fn_isrolemember", 2, "@tranpubid int");
                    await VerifyFunctionSignatureHelpParameter(testService, ownerUri, 39, "fn_isrolemember", 2, "@tranpubid int");

                    await testService.Disconnect(ownerUri);
                }
        }
        public async Task ChangeConfigurationTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

                    Assert.True(connected, "Connection was not successful");

                    Thread.Sleep(500);

                    var settings = new SqlToolsSettings();
                    settings.SqlTools.IntelliSense.EnableIntellisense = false;
                    DidChangeConfigurationParams <SqlToolsSettings> configParams = new DidChangeConfigurationParams <SqlToolsSettings>()
                    {
                        Settings = settings
                    };

                    await testService.RequestChangeConfigurationNotification(configParams);

                    Thread.Sleep(2000);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Exemplo n.º 4
0
        public async Task ScriptTable()
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                ScriptingParams requestParams = new ScriptingParams
                {
                    ScriptDestination = "ToEditor",
                    ConnectionString  = this.Northwind.ConnectionString,
                    ScriptOptions     = new ScriptOptions
                    {
                        TypeOfDataToScript = "SchemaOnly",
                    },
                    ScriptingObjects = new List <ScriptingObject>
                    {
                        new ScriptingObject
                        {
                            Type   = "Table",
                            Schema = "dbo",
                            Name   = "Customers",
                        },
                    }
                };

                ScriptingResult result = await testService.Script(requestParams);

                ScriptingPlanNotificationParams planEvent = await testService.Driver.WaitForEvent(ScriptingPlanNotificationEvent.Type, TimeSpan.FromSeconds(1));

                ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));

                Assert.True(parameters.Success);
                Assert.Equal <int>(1, planEvent.Count);
            }
        }
Exemplo n.º 5
0
        public async Task ScriptSelectTable()
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
                {
                    await testService.Connect(tempFile.FilePath, testService.TestConnectionService.GetConnectionParameters(serverType: TestServerType.OnPrem));

                    ScriptingParams requestParams = new ScriptingParams
                    {
                        ScriptDestination = "ToEditor",
                        OwnerUri          = tempFile.FilePath,
                        ScriptOptions     = new ScriptOptions
                        {
                            ScriptCreateDrop = "ScriptSelect"
                        },
                        ScriptingObjects = new List <ScriptingObject>
                        {
                            new ScriptingObject
                            {
                                Type   = "Table",
                                Schema = "dbo",
                                Name   = "Customers",
                            }
                        }
                    };
                    ScriptingResult result = await testService.Script(requestParams);

                    Assert.True(result.Script.Contains("SELECT"));
                }
        }
        public async Task ScriptDatabaseSchemaAndData()
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
                {
                    ScriptingParams requestParams = new ScriptingParams
                    {
                        FilePath         = tempFile.FilePath,
                        ConnectionString = this.Northwind.ConnectionString,
                        ScriptOptions    = new ScriptOptions
                        {
                            TypeOfDataToScript = "SchemaAndData",
                        },
                    };

                    ScriptingResult result = await testService.Script(requestParams);

                    ScriptingPlanNotificationParams planEvent = await testService.Driver.WaitForEvent(ScriptingPlanNotificationEvent.Type, TimeSpan.FromSeconds(30));

                    ScriptingCompleteParams completeParameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(30));

                    Assert.True(completeParameters.Success);
                    Assert.Equal <int>(ScriptingFixture.ObjectCountWithDatabase, planEvent.Count);
                    Assert.True(File.Exists(tempFile.FilePath));
                    Assert.True(new FileInfo(tempFile.FilePath).Length > 0);
                    AssertSchemaInFile(tempFile.FilePath, assert: true);
                    AssertTableDataInFile(tempFile.FilePath, assert: true);
                }
        }
        public async Task ScriptTableDoesNotExist()
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
                {
                    ScriptingParams requestParams = new ScriptingParams
                    {
                        FilePath         = tempFile.FilePath,
                        ConnectionString = this.Northwind.ConnectionString,
                        ScriptOptions    = new ScriptOptions
                        {
                            TypeOfDataToScript = "SchemaOnly",
                        },
                        ScriptingObjects = new List <ScriptingObject>
                        {
                            new ScriptingObject
                            {
                                Type   = "Table",
                                Schema = "dbo",
                                Name   = "TableDoesNotExist",
                            },
                        }
                    };

                    ScriptingResult result = await testService.Script(requestParams);

                    ScriptingCompleteParams parameters = await testService.Driver.WaitForEvent(ScriptingCompleteEvent.Type, TimeSpan.FromSeconds(15));

                    Assert.True(parameters.HasError);
                    Assert.Equal("An error occurred while scripting the objects.", parameters.ErrorMessage);
                    Assert.Contains("The Table '[dbo].[TableDoesNotExist]' does not exist on the server.", parameters.ErrorDetails);
                }
        }
Exemplo n.º 8
0
        private async Task QueryResultFirstOnPremTest(TestServerType serverType, string query, [CallerMemberName] string testName = "")
        {
            await TestServiceDriverProvider.RunTestIterations(async (timer) =>
            {
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                    using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                    {
                        await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);
                        testService.WriteToFile(queryTempFile.FilePath, query);
                        await testService.RunQueryAndWaitToStart(queryTempFile.FilePath, 50000);
                        await testService.ExecuteWithTimeout(timer, 500000, async() =>
                        {
                            var queryResult = await testService.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 50);
                            if (queryResult != null)
                            {
                                Assert.NotNull(queryResult);
                                Assert.NotNull(queryResult.ResultSubset);
                                Assert.True(queryResult.ResultSubset.Rows.Any());
                            }
                            return(queryResult != null);
                        }, TimeSpan.FromMilliseconds(10));

                        await testService.Disconnect(queryTempFile.FilePath);
                    }
            }, testName);
        }
        public async Task ConnectOnPremTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    testService.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testService.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);
                    var connected = await testService.CalculateRunTime(async() =>
                    {
                        var connectParams = testService.GetConnectionParameters(serverType, Common.PerfTestDatabaseName);
                        return(await testService.Connect(queryTempFile.FilePath, connectParams));
                    }, true);

                    Assert.True(connected, "Connection was not successful");
                }
        }
Exemplo n.º 10
0
        public async Task NoOpQueryReturnsMessage(string query)
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    Assert.True(await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath));
                    // If: the query is executed...
                    var queryResult = await testService.RunQueryAsync(queryTempFile.FilePath, query);

                    var message = await testService.WaitForMessage();

                    // Then:
                    // ... I expect a query result to indicate successfully started query
                    Assert.NotNull(queryResult);

                    // ... I expect a non-error message to be returned without a batch associated with it
                    Assert.NotNull(message);
                    Assert.NotNull(message.Message);
                    Assert.NotNull(message.Message.Message);
                    Assert.False(message.Message.IsError);
                    Assert.Null(message.Message.BatchId);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Repeatedly connect and disconnect to stress test the connection service.
        /// </summary>
        //[Fact]
        public async Task TestConnectionService()
        {
            string ownerUri = "file:///my/test/file.sql";


            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                var connection = testService.GetConnectionParameters(TestServerType.OnPrem);
                connection.Connection.Pooling = false;

                // Connect/disconnect repeatedly
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                while (stopwatch.Elapsed < TimeSpan.FromMinutes(60))
                {
                    // Connect
                    bool connected = await testService.Connect(ownerUri, connection);

                    Assert.True(connected, "Connection is successful");

                    // Disconnect
                    bool disconnected = await testService.Disconnect(ownerUri);

                    Assert.True(disconnected, "Disconnect is successful");
                }
            }
        }
Exemplo n.º 12
0
        public async Task BindingCacheColdOnPremComplexQuery()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                await VerifyBindingLoadScenario(testService, serverType, Scripts.TestDbComplexSelectQueries, false);
            }
        }
Exemplo n.º 13
0
        public async Task BindingCacheColdAzureSimpleQuery()
        {
            TestServerType serverType = TestServerType.Azure;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                await VerifyBindingLoadScenario(testService, serverType, Scripts.TestDbSimpleSelectQuery, false);
            }
        }
Exemplo n.º 14
0
        public async Task DiagnosticsTests()
        {
            TestServerType serverType = TestServerType.OnPrem;

            SqlTestDb.CreateNew(serverType, doNotCleanupDb: true, databaseName: Common.PerfTestDatabaseName, query: Scripts.CreateDatabaseObjectsQuery);

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    await testService.ConnectForQuery(serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);

                    Thread.Sleep(500);
                    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     = queryTempFile.FilePath
                        }
                    };

                    TestTimer timer = new TestTimer()
                    {
                        PrintResult = true
                    };
                    await testService.RequestChangeTextDocumentNotification(changeParams);

                    await testService.ExecuteWithTimeout(timer, 60000, async() =>
                    {
                        var completeEvent = await testService.Driver.WaitForEvent(PublishDiagnosticsNotification.Type, 15000);
                        return(completeEvent?.Diagnostics != null && completeEvent.Diagnostics.Length > 0);
                    });

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Exemplo n.º 15
0
 public async Task BindingCacheWarmOnPremComplexQuery()
 {
     using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
         {
             string query = Scripts.TestDbComplexSelectQueries;
             const TestServerType serverType = TestServerType.OnPrem;
             await VerifyBindingLoadScenario(testService, serverType, query, true);
         }
 }
 public async Task BindingCacheColdOnPremSimpleQuery()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         TestServerType serverType = TestServerType.OnPrem;
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
         {
             await VerifyBindingLoadScenario(testService, serverType, Scripts.TestDbSimpleSelectQuery, false, timer);
         }
     });
 }
Exemplo n.º 17
0
        public async Task BindingCacheWarmAzureSimpleQuery()
        {
            TestServerType serverType = TestServerType.Azure;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await VerifyBindingLoadScenario(testService, serverType, query, true);
                }
        }
 public async Task BindingCacheWarmAzureComplexQuery()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
             using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
             {
                 string query = Scripts.TestDbComplexSelectQueries;
                 const TestServerType serverType = TestServerType.Azure;
                 await VerifyBindingLoadScenario(testService, serverType, query, true, timer);
             }
     });
 }
        public async Task BindingCacheWarmOnPremSimpleQuery()
        {
            await TestServiceDriverProvider.RunTestIterations(async (timer) =>
            {
                TestServerType serverType = TestServerType.OnPrem;

                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                    using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                    {
                        const string query = Scripts.TestDbSimpleSelectQuery;
                        await VerifyBindingLoadScenario(testService, serverType, query, true, timer);
                    }
            });
        }
Exemplo n.º 20
0
        public async Task InitializeRequestTest()
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                InitializeRequest initializeRequest = new InitializeRequest()
                {
                    RootPath     = Path.GetTempPath(),
                    Capabilities = new ClientCapabilities()
                };

                InitializeResult result = await testService.Driver.SendRequest(InitializeRequest.Type, initializeRequest);

                Assert.NotNull(result);
            }
        }
Exemplo n.º 21
0
        public async Task DisconnectTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    await testService.ConnectForQuery(serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);

                    Thread.Sleep(1000);
                    var connected = await testService.CalculateRunTime(() => testService.Disconnect(queryTempFile.FilePath), true);

                    Assert.True(connected);
                }
        }
Exemplo n.º 22
0
        public async Task SuggestionsTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
                    await ValidateCompletionResponse(testService, queryTempFile.FilePath, false, Common.PerfTestDatabaseName, true);
                    await ValidateCompletionResponse(testService, queryTempFile.FilePath, true, Common.PerfTestDatabaseName, false);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        public async Task VerifyFunctionSignatureHelpParameter(
            TestServiceDriverProvider TestService,
            string ownerUri,
            int character,
            string expectedFunctionName,
            int expectedParameterIndex,
            string expectedParameterName)
        {
            var position = new TextDocumentPosition()
            {
                TextDocument = new TextDocumentIdentifier()
                {
                    Uri = ownerUri
                },
                Position = new Position()
                {
                    Line      = 0,
                    Character = character
                }
            };
            var signatureHelp = await TestService.Driver.SendRequest(SignatureHelpRequest.Type, position);

            Assert.NotNull(signatureHelp);
            Assert.NotNull(signatureHelp.ActiveSignature);
            Assert.True(signatureHelp.ActiveSignature.HasValue);
            Assert.NotEmpty(signatureHelp.Signatures);

            var activeSignature = signatureHelp.Signatures[signatureHelp.ActiveSignature.Value];

            Assert.NotNull(activeSignature);

            var label = activeSignature.Label;

            Assert.NotNull(label);
            Assert.NotEmpty(label);
            Assert.True(label.Contains(expectedFunctionName));

            Assert.NotNull(signatureHelp.ActiveParameter);
            Assert.True(signatureHelp.ActiveParameter.HasValue);
            Assert.Equal(expectedParameterIndex, signatureHelp.ActiveParameter.Value);

            var parameter = activeSignature.Parameters[signatureHelp.ActiveParameter.Value];

            Assert.NotNull(parameter);
            Assert.NotNull(parameter.Label);
            Assert.NotEmpty(parameter.Label);
            Assert.Equal(expectedParameterName, parameter.Label);
        }
 public async Task SuggestionsTest()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         TestServerType serverType = TestServerType.OnPrem;
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
             using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
             {
                 const string query = Scripts.TestDbSimpleSelectQuery;
                 await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
                 await ValidateCompletionResponse(testService, queryTempFile.FilePath, Common.PerfTestDatabaseName, timer: null, waitForIntelliSense: true);
                 await ValidateCompletionResponse(testService, queryTempFile.FilePath, Common.PerfTestDatabaseName, timer: timer, waitForIntelliSense: false);
                 await testService.Disconnect(queryTempFile.FilePath);
             }
     });
 }
Exemplo n.º 25
0
        public async Task HoverTestOnPrem()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);

                    Hover hover = await testService.CalculateRunTime(() => testService.RequestHover(queryTempFile.FilePath, query, 0, Scripts.TestDbComplexSelectQueries.Length + 1), true);

                    Assert.NotNull(hover);
                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Exemplo n.º 26
0
        public async Task ListDatabasesTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

                    Assert.True(connected, "Connection successful");

                    var listDatabaseResult = await testService.ListDatabases(queryTempFile.FilePath);

                    Assert.True(listDatabaseResult.DatabaseNames.Length > 0);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        public async Task ListSchemaObjects()
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
                {
                    ScriptingListObjectsParams requestParams = new ScriptingListObjectsParams
                    {
                        ConnectionString = this.Northwind.ConnectionString,
                    };

                    ScriptingListObjectsResult result = await testService.ListScriptingObjects(requestParams);

                    ScriptingListObjectsCompleteParams completeParameters = await testService.Driver.WaitForEvent(ScriptingListObjectsCompleteEvent.Type, TimeSpan.FromSeconds(30));

                    Assert.Equal <int>(ScriptingFixture.ObjectCountWithoutDatabase, completeParameters.ScriptingObjects.Count);
                }
        }
        public async Task NotificationIsSentAfterOnConnectionAutoCompleteUpdate()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    // Connect
                    await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

                    // An event signalling that IntelliSense is ready should be sent shortly thereafter
                    var readyParams = await testService.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);

                    Assert.NotNull(readyParams);
                    Assert.Equal(queryTempFile.FilePath, readyParams.OwnerUri);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        public async Task FunctionSignatureCompletionReturnsCorrectFunction()
        {
            string sqlText = "EXEC sys.fn_isrolemember ";

            using (SelfCleaningTempFile tempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    string ownerUri = tempFile.FilePath;

                    // Connect
                    await testService.ConnectForQuery(TestServerType.OnPrem, sqlText, ownerUri);

                    // Wait for intellisense to be ready
                    var readyParams = await testService.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 30000);

                    Assert.NotNull(readyParams);
                    Assert.Equal(ownerUri, readyParams.OwnerUri);

                    // Send a function signature help Request
                    var position = new TextDocumentPosition()
                    {
                        TextDocument = new TextDocumentIdentifier()
                        {
                            Uri = ownerUri
                        },
                        Position = new Position()
                        {
                            Line      = 0,
                            Character = sqlText.Length
                        }
                    };
                    var signatureHelp = await testService.Driver.SendRequest(SignatureHelpRequest.Type, position);

                    Assert.NotNull(signatureHelp);
                    Assert.True(signatureHelp.ActiveSignature.HasValue);
                    Assert.NotEmpty(signatureHelp.Signatures);

                    var label = signatureHelp.Signatures[signatureHelp.ActiveSignature.Value].Label;
                    Assert.NotNull(label);
                    Assert.NotEmpty(label);
                    Assert.True(label.Contains("fn_isrolemember"));

                    await testService.Disconnect(ownerUri);
                }
        }
Exemplo n.º 30
0
        public async Task InvalidConnection()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    bool connected = await testService.Connect(queryTempFile.FilePath, InvalidConnectParams, 300000);

                    Assert.False(connected, "Invalid connection is failed to connect");

                    await testService.Connect(queryTempFile.FilePath, InvalidConnectParams, 300000);

                    Thread.Sleep(1000);

                    await testService.CancelConnect(queryTempFile.FilePath);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }