mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Actually fixing the service host requirements by using the EventFlowValidator
This commit is contained in:
@@ -8,6 +8,7 @@ using Microsoft.SqlTools.Hosting.Protocol;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
|
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
|
||||||
using Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@@ -107,21 +108,21 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.FileBrowser
|
|||||||
{
|
{
|
||||||
OwnerUri = liveConnection.ConnectionInfo.OwnerUri,
|
OwnerUri = liveConnection.ConnectionInfo.OwnerUri,
|
||||||
ExpandPath = "",
|
ExpandPath = "",
|
||||||
FileFilters = new string[1] { "*" }
|
FileFilters = new[] { "*" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
var efv = new EventFlowValidator<bool>()
|
||||||
service.ServiceHost = serviceHostMock.Object;
|
.AddEventValidation(FileBrowserOpenedNotification.Type, eventParams =>
|
||||||
await service.RunFileBrowserOpenTask(openParams);
|
{
|
||||||
|
Assert.True(eventParams.Succeeded);
|
||||||
// Verify complete notification event was fired and the result
|
Assert.NotNull(eventParams.FileTree);
|
||||||
serviceHostMock.Verify(x => x.SendEvent(FileBrowserOpenedNotification.Type,
|
Assert.NotNull(eventParams.FileTree.RootNode);
|
||||||
It.Is<FileBrowserOpenedParams>(p => p.Succeeded == true
|
Assert.NotNull(eventParams.FileTree.RootNode.Children);
|
||||||
&& p.FileTree != null
|
Assert.True(eventParams.FileTree.RootNode.Children.Count > 0);
|
||||||
&& p.FileTree.RootNode != null
|
})
|
||||||
&& p.FileTree.RootNode.Children != null
|
.Complete();
|
||||||
&& p.FileTree.RootNode.Children.Count > 0)),
|
await service.RunFileBrowserOpenTask(openParams, efv.Object);
|
||||||
Times.Once());
|
efv.Validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -135,17 +136,16 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.FileBrowser
|
|||||||
// Do not pass any service so that the file validator will be null
|
// Do not pass any service so that the file validator will be null
|
||||||
ServiceType = "",
|
ServiceType = "",
|
||||||
OwnerUri = liveConnection.ConnectionInfo.OwnerUri,
|
OwnerUri = liveConnection.ConnectionInfo.OwnerUri,
|
||||||
SelectedFiles = new string[] { "" }
|
SelectedFiles = new[] { "" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
var efv = new EventFlowValidator<bool>()
|
||||||
service.ServiceHost = serviceHostMock.Object;
|
.AddEventValidation(FileBrowserValidatedNotification.Type, eventParams => Assert.True(eventParams.Succeeded))
|
||||||
|
.Complete();
|
||||||
|
|
||||||
// Validate files with null file validator
|
// Validate files with null file validator
|
||||||
await service.RunFileBrowserValidateTask(validateParams);
|
await service.RunFileBrowserValidateTask(validateParams, efv.Object);
|
||||||
|
efv.Validate();
|
||||||
// Verify complete notification event was fired and the result
|
|
||||||
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidatedNotification.Type, It.Is<FileBrowserValidatedParams>(p => p.Succeeded == true)), Times.Once());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -158,22 +158,23 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.FileBrowser
|
|||||||
{
|
{
|
||||||
// Do not pass any service so that the file validator will be null
|
// Do not pass any service so that the file validator will be null
|
||||||
ServiceType = "TestService",
|
ServiceType = "TestService",
|
||||||
SelectedFiles = new string[] { "" }
|
SelectedFiles = new[] { "" }
|
||||||
};
|
};
|
||||||
|
|
||||||
var serviceHostMock = new Mock<IProtocolEndpoint>();
|
var efv = new EventFlowValidator<bool>()
|
||||||
service.ServiceHost = serviceHostMock.Object;
|
.AddEventValidation(FileBrowserValidatedNotification.Type, eventParams => Assert.False(eventParams.Succeeded))
|
||||||
|
.Complete();
|
||||||
|
|
||||||
// Validate files with null file validator
|
// Validate files with null file validator
|
||||||
await service.RunFileBrowserValidateTask(validateParams);
|
await service.RunFileBrowserValidateTask(validateParams, efv.Object);
|
||||||
|
|
||||||
// Verify complete notification event was fired and the result
|
// Verify complete notification event was fired and the result
|
||||||
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidatedNotification.Type, It.Is<FileBrowserValidatedParams>(p => p.Succeeded == false)), Times.Once());
|
efv.Validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region private methods
|
#region private methods
|
||||||
|
|
||||||
private bool ValidatePaths(FileBrowserValidateEventArgs eventArgs, out string message)
|
private static bool ValidatePaths(FileBrowserValidateEventArgs eventArgs, out string message)
|
||||||
{
|
{
|
||||||
message = string.Empty;
|
message = string.Empty;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user