Esempio n. 1
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);
                }
        }
        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);
                }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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");
                }
            }
        }
Esempio n. 6
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);
                }
        }
Esempio n. 7
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 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);
                }
        }
        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 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);
             }
     });
 }
Esempio n. 11
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);
                }
        }
        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);
                }
        }
        private async Task VerifyCompletationLoaded(
            TestServiceDriverProvider testService,
            TestServerType serverType,
            string query,
            string databaseName,
            TestTimer timer,
            string testName)
        {
            using (SelfCleaningTempFile testTempFile = new SelfCleaningTempFile())
            {
                testService.WriteToFile(testTempFile.FilePath, query);
                await testService.ConnectForQuery(serverType, query, testTempFile.FilePath, databaseName);
                await ValidateCompletionResponse(testService, testTempFile.FilePath, databaseName,
                                                 waitForIntelliSense : true, timer : timer, testName : testName);

                await testService.Disconnect(testTempFile.FilePath);
            }
        }
        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);
                }
        }
Esempio n. 16
0
        public async Task QueryResultSummaryOnPremTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    const string query = Scripts.MasterBasicQuery;

                    await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);

                    var queryResult = await testService.CalculateRunTime(() => testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, query), true);

                    Assert.NotNull(queryResult);
                    Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        public async Task CompletionTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    string query = "SELECT * FROM sys.objects";

                    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);

                    bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

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

                    Thread.Sleep(10000);

                    CompletionItem[] completions = await testService.RequestCompletion(queryTempFile.FilePath, query, 0, 15);

                    Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");

                    Thread.Sleep(50);

                    await testService.RequestResolveCompletion(completions[0]);

                    Assert.True(completions != null && completions.Length > 0, "Completion items list is null or empty");

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        public async Task DefinitionTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    string query      = "SELECT * FROM sys.objects";
                    int    lineNumber = 0;
                    int    position   = 23;

                    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);

                    bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

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

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


                    // Request definition for "objects"
                    Location[] locations = await testService.RequestDefinition(queryTempFile.FilePath, query, lineNumber, position);

                    Assert.True(locations != null, "Location is not null and not empty");
                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Esempio n. 19
0
        private async Task QueryResultSummaryOnPremTest(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);
                        var queryResult = await testService.CalculateRunTime(
                            () => testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, 50000),
                            timer);

                        Assert.NotNull(queryResult);
                        Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));

                        await testService.Disconnect(queryTempFile.FilePath);
                    }
            }, testName);
        }
Esempio n. 20
0
        public async Task TestSaveResultsToJsonTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
                    using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                    {
                        const string query = Scripts.MasterBasicQuery;

                        // Execute a query
                        await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);

                        await testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, query);

                        await testService.CalculateRunTime(() => testService.SaveAsJson(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0), true);

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

            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);

                    // 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.False(signatureHelp.ActiveSignature.HasValue);
                    Assert.Null(signatureHelp.Signatures);

                    await testService.Disconnect(ownerUri);
                }
        }
