Exemple #1
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);
        }
Exemple #2
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);
                }
        }
        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);
                }
        }
Exemple #4
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 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);
             }
     });
 }
Exemple #6
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 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);
            }
        }
Exemple #9
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);
                }
        }
Exemple #10
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);
        }
Exemple #11
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);
                    }
        }
        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);
        }
Exemple #13
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);
                }
        }
Exemple #14
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);
                }
        }