mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Add end-to-end language service tests. (#123)
Test-only code coverage changes. Please review the commit and I'll follow-up on next iteration.
This commit is contained in:
@@ -70,7 +70,10 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionDetails GetIntegratedTestConnectionDetails()
|
/// <summary>
|
||||||
|
/// Gets a ConnectionDetails for connecting to localhost with integrated auth
|
||||||
|
/// </summary>
|
||||||
|
public static ConnectionDetails GetIntegratedTestConnectionDetails()
|
||||||
{
|
{
|
||||||
return new ConnectionDetails()
|
return new ConnectionDetails()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Language Service end-to-end integration tests
|
||||||
|
/// </summary>
|
||||||
|
public class LanguageServiceTests : TestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Validate hover tooltip scenarios
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task HoverTest()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string ownerUri = System.IO.Path.GetTempFileName();
|
||||||
|
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||||
|
Assert.True(connected, "Connection is successful");
|
||||||
|
|
||||||
|
Thread.Sleep(500);
|
||||||
|
|
||||||
|
string query = "SELECT * FROM sys.objects";
|
||||||
|
|
||||||
|
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||||
|
{
|
||||||
|
TextDocument = new TextDocumentItem()
|
||||||
|
{
|
||||||
|
Uri = ownerUri,
|
||||||
|
LanguageId = "enu",
|
||||||
|
Version = 1,
|
||||||
|
Text = query
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await RequestOpenDocumentNotification(openParams);
|
||||||
|
|
||||||
|
Hover hover = await RequestHover(ownerUri, query, 0, 15);
|
||||||
|
|
||||||
|
Assert.True(hover != null, "Hover tooltop is not null");
|
||||||
|
|
||||||
|
await Disconnect(ownerUri);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
WaitForExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation autocompletion suggestions scenarios
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task CompletionTest()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string ownerUri = System.IO.Path.GetTempFileName();
|
||||||
|
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||||
|
Assert.True(connected, "Connection is successful");
|
||||||
|
|
||||||
|
Thread.Sleep(500);
|
||||||
|
|
||||||
|
string query = "SELECT * FROM sys.objects";
|
||||||
|
|
||||||
|
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||||
|
{
|
||||||
|
TextDocument = new TextDocumentItem()
|
||||||
|
{
|
||||||
|
Uri = ownerUri,
|
||||||
|
LanguageId = "enu",
|
||||||
|
Version = 1,
|
||||||
|
Text = query
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await RequestOpenDocumentNotification(openParams);
|
||||||
|
|
||||||
|
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 = ownerUri
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await RequestChangeTextDocumentNotification(changeParams);
|
||||||
|
|
||||||
|
CompletionItem[] completions = await RequestCompletion(ownerUri, query, 0, 15);
|
||||||
|
|
||||||
|
Assert.True(completions != null && completions.Length > 0, "Completion items list is not null and not empty");
|
||||||
|
|
||||||
|
CompletionItem item = await RequestResolveCompletion(completions[0]);
|
||||||
|
|
||||||
|
Assert.True(completions != null && completions.Length > 0, "Completion items list is not null and not empty");
|
||||||
|
|
||||||
|
await Disconnect(ownerUri);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
WaitForExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate diagnostic scenarios
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task DiagnosticsTests()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string ownerUri = System.IO.Path.GetTempFileName();
|
||||||
|
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||||
|
Assert.True(connected, "Connection is successful");
|
||||||
|
|
||||||
|
Thread.Sleep(500);
|
||||||
|
|
||||||
|
string query = "SELECT *** FROM sys.objects";
|
||||||
|
|
||||||
|
|
||||||
|
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||||
|
{
|
||||||
|
TextDocument = new TextDocumentItem()
|
||||||
|
{
|
||||||
|
Uri = ownerUri,
|
||||||
|
LanguageId = "enu",
|
||||||
|
Version = 1,
|
||||||
|
Text = query
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await RequestOpenDocumentNotification(openParams);
|
||||||
|
|
||||||
|
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
|
||||||
|
await Disconnect(ownerUri);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
WaitForExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
|||||||
{
|
{
|
||||||
public class QueryExecutionTests : TestBase
|
public class QueryExecutionTests : TestBase
|
||||||
{
|
{
|
||||||
[Fact]
|
//[Fact]
|
||||||
public async Task TestQueryingAfterCompletionRequests()
|
public async Task TestQueryingAfterCompletionRequests()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -38,17 +38,23 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
|||||||
|
|
||||||
public void WaitForExit()
|
public void WaitForExit()
|
||||||
{
|
{
|
||||||
this.isRunning = false;
|
try
|
||||||
|
{
|
||||||
|
this.isRunning = false;
|
||||||
|
|
||||||
if (!Driver.IsCoverageRun)
|
if (!Driver.IsCoverageRun)
|
||||||
{
|
{
|
||||||
Driver.Stop().Wait();
|
Driver.Stop().Wait();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var p = Process.Start("taskkill", "/IM Microsoft.SqlTools.ServiceLayer.exe /F");
|
||||||
|
p.WaitForExit();
|
||||||
|
Driver.ServiceProcess?.WaitForExit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch
|
||||||
{
|
{
|
||||||
var p = Process.Start("taskkill", "/IM Microsoft.SqlTools.ServiceLayer.exe /F");
|
|
||||||
p.WaitForExit();
|
|
||||||
Driver.ServiceProcess?.WaitForExit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +100,31 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
|||||||
return disconnectResult;
|
return disconnectResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request the active SQL script is parsed for errors
|
||||||
|
/// </summary>
|
||||||
|
protected async Task RequestOpenDocumentNotification(DidOpenTextDocumentNotification openParams)
|
||||||
|
{
|
||||||
|
await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// /// Request the active SQL script is parsed for errors
|
||||||
|
/// </summary>
|
||||||
|
protected async Task RequestChangeTextDocumentNotification(DidChangeTextDocumentParams changeParams)
|
||||||
|
{
|
||||||
|
await Driver.SendEvent(DidChangeTextDocumentNotification.Type, changeParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request completion item resolve to look-up additional info
|
||||||
|
/// </summary>
|
||||||
|
protected async Task<CompletionItem> RequestResolveCompletion(CompletionItem item)
|
||||||
|
{
|
||||||
|
var result = await Driver.SendRequest(CompletionResolveRequest.Type, item);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request a list of completion items for a position in a block of text
|
/// Request a list of completion items for a position in a block of text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -116,6 +147,28 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request a a hover tooltop
|
||||||
|
/// </summary>
|
||||||
|
protected async Task<Hover> RequestHover(string ownerUri, string text, int line, int character)
|
||||||
|
{
|
||||||
|
// Write the text to a backing file
|
||||||
|
lock (fileLock)
|
||||||
|
{
|
||||||
|
System.IO.File.WriteAllText(ownerUri, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
var completionParams = new TextDocumentPosition();
|
||||||
|
completionParams.TextDocument = new TextDocumentIdentifier();
|
||||||
|
completionParams.TextDocument.Uri = ownerUri;
|
||||||
|
completionParams.Position = new Position();
|
||||||
|
completionParams.Position.Line = line;
|
||||||
|
completionParams.Position.Character = character;
|
||||||
|
|
||||||
|
var result = await Driver.SendRequest(HoverRequest.Type, completionParams);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run a query using a given connection bound to a URI
|
/// Run a query using a given connection bound to a URI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user