mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 01:25:40 -05:00
Next batch of code coverage tests. (#128)
Auto-merging test-only changes. Please review the commit and I'll make changes in next iteration. * Add more tests to boast code coverage * Add more reliable connection tests.
This commit is contained in:
@@ -30,15 +30,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
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";
|
||||
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||
{
|
||||
TextDocument = new TextDocumentItem()
|
||||
@@ -51,7 +48,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
};
|
||||
|
||||
await RequestOpenDocumentNotification(openParams);
|
||||
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(10000);
|
||||
|
||||
Hover hover = await RequestHover(ownerUri, query, 0, 15);
|
||||
|
||||
Assert.True(hover != null, "Hover tooltop is not null");
|
||||
@@ -71,15 +75,12 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
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";
|
||||
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||
{
|
||||
TextDocument = new TextDocumentItem()
|
||||
@@ -92,43 +93,20 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
};
|
||||
|
||||
await RequestOpenDocumentNotification(openParams);
|
||||
|
||||
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"
|
||||
};
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams()
|
||||
{
|
||||
ContentChanges = contentChanges,
|
||||
TextDocument = new VersionedTextDocumentIdentifier()
|
||||
{
|
||||
Version = 2,
|
||||
Uri = ownerUri
|
||||
}
|
||||
};
|
||||
Thread.Sleep(10000);
|
||||
|
||||
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");
|
||||
|
||||
Thread.Sleep(50);
|
||||
|
||||
CompletionItem item = await RequestResolveCompletion(completions[0]);
|
||||
|
||||
Assert.True(completions != null && completions.Length > 0, "Completion items list is not null and not empty");
|
||||
|
||||
@@ -214,10 +214,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
protected async Task<QueryExecuteCompleteParams> RunQuery(string ownerUri, string query)
|
||||
{
|
||||
// Write the query text to a backing file
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, query);
|
||||
}
|
||||
WriteToFile(ownerUri, query);
|
||||
|
||||
var queryParams = new QueryExecuteParams();
|
||||
queryParams.OwnerUri = ownerUri;
|
||||
@@ -234,5 +231,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void WriteToFile(string ownerUri, string query)
|
||||
{
|
||||
lock (fileLock)
|
||||
{
|
||||
System.IO.File.WriteAllText(ownerUri, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Language Service end-to-end integration tests
|
||||
/// </summary>
|
||||
public class WorkspaceTests : TestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Validate workspace lifecycle events
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task InitializeRequestTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
InitializeRequest initializeRequest = new InitializeRequest()
|
||||
{
|
||||
RootPath = Path.GetTempPath(),
|
||||
Capabilities = new ClientCapabilities()
|
||||
};
|
||||
|
||||
InitializeResult result = await Driver.SendRequest(InitializeRequest.Type, initializeRequest);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user