mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 01:25:40 -05:00
Fire connection changed event when USE statements are executed
This commit is contained in:
@@ -11,6 +11,7 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Moq;
|
||||
@@ -287,6 +288,40 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
Assert.True(connectionString.Contains(connectionStringMarker));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that a connection changed event is fired when the database context changes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConnectionChangedEventIsFiredWhenDatabaseContextChanges()
|
||||
{
|
||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
||||
|
||||
var connectionService = TestObjects.GetTestConnectionService();
|
||||
connectionService.ServiceHost = serviceHostMock.Object;
|
||||
|
||||
// Set up an initial connection
|
||||
string ownerUri = "file://my/sample/file.sql";
|
||||
var connectionResult =
|
||||
connectionService
|
||||
.Connect(new ConnectParams()
|
||||
{
|
||||
OwnerUri = ownerUri,
|
||||
Connection = TestObjects.GetTestConnectionDetails()
|
||||
});
|
||||
|
||||
// verify that a valid connection id was returned
|
||||
Assert.NotEmpty(connectionResult.ConnectionId);
|
||||
|
||||
ConnectionInfo info;
|
||||
Assert.True(connectionService.TryFindConnection(ownerUri, out info));
|
||||
|
||||
// Tell the connection manager that the database change ocurred
|
||||
connectionService.ChangeConnectionDatabaseContext(ownerUri, "myOtherDb");
|
||||
|
||||
// Verify that the connection changed event was fired
|
||||
serviceHostMock.Verify(x => x.SendEvent<ConnectionChangedParams>(ConnectionChangedNotification.Type, It.IsAny<ConnectionChangedParams>()), Times.Once());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user