Esempio n. 22
0
        /// <summary>
        /// Repeatedly execute queries to stress test the query execution service.
        /// </summary>
        //[Fact]
        public async Task TestQueryExecutionService()
        {
            const string queryToRun = "SELECT * FROM sys.all_objects GO " +
                                      "SELECT * FROM sys.objects GO " +
                                      "SELECT * FROM sys.tables GO " +
                                      "SELECT COUNT(*) FROM sys.objects";

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    // Connect
                    bool connected = await testService.Connect(TestServerType.OnPrem, string.Empty, queryTempFile.FilePath);

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

                    // Run queries repeatedly
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    while (stopwatch.Elapsed < TimeSpan.FromMinutes(60))
                    {
                        var queryResult = await testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, queryToRun, 10000);

                        Assert.NotNull(queryResult);
                        Assert.NotNull(queryResult.BatchSummaries);
                        Assert.NotEmpty(queryResult.BatchSummaries);
                        Assert.NotNull(queryResult.BatchSummaries[0].ResultSetSummaries);
                        Assert.NotNull(queryResult.BatchSummaries[1].ResultSetSummaries);
                        Assert.NotNull(queryResult.BatchSummaries[2].ResultSetSummaries);
                        Assert.NotNull(queryResult.BatchSummaries[3].ResultSetSummaries);

                        Assert.NotNull(await testService.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 7));
                        Assert.NotNull(await testService.ExecuteSubset(queryTempFile.FilePath, 1, 0, 0, 7));
                        Assert.NotNull(await testService.ExecuteSubset(queryTempFile.FilePath, 2, 0, 0, 7));
                        Assert.NotNull(await testService.ExecuteSubset(queryTempFile.FilePath, 3, 0, 0, 1));

                        Thread.Sleep(500);
                    }

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        private async Task VerifyScriptTable(TestServerType serverType, [CallerMemberName] string testName = "")
        {
            await TestServiceDriverProvider.RunTestIterations(async (timer) =>
            {
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                    using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                    {
                        await testService.ConnectForQuery(serverType, string.Empty, queryTempFile.FilePath, Common.PerfTestDatabaseName);
                        List <ScriptingObject> scriptingObjects = new List <ScriptingObject>()
                        {
                            new ScriptingObject
                            {
                                Schema = "Person",
                                Name   = "Address",
                                Type   = "Table"
                            }
                        };
                        ScriptingParams scriptingParams = new ScriptingParams
                        {
                            OwnerUri      = queryTempFile.FilePath,
                            Operation     = ScriptingOperationType.Create,
                            FilePath      = queryTempFile.FilePath,
                            ScriptOptions = new ScriptOptions
                            {
                                ScriptCreateDrop = "ScriptCreate",
                            },
                            ScriptDestination = "ToEditor",
                            ScriptingObjects  = scriptingObjects
                        };
                        var result = await testService.CalculateRunTime(() => testService.RequestScript(scriptingParams), timer);

                        Assert.NotNull(result);
                        Assert.NotNull(result.Script);

                        Assert.False(string.IsNullOrEmpty(result.Script), "Script result is invalid");

                        await testService.Disconnect(queryTempFile.FilePath);
                    }
            }, testName);
        }
