mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 09:35:38 -05:00
Add more test cases for code coverage (#127)
Next round of code coverage test cases. Please review the commit for next iteration. * Add connection retry tests * More test coverage * Update diagnostics end-to-end test
This commit is contained in:
@@ -3,15 +3,9 @@
|
||||
// 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
|
||||
@@ -24,15 +18,44 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
/// <summary>
|
||||
/// Try to connect with invalid credentials
|
||||
/// </summary>
|
||||
//[Fact]
|
||||
[Fact]
|
||||
public async Task InvalidConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
string ownerUri = System.IO.Path.GetTempFileName();
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.InvalidConnection);
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.InvalidConnection, 300000);
|
||||
Assert.False(connected, "Invalid connection is failed to connect");
|
||||
|
||||
await Connect(ownerUri, ConnectionTestUtils.InvalidConnection, 300000);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
await CancelConnect(ownerUri);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate list databases request
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ListDatabasesTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
string ownerUri = System.IO.Path.GetTempFileName();
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection successful");
|
||||
|
||||
var listDatabaseResult = await ListDatabases(ownerUri);
|
||||
Assert.True(listDatabaseResult.DatabaseNames.Length > 0);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
@@ -21,6 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
/// </summary>
|
||||
public class LanguageServiceTests : TestBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Validate hover tooltip scenarios
|
||||
/// </summary>
|
||||
@@ -168,7 +170,74 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
|
||||
await RequestOpenDocumentNotification(openParams);
|
||||
|
||||
Thread.Sleep(5000);
|
||||
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 = ownerUri
|
||||
}
|
||||
};
|
||||
|
||||
await 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 = ownerUri
|
||||
}
|
||||
};
|
||||
|
||||
await RequestChangeTextDocumentNotification(changeParams);
|
||||
|
||||
Thread.Sleep(2500);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
@@ -177,5 +246,39 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the configuration change event
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ChangeConfigurationTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
string ownerUri = System.IO.Path.GetTempFileName();
|
||||
bool connected = await Connect(ownerUri, ConnectionTestUtils.LocalhostConnection);
|
||||
Assert.True(connected, "Connection is successful");
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
var settings = new SqlToolsSettings();
|
||||
settings.SqlTools.IntelliSense.EnableIntellisense = false;
|
||||
DidChangeConfigurationParams<SqlToolsSettings> configParams = new DidChangeConfigurationParams<SqlToolsSettings>()
|
||||
{
|
||||
Settings = settings
|
||||
};
|
||||
|
||||
await RequestChangeConfigurationNotification(configParams);
|
||||
|
||||
Thread.Sleep(2000);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
{
|
||||
WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using Xunit;
|
||||
@@ -28,7 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
|
||||
Thread.Sleep(500);
|
||||
|
||||
string query = "SELECT * FROM sys.objects";
|
||||
string query = "SELECT * FROM sys.all_columns c";
|
||||
|
||||
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification()
|
||||
{
|
||||
@@ -48,6 +49,27 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
Assert.NotNull(queryResult);
|
||||
Assert.NotNull(queryResult.BatchSummaries);
|
||||
|
||||
foreach (var batchSummary in queryResult.BatchSummaries)
|
||||
{
|
||||
foreach (var resultSetSummary in batchSummary.ResultSetSummaries)
|
||||
{
|
||||
Assert.True(resultSetSummary.RowCount > 0);
|
||||
}
|
||||
}
|
||||
|
||||
var subsetRequest = new QueryExecuteSubsetParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
BatchIndex = 0,
|
||||
ResultSetIndex = 0,
|
||||
RowsStartIndex = 0,
|
||||
RowsCount = 100,
|
||||
};
|
||||
|
||||
var querySubset = await RequestQueryExecuteSubset(subsetRequest);
|
||||
Assert.NotNull(querySubset);
|
||||
Assert.True(querySubset.ResultSubset.RowCount == 100);
|
||||
|
||||
await Disconnect(ownerUri);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.TestDriver.Driver;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
|
||||
@@ -73,13 +74,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
/// Request a new connection to be created
|
||||
/// </summary>
|
||||
/// <returns>True if the connection completed successfully</returns>
|
||||
protected async Task<bool> Connect(string ownerUri, ConnectParams connectParams)
|
||||
protected async Task<bool> Connect(string ownerUri, ConnectParams connectParams, int timeout = 15000)
|
||||
{
|
||||
connectParams.OwnerUri = ownerUri;
|
||||
var connectResult = await Driver.SendRequest(ConnectionRequest.Type, connectParams);
|
||||
if (connectResult)
|
||||
{
|
||||
var completeEvent = await Driver.WaitForEvent(ConnectionCompleteNotification.Type);
|
||||
var completeEvent = await Driver.WaitForEvent(ConnectionCompleteNotification.Type, timeout);
|
||||
return !string.IsNullOrEmpty(completeEvent.ConnectionId);
|
||||
}
|
||||
else
|
||||
@@ -100,6 +101,36 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
return disconnectResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
protected async Task<bool> CancelConnect(string ownerUri)
|
||||
{
|
||||
var cancelParams = new CancelConnectParams();
|
||||
cancelParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(CancelConnectRequest.Type, cancelParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a cancel connect
|
||||
/// </summary>
|
||||
protected async Task<ListDatabasesResponse> ListDatabases(string ownerUri)
|
||||
{
|
||||
var listParams = new ListDatabasesParams();
|
||||
listParams.OwnerUri = ownerUri;
|
||||
|
||||
return await Driver.SendRequest(ListDatabasesRequest.Type, listParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
protected async Task<QueryExecuteSubsetResult> RequestQueryExecuteSubset(QueryExecuteSubsetParams subsetParams)
|
||||
{
|
||||
return await Driver.SendRequest(QueryExecuteSubsetRequest.Type, subsetParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
@@ -108,6 +139,14 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
|
||||
await Driver.SendEvent(DidOpenTextDocumentNotification.Type, openParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request a configuration change notification
|
||||
/// </summary>
|
||||
protected async Task RequestChangeConfigurationNotification(DidChangeConfigurationParams<SqlToolsSettings> configParams)
|
||||
{
|
||||
await Driver.SendEvent(DidChangeConfigurationNotification<SqlToolsSettings>.Type, configParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /// Request the active SQL script is parsed for errors
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user