Esempio n. 24
0
        private async Task VerifyCreateSession(TestServerType serverType, [CallerMemberName] string testName = "")
        {
            await TestServiceDriverProvider.RunTestIterations(async (timer) =>
            {
                ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(serverType, SqlTestDb.MasterDatabaseName);
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                    using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                    {
                        var result = await testService.CalculateRunTime(() => testService.RequestObjectExplorerCreateSession(connectParams.Connection), timer);

                        Assert.NotNull(result);
                        Assert.True(result.Success);
                        Assert.False(string.IsNullOrEmpty(result.SessionId), "Session id cannot be empty");

                        await testService.RequestObjectExplorerCloseSession(new ObjectExplorer.Contracts.CloseSessionParams
                        {
                            SessionId = result.SessionId
                        });
                        await testService.Disconnect(queryTempFile.FilePath);
                    }
            }, testName);
        }
        public async Task HoverTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    string query = "SELECT * FROM sys.objects";

                    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);

                    bool connected = await testService.Connect(TestServerType.OnPrem, queryTempFile.FilePath);

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

                    Thread.Sleep(10000);

                    Hover hover = await testService.RequestHover(queryTempFile.FilePath, query, 0, 15);

                    Assert.True(hover != null, "Hover tooltop is null");

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Esempio n. 26
0
        public async Task CancelQueryOnPremTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

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

                    var queryParams = new ExecuteDocumentSelectionParams
                    {
                        OwnerUri       = queryTempFile.FilePath,
                        QuerySelection = null
                    };

                    var result = await testService.Driver.SendRequest(ExecuteDocumentSelectionRequest.Type, queryParams);

                    if (result != null)
                    {
                        TestTimer timer = new TestTimer()
                        {
                            PrintResult = true
                        };
                        await testService.ExecuteWithTimeout(timer, 100000, async() =>
                        {
                            var cancelQueryResult = await testService.CancelQuery(queryTempFile.FilePath);
                            return(true);
                        }, TimeSpan.FromMilliseconds(10));
                    }
                    else
                    {
                        Assert.True(false, "Failed to run the query");
                    }

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Esempio n. 27
0
        public async Task QueryResultFirstOnPremTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    const string query = Scripts.MasterBasicQuery;

                    await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);

                    var queryResult = await testService.CalculateRunTime(async() =>
                    {
                        await testService.RunQueryAndWaitToComplete(queryTempFile.FilePath, query);
                        return(await testService.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100));
                    }, true);

                    Assert.NotNull(queryResult);
                    Assert.NotNull(queryResult.ResultSubset);
                    Assert.True(queryResult.ResultSubset.Rows.Any());

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
        public async Task DiagnosticsTests()
        {
            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);

                    string query = "SELECT *** FROM sys.objects";

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

                    await testService.RequestOpenDocumentNotification(openParams);

                    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     = queryTempFile.FilePath
                        }
                    };

                    await testService.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     = queryTempFile.FilePath
                        }
                    };

                    await testService.RequestChangeTextDocumentNotification(changeParams);

                    Thread.Sleep(2500);

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Esempio n. 29
0
        /// <summary>
        /// Simulate typing by a user to stress test the language service
        /// </summary>
        //[Fact]
        public async Task TestLanguageService()
        {
            const string textToType = "SELECT * FROM sys.objects GO " +
                                      "CREATE TABLE MyTable(" +
                                      "FirstName CHAR," +
                                      "LastName CHAR," +
                                      "DateOfBirth DATETIME," +
                                      "CONSTRAINT MyTableConstraint UNIQUE (FirstName, LastName, DateOfBirth)) GO " +
                                      "INSERT INTO MyTable (FirstName, LastName, DateOfBirth) VALUES ('John', 'Doe', '19800101') GO " +
                                      "SELECT * FROM MyTable GO " +
                                      "ALTER TABLE MyTable DROP CONSTRAINT MyTableConstraint GO " +
                                      "DROP TABLE MyTable GO ";


            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    // Connect
                    bool connected = await testService.Connect(TestServerType.OnPrem, string.Empty, queryTempFile.FilePath);

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

                    Thread.Sleep(10000); // Wait for intellisense to warm up

                    // Simulate typing
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    int version = 1;
                    while (stopwatch.Elapsed < TimeSpan.FromMinutes(60))
                    {
                        for (int i = 0; i < textToType.Length; i++)
                        {
                            System.IO.File.WriteAllText(queryTempFile.FilePath, textToType.Substring(0, i + 1));

                            var contentChanges = new TextDocumentChangeEvent[1];
                            contentChanges[0] = new TextDocumentChangeEvent()
                            {
                                Range = new Range()
                                {
                                    Start = new Position()
                                    {
                                        Line      = 0,
                                        Character = i
                                    },
                                    End = new Position()
                                    {
                                        Line      = 0,
                                        Character = i
                                    }
                                },
                                RangeLength = 1,
                                Text        = textToType.Substring(i, 1)
                            };

                            DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams()
                            {
                                ContentChanges = contentChanges,
                                TextDocument   = new VersionedTextDocumentIdentifier()
                                {
                                    Version = ++version,
                                    Uri     = queryTempFile.FilePath
                                }
                            };

                            await testService.RequestChangeTextDocumentNotification(changeParams);

                            Thread.Sleep(50);

                            // If we just typed a space, request/resolve completion
                            if (textToType[i] == ' ')
                            {
                                var completions = await testService.RequestCompletion(queryTempFile.FilePath, textToType.Substring(0, i + 1), 0, i + 1);

                                Assert.True(completions != null && completions.Length > 0, "Completion items list was null or empty");

                                Thread.Sleep(50);

                                var item = await testService.RequestResolveCompletion(completions[0]);

                                Assert.NotNull(item);
                            }
                        }

                        // Clear the text document
                        System.IO.File.WriteAllText(queryTempFile.FilePath, "");

                        var contentChanges2 = new TextDocumentChangeEvent[1];
                        contentChanges2[0] = new TextDocumentChangeEvent()
                        {
                            Range = new Range()
                            {
                                Start = new Position()
                                {
                                    Line      = 0,
                                    Character = 0
                                },
                                End = new Position()
                                {
                                    Line      = 0,
                                    Character = textToType.Length - 1
                                }
                            },
                            RangeLength = textToType.Length,
                            Text        = ""
                        };

                        DidChangeTextDocumentParams changeParams2 = new DidChangeTextDocumentParams()
                        {
                            ContentChanges = contentChanges2,
                            TextDocument   = new VersionedTextDocumentIdentifier()
                            {
                                Version = ++version,
                                Uri     = queryTempFile.FilePath
                            }
                        };

                        await testService.RequestChangeTextDocumentNotification(changeParams2);
                    }

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