mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Isolate Shared Test Code (#252)
The goal of this make sure that test code is correctly organized to ensure that test suites aren't dependent on each other.
* UnitTests get their own project now (renaming Microsoft.SqlTools.ServiceLayer.Test to Microsoft.SqlTools.ServiceLayer.UnitTests) which is about 90% of the changes to the files.
* IntegrationTests no longer depends on UnitTests, only Test.Common
* Any shared components from TestObjects that spins up a "live" connection has been moved to IntegrationTests Utility/LiveConnectionHelper.cs
* The dictionary-based mock file stream factory has been moved to Test.Common since it is used by UnitTests and IntegrationTests
* Added a overload that doesn't take a dictionary for when we don't care about monitoring the storage (about 90% of the time)
* The RunIf* wrapper methods have been moved to Test.Common
* OwnerUri and StandardQuery constants have been moved to Test.Common Constants file
* Updating to latest SDK version available at https://www.microsoft.com/net/core#windowscmd
* Moving unit tests to unit test folder
* Changing namespaces to UnitTests
* Moving some constants and shared functionality into common project, making the UnitTests reference it
* Unit tests are working!
* Integration tests are working
* Updating automated test runs
* Fixing one last broken unit test
* Exposing internals for other projects
* Moving edit data tests to UnitTest project
* Applying refactor fixes to unit tests
* Fixing flaky test that wasn't awaiting completion
This commit is contained in:
@@ -36,7 +36,7 @@ install:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- dotnet build src/Microsoft.SqlTools.ServiceLayer
|
- dotnet build src/Microsoft.SqlTools.ServiceLayer
|
||||||
- dotnet test test/Microsoft.SqlTools.ServiceLayer.Test
|
- dotnet test test/Microsoft.SqlTools.ServiceLayer.UnitTests
|
||||||
|
|
||||||
env:
|
env:
|
||||||
# Since we are building from root, current directory is the project path
|
# Since we are building from root, current directory is the project path
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ build_script:
|
|||||||
- dotnet build src/Microsoft.SqlTools.ServiceLayer
|
- dotnet build src/Microsoft.SqlTools.ServiceLayer
|
||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- dotnet test test/Microsoft.SqlTools.ServiceLayer.Test
|
- dotnet test test/Microsoft.SqlTools.ServiceLayer.UnitTests
|
||||||
|
|
||||||
after_test:
|
after_test:
|
||||||
- cd test/CodeCoverage
|
- cd test/CodeCoverage
|
||||||
|
|||||||
@@ -9,10 +9,15 @@ EndProject
|
|||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32DC973E-9EEA-4694-B1C2-B031167AB945}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32DC973E-9EEA-4694-B1C2-B031167AB945}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.gitignore = .gitignore
|
.gitignore = .gitignore
|
||||||
|
.mention-bot = .mention-bot
|
||||||
|
.travis.yml = .travis.yml
|
||||||
|
appveyor.yml = appveyor.yml
|
||||||
BUILD.md = BUILD.md
|
BUILD.md = BUILD.md
|
||||||
global.json = global.json
|
global.json = global.json
|
||||||
|
license.txt = license.txt
|
||||||
nuget.config = nuget.config
|
nuget.config = nuget.config
|
||||||
README.md = README.md
|
README.md = README.md
|
||||||
|
RefreshDllsForTestRun.cmd = RefreshDllsForTestRun.cmd
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.Credentials", "src\Microsoft.SqlTools.Credentials\Microsoft.SqlTools.Credentials.xproj", "{1D61DC2B-DA66-441D-B9D0-887798F780F9}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.Credentials", "src\Microsoft.SqlTools.Credentials\Microsoft.SqlTools.Credentials.xproj", "{1D61DC2B-DA66-441D-B9D0-887798F780F9}"
|
||||||
@@ -21,7 +26,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.Hosting"
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer", "src\Microsoft.SqlTools.ServiceLayer\Microsoft.SqlTools.ServiceLayer.xproj", "{0D61DC2B-DA66-441D-B9D0-F76C98F780F9}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer", "src\Microsoft.SqlTools.ServiceLayer\Microsoft.SqlTools.ServiceLayer.xproj", "{0D61DC2B-DA66-441D-B9D0-F76C98F780F9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.Test", "test\Microsoft.SqlTools.ServiceLayer.Test\Microsoft.SqlTools.ServiceLayer.Test.xproj", "{2D771D16-9D85-4053-9F79-E2034737DEEF}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.UnitTests", "test\Microsoft.SqlTools.ServiceLayer.UnitTests\Microsoft.SqlTools.ServiceLayer.UnitTests.xproj", "{2D771D16-9D85-4053-9F79-E2034737DEEF}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.TestDriver", "test\Microsoft.SqlTools.ServiceLayer.TestDriver\Microsoft.SqlTools.ServiceLayer.TestDriver.xproj", "{CC785604-6277-4878-8DA9-360C47158E96}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.TestDriver", "test\Microsoft.SqlTools.ServiceLayer.TestDriver\Microsoft.SqlTools.ServiceLayer.TestDriver.xproj", "{CC785604-6277-4878-8DA9-360C47158E96}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
||||||
|
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.UnitTests")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test.Common")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test.Common")]
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,6 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.UnitTests")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test.Common")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test.Common")]
|
||||||
|
|||||||
@@ -41,6 +41,6 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.UnitTests")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test.Common")]
|
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test.Common")]
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ REM rebuild the SqlToolsService project
|
|||||||
dotnet build %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json %DOTNETCONFIG%
|
dotnet build %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json %DOTNETCONFIG%
|
||||||
|
|
||||||
REM run the tests through OpenCover and generate a report
|
REM run the tests through OpenCover and generate a report
|
||||||
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.Test\project.json %DOTNETCONFIG%
|
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.UnitTests\project.json %DOTNETCONFIG%
|
||||||
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.TestDriver\project.json %DOTNETCONFIG%
|
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.TestDriver\project.json %DOTNETCONFIG%
|
||||||
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.Tests.Common\project.json %DOTNETCONFIG%
|
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.Tests.Common\project.json %DOTNETCONFIG%
|
||||||
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.IntegrationTests\project.json %DOTNETCONFIG%
|
dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.IntegrationTests\project.json %DOTNETCONFIG%
|
||||||
@@ -35,12 +35,13 @@ dotnet.exe test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.TestDriver.Tests\
|
|||||||
|
|
||||||
SET SERVICECODECOVERAGE=FALSE
|
SET SERVICECODECOVERAGE=FALSE
|
||||||
|
|
||||||
"%WORKINGDIR%packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -mergeoutput -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.TestDriver.Tests\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]* -[Microsoft.SqlTools.ServiceLayer.Test*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.TestDriver.Tests\bin\Debug\netcoreapp1.0
|
%CODECOVERAGETOOL% -mergeoutput -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.TestDriver.Tests\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]* -[Microsoft.SqlTools.ServiceLayer.Test*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.TestDriver.Tests\bin\Debug\netcoreapp1.0
|
||||||
|
|
||||||
"%WORKINGDIR%packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -mergeoutput -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]* -[Microsoft.SqlTools.ServiceLayer.Test*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\bin\Debug\netcoreapp1.0
|
%CODECOVERAGETOOL% -mergeoutput -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.UnitTests\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]* -[Microsoft.SqlTools.ServiceLayer.Test*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.UnitTests\bin\Debug\netcoreapp1.0
|
||||||
|
|
||||||
"%WORKINGDIR%packages\OpenCover.4.6.519\tools\OpenCover.Console.exe" -mergeoutput -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.IntegrationTests\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]* -[Microsoft.SqlTools.ServiceLayer.Test*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.IntegrationTests\bin\Debug\netcoreapp1.0
|
%CODECOVERAGETOOL% -mergeoutput -register:user -target:dotnet.exe -targetargs:"test %WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.IntegrationTests\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]* -[Microsoft.SqlTools.ServiceLayer.Test*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.IntegrationTests\bin\Debug\netcoreapp1.0
|
||||||
|
|
||||||
|
REM Generate the report
|
||||||
"%WORKINGDIR%packages\OpenCoverToCoberturaConverter.0.2.4.0\tools\OpenCoverToCoberturaConverter.exe" -input:coverage.xml -output:outputCobertura.xml -sources:%WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer
|
"%WORKINGDIR%packages\OpenCoverToCoberturaConverter.0.2.4.0\tools\OpenCoverToCoberturaConverter.exe" -input:coverage.xml -output:outputCobertura.xml -sources:%WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer
|
||||||
"%WORKINGDIR%packages\ReportGenerator.2.4.5.0\tools\ReportGenerator.exe" "-reports:coverage.xml" "-targetdir:%WORKINGDIR%\reports"
|
"%WORKINGDIR%packages\ReportGenerator.2.4.5.0\tools\ReportGenerator.exe" "-reports:coverage.xml" "-targetdir:%WORKINGDIR%\reports"
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,14 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
||||||
{
|
{
|
||||||
@@ -30,7 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
service.OwnerToConnectionMap.Clear();
|
service.OwnerToConnectionMap.Clear();
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connectionInfo = result.ConnectionInfo;
|
ConnectionInfo connectionInfo = result.ConnectionInfo;
|
||||||
string uri = connectionInfo.OwnerUri;
|
string uri = connectionInfo.OwnerUri;
|
||||||
|
|
||||||
@@ -39,8 +36,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
Assert.Equal(1, service.OwnerToConnectionMap.Count);
|
Assert.Equal(1, service.OwnerToConnectionMap.Count);
|
||||||
|
|
||||||
// If we run a query
|
// If we run a query
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(Common.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
|
|
||||||
@@ -48,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
Assert.Equal(2, connectionInfo.CountConnections);
|
Assert.Equal(2, connectionInfo.CountConnections);
|
||||||
|
|
||||||
// If we run another query
|
// If we run another query
|
||||||
query = new Query(Common.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
|
|
||||||
@@ -69,7 +66,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
{
|
{
|
||||||
// If we make a connection to a live database
|
// If we make a connection to a live database
|
||||||
ConnectionService service = ConnectionService.Instance;
|
ConnectionService service = ConnectionService.Instance;
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connectionInfo = result.ConnectionInfo;
|
ConnectionInfo connectionInfo = result.ConnectionInfo;
|
||||||
ConnectionDetails details = connectionInfo.ConnectionDetails;
|
ConnectionDetails details = connectionInfo.ConnectionDetails;
|
||||||
string uri = connectionInfo.OwnerUri;
|
string uri = connectionInfo.OwnerUri;
|
||||||
@@ -78,8 +75,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
string changeDatabaseQuery = "use " + newDatabaseName;
|
string changeDatabaseQuery = "use " + newDatabaseName;
|
||||||
|
|
||||||
// Then run any query to create a query DbConnection
|
// Then run any query to create a query DbConnection
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(Common.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(Constants.StandardQuery, connectionInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,11 @@ using System.Data;
|
|||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.ReliableConnectionHelper;
|
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.ReliableConnectionHelper;
|
||||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy;
|
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy;
|
||||||
@@ -451,7 +446,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void RetryPolicyFactoryConstructsPoliciesSuccessfully()
|
public void RetryPolicyFactoryConstructsPoliciesSuccessfully()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(RetryPolicyFactory.CreateColumnEncryptionTransferRetryPolicy());
|
Assert.NotNull(RetryPolicyFactory.CreateColumnEncryptionTransferRetryPolicy());
|
||||||
Assert.NotNull(RetryPolicyFactory.CreateDatabaseCommandRetryPolicy());
|
Assert.NotNull(RetryPolicyFactory.CreateDatabaseCommandRetryPolicy());
|
||||||
@@ -539,7 +534,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void TestTryGetServerVersionInvalidConnectionString()
|
public void TestTryGetServerVersionInvalidConnectionString()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
ReliableConnectionHelper.ServerInfo info = null;
|
ReliableConnectionHelper.ServerInfo info = null;
|
||||||
Assert.False(ReliableConnectionHelper.TryGetServerVersion("this is not a valid connstr", out info));
|
Assert.False(ReliableConnectionHelper.TryGetServerVersion("this is not a valid connstr", out info));
|
||||||
@@ -681,7 +676,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void ReliableConnectionHelperTest()
|
public void ReliableConnectionHelperTest()
|
||||||
{
|
{
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||||
DbConnection connection = connInfo.ConnectionTypeToConnectionMap[ConnectionType.Default];
|
DbConnection connection = connInfo.ConnectionTypeToConnectionMap[ConnectionType.Default];
|
||||||
|
|
||||||
@@ -726,7 +721,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void InitReliableSqlConnectionTest()
|
public void InitReliableSqlConnectionTest()
|
||||||
{
|
{
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||||
DbConnection dbConnection;
|
DbConnection dbConnection;
|
||||||
connInfo.TryGetConnection(ConnectionType.Default, out dbConnection);
|
connInfo.TryGetConnection(ConnectionType.Default, out dbConnection);
|
||||||
|
|||||||
@@ -5,14 +5,11 @@
|
|||||||
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
||||||
@@ -22,11 +19,11 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class LanguageServiceTests
|
public class LanguageServiceTests
|
||||||
{
|
{
|
||||||
private TestConnectionResult GetLiveAutoCompleteTestObjects()
|
private LiveConnectionHelper.TestConnectionResult GetLiveAutoCompleteTestObjects()
|
||||||
{
|
{
|
||||||
var textDocument = new TextDocumentPosition
|
var textDocument = new TextDocumentPosition
|
||||||
{
|
{
|
||||||
TextDocument = new TextDocumentIdentifier { Uri = TestObjects.ScriptUri },
|
TextDocument = new TextDocumentIdentifier { Uri = Constants.OwnerUri },
|
||||||
Position = new Position
|
Position = new Position
|
||||||
{
|
{
|
||||||
Line = 0,
|
Line = 0,
|
||||||
@@ -34,7 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
result.TextDocumentPosition = textDocument;
|
result.TextDocumentPosition = textDocument;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -66,7 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void PrepopulateCommonMetadata()
|
public void PrepopulateCommonMetadata()
|
||||||
{
|
{
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
var connInfo = result.ConnectionInfo;
|
var connInfo = result.ConnectionInfo;
|
||||||
|
|
||||||
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
|
||||||
@@ -104,7 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
{
|
{
|
||||||
// When we make a connection to a live database
|
// When we make a connection to a live database
|
||||||
Hosting.ServiceHost.SendEventIgnoreExceptions = true;
|
Hosting.ServiceHost.SendEventIgnoreExceptions = true;
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
|
|
||||||
// And we place the cursor after a function that should prompt for signature help
|
// And we place the cursor after a function that should prompt for signature help
|
||||||
string queryWithFunction = "EXEC sys.fn_isrolemember ";
|
string queryWithFunction = "EXEC sys.fn_isrolemember ";
|
||||||
@@ -142,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void OverwriteBindingContext()
|
public void OverwriteBindingContext()
|
||||||
{
|
{
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
|
|
||||||
// add a new connection context
|
// add a new connection context
|
||||||
var connectionKey = LanguageService.Instance.BindingQueue.AddConnectionContext(result.ConnectionInfo, overwrite: true);
|
var connectionKey = LanguageService.Instance.BindingQueue.AddConnectionContext(result.ConnectionInfo, overwrite: true);
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ using System;
|
|||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using ConnectionType = Microsoft.SqlTools.ServiceLayer.Connection.ConnectionType;
|
using ConnectionType = Microsoft.SqlTools.ServiceLayer.Connection.ConnectionType;
|
||||||
@@ -86,8 +85,8 @@ GO";
|
|||||||
public void GetValidTableDefinitionTest()
|
public void GetValidTableDefinitionTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "spt_monitor";
|
string objectName = "spt_monitor";
|
||||||
@@ -108,8 +107,8 @@ GO";
|
|||||||
public void GetTableDefinitionInvalidObjectTest()
|
public void GetTableDefinitionInvalidObjectTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "test_invalid";
|
string objectName = "test_invalid";
|
||||||
@@ -128,8 +127,8 @@ GO";
|
|||||||
public void GetTableDefinitionWithSchemaTest()
|
public void GetTableDefinitionWithSchemaTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "spt_monitor";
|
string objectName = "spt_monitor";
|
||||||
@@ -147,10 +146,10 @@ GO";
|
|||||||
/// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
|
/// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetUnsupportedDefinitionErrorTest()
|
public void GetUnsupportedDefinitionErrorTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "objects";
|
string objectName = "objects";
|
||||||
@@ -168,8 +167,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDefinitionWithNoResultsFoundError()
|
public void GetDefinitionWithNoResultsFoundError()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "from";
|
string objectName = "from";
|
||||||
@@ -226,7 +225,7 @@ GO";
|
|||||||
Character = 20
|
Character = 20
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TestConnectionResult connectionResult = TestObjects.InitLiveConnectionInfo();
|
LiveConnectionHelper.TestConnectionResult connectionResult = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ScriptFile scriptFile = connectionResult.ScriptFile;
|
ScriptFile scriptFile = connectionResult.ScriptFile;
|
||||||
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
ConnectionInfo connInfo = connectionResult.ConnectionInfo;
|
||||||
scriptFile.Contents = "select * from dbo.func ()";
|
scriptFile.Contents = "select * from dbo.func ()";
|
||||||
@@ -250,8 +249,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetValidViewDefinitionTest()
|
public void GetValidViewDefinitionTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "objects";
|
string objectName = "objects";
|
||||||
@@ -270,8 +269,8 @@ GO";
|
|||||||
public void GetViewDefinitionInvalidObjectTest()
|
public void GetViewDefinitionInvalidObjectTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "objects";
|
string objectName = "objects";
|
||||||
@@ -289,8 +288,8 @@ GO";
|
|||||||
public void GetStoredProcedureDefinitionTest()
|
public void GetStoredProcedureDefinitionTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "sp_MSrepl_startup";
|
string objectName = "sp_MSrepl_startup";
|
||||||
@@ -310,8 +309,8 @@ GO";
|
|||||||
public void GetStoredProcedureDefinitionFailureTest()
|
public void GetStoredProcedureDefinitionFailureTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "SP2";
|
string objectName = "SP2";
|
||||||
@@ -329,8 +328,8 @@ GO";
|
|||||||
public void GetStoredProcedureDefinitionWithoutSchemaTest()
|
public void GetStoredProcedureDefinitionWithoutSchemaTest()
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "sp_MSrepl_startup";
|
string objectName = "sp_MSrepl_startup";
|
||||||
@@ -369,8 +368,8 @@ GO";
|
|||||||
private void ValidatePeekTest(string databaseName, string objectName, string objectType, string schemaName, bool shouldReturnValidResult)
|
private void ValidatePeekTest(string databaseName, string objectName, string objectType, string schemaName, bool shouldReturnValidResult)
|
||||||
{
|
{
|
||||||
// Get live connectionInfo and serverConnection
|
// Get live connectionInfo and serverConnection
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition(databaseName);
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition(databaseName);
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
|
|
||||||
@@ -571,8 +570,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDefinitionUsingDeclarationTypeWithValidObjectTest()
|
public void GetDefinitionUsingDeclarationTypeWithValidObjectTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "objects";
|
string objectName = "objects";
|
||||||
@@ -593,8 +592,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDefinitionUsingDeclarationTypeWithNonexistentObjectTest()
|
public void GetDefinitionUsingDeclarationTypeWithNonexistentObjectTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "doesNotExist";
|
string objectName = "doesNotExist";
|
||||||
@@ -612,8 +611,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDefinitionUsingQuickInfoTextWithValidObjectTest()
|
public void GetDefinitionUsingQuickInfoTextWithValidObjectTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "objects";
|
string objectName = "objects";
|
||||||
@@ -635,8 +634,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDefinitionUsingQuickInfoTextWithNonexistentObjectTest()
|
public void GetDefinitionUsingQuickInfoTextWithNonexistentObjectTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
|
|
||||||
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
|
||||||
string objectName = "doesNotExist";
|
string objectName = "doesNotExist";
|
||||||
@@ -656,8 +655,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDatabaseWithNoQueryConnectionTest()
|
public void GetDatabaseWithNoQueryConnectionTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
DbConnection connection;
|
DbConnection connection;
|
||||||
//Check if query connection is present
|
//Check if query connection is present
|
||||||
Assert.False(connInfo.TryGetConnection(ConnectionType.Query, out connection));
|
Assert.False(connInfo.TryGetConnection(ConnectionType.Query, out connection));
|
||||||
@@ -675,8 +674,8 @@ GO";
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void GetDatabaseWithQueryConnectionTest()
|
public void GetDatabaseWithQueryConnectionTest()
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition();
|
||||||
ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
|
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||||
//Mock a query connection object
|
//Mock a query connection object
|
||||||
var mockQueryConnection = new Mock<DbConnection> { CallBase = true };
|
var mockQueryConnection = new Mock<DbConnection> { CallBase = true };
|
||||||
mockQueryConnection.SetupGet(x => x.Database).Returns("testdb");
|
mockQueryConnection.SetupGet(x => x.Database).Returns("testdb");
|
||||||
|
|||||||
@@ -5,11 +5,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataStorage
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataStorage
|
||||||
@@ -18,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataSt
|
|||||||
{
|
{
|
||||||
private StorageDataReader GetTestStorageDataReader(string query)
|
private StorageDataReader GetTestStorageDataReader(string query)
|
||||||
{
|
{
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
DbConnection connection;
|
DbConnection connection;
|
||||||
result.ConnectionInfo.TryGetConnection(ConnectionType.Default, out connection);
|
result.ConnectionInfo.TryGetConnection(ConnectionType.Default, out connection);
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
||||||
@@ -22,9 +19,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
|||||||
const string refactorText = "ROLLBACK TRANSACTION";
|
const string refactorText = "ROLLBACK TRANSACTION";
|
||||||
|
|
||||||
// Given a connection to a live database
|
// Given a connection to a live database
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
|
|
||||||
// If I run a "ROLLBACK TRANSACTION" query
|
// If I run a "ROLLBACK TRANSACTION" query
|
||||||
Query query = new Query(refactorText, connInfo, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(refactorText, connInfo, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
@@ -42,9 +39,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
|||||||
const string rollbackText = "ROLLBACK TRANSACTION";
|
const string rollbackText = "ROLLBACK TRANSACTION";
|
||||||
|
|
||||||
// Given a connection to a live database
|
// Given a connection to a live database
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
|
|
||||||
// If I run a "BEGIN TRANSACTION" query
|
// If I run a "BEGIN TRANSACTION" query
|
||||||
CreateAndExecuteQuery(beginText, connInfo, fileStreamFactory);
|
CreateAndExecuteQuery(beginText, connInfo, fileStreamFactory);
|
||||||
@@ -61,9 +58,9 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
|||||||
const string insertTempText = "INSERT INTO #someTempTable VALUES(1)";
|
const string insertTempText = "INSERT INTO #someTempTable VALUES(1)";
|
||||||
|
|
||||||
// Given a connection to a live database
|
// Given a connection to a live database
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||||
|
|
||||||
// If I run a query creating a temp table
|
// If I run a query creating a temp table
|
||||||
CreateAndExecuteQuery(createTempText, connInfo, fileStreamFactory);
|
CreateAndExecuteQuery(createTempText, connInfo, fileStreamFactory);
|
||||||
@@ -81,12 +78,12 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution
|
|||||||
const string useQuery = "USE {0}";
|
const string useQuery = "USE {0}";
|
||||||
|
|
||||||
// Given a connection to a live database
|
// Given a connection to a live database
|
||||||
var result = TestObjects.InitLiveConnectionInfo();
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
ConnectionInfo connInfo = result.ConnectionInfo;
|
ConnectionInfo connInfo = result.ConnectionInfo;
|
||||||
DbConnection connection;
|
DbConnection connection;
|
||||||
connInfo.TryGetConnection(ConnectionType.Default, out connection);
|
connInfo.TryGetConnection(ConnectionType.Default, out connection);
|
||||||
|
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||||
|
|
||||||
// If I use master, the current database should be master
|
// If I use master, the current database should be master
|
||||||
CreateAndExecuteQuery(string.Format(useQuery, master), connInfo, fileStreamFactory);
|
CreateAndExecuteQuery(string.Format(useQuery, master), connInfo, fileStreamFactory);
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ using System.Data.SqlClient;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode;
|
using Microsoft.SqlTools.ServiceLayer.BatchParser.ExecutionEngineCode;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.TSQLExecutionEngine
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.TSQLExecutionEngine
|
||||||
@@ -46,7 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.TSQLExecutionEngine
|
|||||||
private SqlConnection SetUpConnection(string name)
|
private SqlConnection SetUpConnection(string name)
|
||||||
{
|
{
|
||||||
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, name);
|
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, name);
|
||||||
ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition(testDb.DatabaseName);
|
ConnectionInfo connInfo = LiveConnectionHelper.InitLiveConnectionInfoForDefinition(testDb.DatabaseName);
|
||||||
string connectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
|
string connectionString = ConnectionService.BuildConnectionString(connInfo.ConnectionDetails);
|
||||||
SqlConnection resultConnection = new SqlConnection(connectionString);
|
SqlConnection resultConnection = new SqlConnection(connectionString);
|
||||||
resultConnection.Open();
|
resultConnection.Open();
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
using System.Data.SqlClient;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using Microsoft.SqlServer.Management.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||||
|
{
|
||||||
|
public class LiveConnectionHelper
|
||||||
|
{
|
||||||
|
public static string GetTestSqlFile()
|
||||||
|
{
|
||||||
|
string filePath = Path.Combine(
|
||||||
|
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
|
||||||
|
"sqltest.sql");
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
{
|
||||||
|
File.Delete(filePath);
|
||||||
|
}
|
||||||
|
File.WriteAllText(filePath, "SELECT * FROM sys.objects\n");
|
||||||
|
return filePath;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestConnectionResult InitLiveConnectionInfo()
|
||||||
|
{
|
||||||
|
string sqlFilePath = GetTestSqlFile();
|
||||||
|
ScriptFile scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(sqlFilePath);
|
||||||
|
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem);
|
||||||
|
|
||||||
|
string ownerUri = scriptFile.ClientFilePath;
|
||||||
|
var connectionService = GetLiveTestConnectionService();
|
||||||
|
var connectionResult =
|
||||||
|
connectionService
|
||||||
|
.Connect(new ConnectParams
|
||||||
|
{
|
||||||
|
OwnerUri = ownerUri,
|
||||||
|
Connection = connectParams.Connection
|
||||||
|
});
|
||||||
|
|
||||||
|
connectionResult.Wait();
|
||||||
|
|
||||||
|
ConnectionInfo connInfo = null;
|
||||||
|
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||||
|
return new TestConnectionResult() { ConnectionInfo = connInfo, ScriptFile = scriptFile };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConnectionInfo InitLiveConnectionInfoForDefinition(string databaseName = null)
|
||||||
|
{
|
||||||
|
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||||
|
const string ScriptUriTemplate = "file://some/{0}.sql";
|
||||||
|
string ownerUri = string.Format(CultureInfo.InvariantCulture, ScriptUriTemplate, string.IsNullOrEmpty(databaseName) ? "file" : databaseName);
|
||||||
|
var connectionService = GetLiveTestConnectionService();
|
||||||
|
var connectionResult =
|
||||||
|
connectionService
|
||||||
|
.Connect(new ConnectParams
|
||||||
|
{
|
||||||
|
OwnerUri = ownerUri,
|
||||||
|
Connection = connectParams.Connection
|
||||||
|
});
|
||||||
|
|
||||||
|
connectionResult.Wait();
|
||||||
|
|
||||||
|
ConnectionInfo connInfo = null;
|
||||||
|
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||||
|
|
||||||
|
Assert.NotNull(connInfo);
|
||||||
|
return connInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerConnection InitLiveServerConnectionForDefinition(ConnectionInfo connInfo)
|
||||||
|
{
|
||||||
|
SqlConnection sqlConn = new SqlConnection(ConnectionService.BuildConnectionString(connInfo.ConnectionDetails));
|
||||||
|
return new ServerConnection(sqlConn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a test sql connection factory instance
|
||||||
|
/// </summary>
|
||||||
|
public static ISqlConnectionFactory GetLiveTestSqlConnectionFactory()
|
||||||
|
{
|
||||||
|
// connect to a real server instance
|
||||||
|
return ConnectionService.Instance.ConnectionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConnectionService GetLiveTestConnectionService()
|
||||||
|
{
|
||||||
|
// connect to a real server instance
|
||||||
|
return ConnectionService.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestConnectionResult
|
||||||
|
{
|
||||||
|
public ConnectionInfo ConnectionInfo { get; set; }
|
||||||
|
|
||||||
|
public ScriptFile ScriptFile { get; set; }
|
||||||
|
|
||||||
|
public TextDocumentPosition TextDocumentPosition { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
"Moq": "4.6.36-alpha",
|
"Moq": "4.6.36-alpha",
|
||||||
"Microsoft.SqlTools.ServiceLayer.Test": "1.0.0-*"
|
"Microsoft.SqlTools.ServiceLayer.Test.Common": "1.0.0-*"
|
||||||
},
|
},
|
||||||
"testRunner": "xunit",
|
"testRunner": "xunit",
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
|
|||||||
@@ -30,5 +30,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
public const string BVTLocalRoot = "BVT_LOCALROOT";
|
public const string BVTLocalRoot = "BVT_LOCALROOT";
|
||||||
|
|
||||||
public const string DBIMode = "DBI_MODE";
|
public const string DBIMode = "DBI_MODE";
|
||||||
|
|
||||||
|
public const string OwnerUri = "testFile";
|
||||||
|
|
||||||
|
public const string StandardQuery = "SELECT * FROM sys.objects";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Moq;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||||
|
{
|
||||||
|
public class MemoryFileSystem
|
||||||
|
{
|
||||||
|
|
||||||
|
public static IFileStreamFactory GetFileStreamFactory()
|
||||||
|
{
|
||||||
|
return GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IFileStreamFactory GetFileStreamFactory(Dictionary<string, byte[]> storage)
|
||||||
|
{
|
||||||
|
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
||||||
|
mock.Setup(fsf => fsf.CreateFile())
|
||||||
|
.Returns(() =>
|
||||||
|
{
|
||||||
|
string fileName = Guid.NewGuid().ToString();
|
||||||
|
storage.Add(fileName, new byte[8192]);
|
||||||
|
return fileName;
|
||||||
|
});
|
||||||
|
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))
|
||||||
|
.Returns<string>(output => new ServiceBufferFileStreamReader(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
||||||
|
mock.Setup(fsf => fsf.GetWriter(It.IsAny<string>()))
|
||||||
|
.Returns<string>(output => new ServiceBufferFileStreamWriter(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
||||||
|
|
||||||
|
return mock.Object;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// 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.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||||
|
{
|
||||||
|
public class RunIfWrapper
|
||||||
|
{
|
||||||
|
public static void RunIfLinux(Action test)
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RunIfLinuxOrOSX(Action test)
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RunIfWindows(Action test)
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,18 +4,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Moq;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
||||||
@@ -74,7 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, queryTempFile.FilePath);
|
ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, queryTempFile.FilePath);
|
||||||
Query query = new Query(queryText, connInfo, new QueryExecutionSettings(), GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Query query = new Query(queryText, connInfo, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory());
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
}
|
}
|
||||||
@@ -100,24 +95,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
return connInfo;
|
return connInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IFileStreamFactory GetFileStreamFactory(Dictionary<string, byte[]> storage)
|
|
||||||
{
|
|
||||||
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
|
||||||
mock.Setup(fsf => fsf.CreateFile())
|
|
||||||
.Returns(() =>
|
|
||||||
{
|
|
||||||
string fileName = Guid.NewGuid().ToString();
|
|
||||||
storage.Add(fileName, new byte[8192]);
|
|
||||||
return fileName;
|
|
||||||
});
|
|
||||||
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))
|
|
||||||
.Returns<string>(output => new ServiceBufferFileStreamReader(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
|
||||||
mock.Setup(fsf => fsf.GetWriter(It.IsAny<string>()))
|
|
||||||
.Returns<string>(output => new ServiceBufferFileStreamWriter(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
|
||||||
|
|
||||||
return mock.Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool hasInitServices = false;
|
private static bool hasInitServices = false;
|
||||||
|
|
||||||
private static void InitializeTestServices()
|
private static void InitializeTestServices()
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright (c) Microsoft. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
//
|
|
||||||
|
|
||||||
//#define USE_LIVE_CONNECTION
|
|
||||||
|
|
||||||
using System.Data.Common;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|
||||||
{
|
|
||||||
public class ExecuteTests
|
|
||||||
{
|
|
||||||
|
|
||||||
#if USE_LIVE_CONNECTION
|
|
||||||
[Fact]
|
|
||||||
public void QueryUdtShouldNotRetry()
|
|
||||||
{
|
|
||||||
// If:
|
|
||||||
// ... I create a query with a udt column in the result set
|
|
||||||
ConnectionInfo connectionInfo = TestObjects.GetTestConnectionInfo();
|
|
||||||
Query query = new Query(Common.UdtQuery, connectionInfo, new QueryExecutionSettings(), Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
|
||||||
|
|
||||||
// If:
|
|
||||||
// ... I then execute the query
|
|
||||||
DateTime startTime = DateTime.Now;
|
|
||||||
query.Execute();
|
|
||||||
query.ExecutionTask.Wait();
|
|
||||||
|
|
||||||
// Then:
|
|
||||||
// ... The query should complete within 2 seconds since retry logic should not kick in
|
|
||||||
Assert.True(DateTime.Now.Subtract(startTime) < TimeSpan.FromSeconds(2), "Query completed slower than expected, did retry logic execute?");
|
|
||||||
|
|
||||||
// Then:
|
|
||||||
// ... There should be an error on the batch
|
|
||||||
Assert.True(query.HasExecuted);
|
|
||||||
Assert.NotEmpty(query.BatchSummaries);
|
|
||||||
Assert.Equal(1, query.BatchSummaries.Length);
|
|
||||||
Assert.True(query.BatchSummaries[0].HasError);
|
|
||||||
Assert.NotEmpty(query.BatchSummaries[0].Messages);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Completion
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Completion
|
||||||
{
|
{
|
||||||
public class AutoCompletionResultTest
|
public class AutoCompletionResultTest
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,7 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Completion
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Completion
|
||||||
{
|
{
|
||||||
public class ScriptDocumentInfoTest
|
public class ScriptDocumentInfoTest
|
||||||
{
|
{
|
||||||
@@ -3,11 +3,10 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
|
||||||
using Xunit;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for Sever Information Caching Class
|
/// Tests for Sever Information Caching Class
|
||||||
@@ -14,13 +14,13 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the ServiceHost Connection Service tests
|
/// Tests for the ServiceHost Connection Service tests
|
||||||
@@ -249,8 +249,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
/// provided as a parameter.
|
/// provided as a parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineDataAttribute(null)]
|
[InlineData(null)]
|
||||||
[InlineDataAttribute("")]
|
[InlineData("")]
|
||||||
public async Task CanConnectWithEmptyDatabaseName(string databaseName)
|
public async Task CanConnectWithEmptyDatabaseName(string databaseName)
|
||||||
{
|
{
|
||||||
// Connect
|
// Connect
|
||||||
@@ -273,8 +273,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
/// provided as a parameter.
|
/// provided as a parameter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineDataAttribute("master")]
|
[InlineData("master")]
|
||||||
[InlineDataAttribute("nonMasterDb")]
|
[InlineData("nonMasterDb")]
|
||||||
public async Task ConnectToDefaultDatabaseRespondsWithActualDbName(string expectedDbName)
|
public async Task ConnectToDefaultDatabaseRespondsWithActualDbName(string expectedDbName)
|
||||||
{
|
{
|
||||||
// Given connecting with empty database name will return the expected DB name
|
// Given connecting with empty database name will return the expected DB name
|
||||||
@@ -701,8 +701,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
/// Test that disconnecting validates parameters and doesn't succeed when they are invalid
|
/// Test that disconnecting validates parameters and doesn't succeed when they are invalid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineDataAttribute(null)]
|
[InlineData(null)]
|
||||||
[InlineDataAttribute("")]
|
[InlineData("")]
|
||||||
|
|
||||||
public async Task DisconnectValidatesParameters(string disconnectUri)
|
public async Task DisconnectValidatesParameters(string disconnectUri)
|
||||||
{
|
{
|
||||||
@@ -869,7 +869,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void TestThatLinuxAndOsxSqlExceptionHasNoErrorCode()
|
public void TestThatLinuxAndOsxSqlExceptionHasNoErrorCode()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfLinuxOrOSX(() =>
|
RunIfWrapper.RunIfLinuxOrOSX(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -10,12 +10,10 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Credentials.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Linux;
|
using Microsoft.SqlTools.ServiceLayer.Credentials.Linux;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
|
||||||
using Moq;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Credential Service tests that should pass on all platforms, regardless of backing store.
|
/// Credential Service tests that should pass on all platforms, regardless of backing store.
|
||||||
@@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Linux;
|
using Microsoft.SqlTools.ServiceLayer.Credentials.Linux;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials.Linux
|
||||||
{
|
{
|
||||||
public class LinuxInteropTests
|
public class LinuxInteropTests
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
public void GetEUidReturnsInt()
|
public void GetEUidReturnsInt()
|
||||||
{
|
{
|
||||||
#if !WINDOWS_ONLY_BUILD
|
#if !WINDOWS_ONLY_BUILD
|
||||||
TestUtils.RunIfLinux(() =>
|
RunIfWrapper.RunIfLinux(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(Interop.Sys.GetEUid());
|
Assert.NotNull(Interop.Sys.GetEUid());
|
||||||
});
|
});
|
||||||
@@ -27,7 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
public void GetHomeDirectoryFromPwFindsHomeDir()
|
public void GetHomeDirectoryFromPwFindsHomeDir()
|
||||||
{
|
{
|
||||||
#if !WINDOWS_ONLY_BUILD
|
#if !WINDOWS_ONLY_BUILD
|
||||||
TestUtils.RunIfLinux(() =>
|
RunIfWrapper.RunIfLinux(() =>
|
||||||
{
|
{
|
||||||
string userDir = LinuxCredentialStore.GetHomeDirectoryFromPw();
|
string userDir = LinuxCredentialStore.GetHomeDirectoryFromPw();
|
||||||
Assert.StartsWith("/", userDir);
|
Assert.StartsWith("/", userDir);
|
||||||
@@ -5,17 +5,17 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Win32;
|
using Microsoft.SqlTools.ServiceLayer.Credentials.Win32;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials.Win32
|
||||||
{
|
{
|
||||||
public class CredentialSetTests
|
public class CredentialSetTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CredentialSetCreate()
|
public void CredentialSetCreate()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(new CredentialSet());
|
Assert.NotNull(new CredentialSet());
|
||||||
});
|
});
|
||||||
@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CredentialSetCreateWithTarget()
|
public void CredentialSetCreateWithTarget()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(new CredentialSet("target"));
|
Assert.NotNull(new CredentialSet("target"));
|
||||||
});
|
});
|
||||||
@@ -33,7 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CredentialSetShouldBeIDisposable()
|
public void CredentialSetShouldBeIDisposable()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.True(new CredentialSet() is IDisposable, "CredentialSet needs to implement IDisposable Interface.");
|
Assert.True(new CredentialSet() is IDisposable, "CredentialSet needs to implement IDisposable Interface.");
|
||||||
});
|
});
|
||||||
@@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CredentialSetLoad()
|
public void CredentialSetLoad()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Win32Credential credential = new Win32Credential
|
Win32Credential credential = new Win32Credential
|
||||||
{
|
{
|
||||||
@@ -67,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CredentialSetLoadShouldReturnSelf()
|
public void CredentialSetLoadShouldReturnSelf()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
CredentialSet set = new CredentialSet();
|
CredentialSet set = new CredentialSet();
|
||||||
Assert.IsType<CredentialSet>(set.Load());
|
Assert.IsType<CredentialSet>(set.Load());
|
||||||
@@ -79,7 +79,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CredentialSetLoadWithTargetFilter()
|
public void CredentialSetLoadWithTargetFilter()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Win32Credential credential = new Win32Credential
|
Win32Credential credential = new Win32Credential
|
||||||
{
|
{
|
||||||
@@ -5,17 +5,17 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Credentials.Win32;
|
using Microsoft.SqlTools.ServiceLayer.Credentials.Win32;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials.Win32
|
||||||
{
|
{
|
||||||
public class Win32CredentialTests
|
public class Win32CredentialTests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Create_ShouldNotThrowNull()
|
public void Credential_Create_ShouldNotThrowNull()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(new Win32Credential());
|
Assert.NotNull(new Win32Credential());
|
||||||
});
|
});
|
||||||
@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Create_With_Username_ShouldNotThrowNull()
|
public void Credential_Create_With_Username_ShouldNotThrowNull()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(new Win32Credential("username"));
|
Assert.NotNull(new Win32Credential("username"));
|
||||||
});
|
});
|
||||||
@@ -33,7 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Create_With_Username_And_Password_ShouldNotThrowNull()
|
public void Credential_Create_With_Username_And_Password_ShouldNotThrowNull()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(new Win32Credential("username", "password"));
|
Assert.NotNull(new Win32Credential("username", "password"));
|
||||||
});
|
});
|
||||||
@@ -42,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Create_With_Username_Password_Target_ShouldNotThrowNull()
|
public void Credential_Create_With_Username_Password_Target_ShouldNotThrowNull()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.NotNull(new Win32Credential("username", "password", "target"));
|
Assert.NotNull(new Win32Credential("username", "password", "target"));
|
||||||
});
|
});
|
||||||
@@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_ShouldBe_IDisposable()
|
public void Credential_ShouldBe_IDisposable()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Assert.True(new Win32Credential() is IDisposable, "Credential should implement IDisposable Interface.");
|
Assert.True(new Win32Credential() is IDisposable, "Credential should implement IDisposable Interface.");
|
||||||
});
|
});
|
||||||
@@ -60,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Dispose_ShouldNotThrowException()
|
public void Credential_Dispose_ShouldNotThrowException()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
new Win32Credential().Dispose();
|
new Win32Credential().Dispose();
|
||||||
});
|
});
|
||||||
@@ -69,7 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_ShouldThrowObjectDisposedException()
|
public void Credential_ShouldThrowObjectDisposedException()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Win32Credential disposed = new Win32Credential { Password = "password" };
|
Win32Credential disposed = new Win32Credential { Password = "password" };
|
||||||
disposed.Dispose();
|
disposed.Dispose();
|
||||||
@@ -80,7 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Save()
|
public void Credential_Save()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Win32Credential saved = new Win32Credential("username", "password", "target", CredentialType.Generic);
|
Win32Credential saved = new Win32Credential("username", "password", "target", CredentialType.Generic);
|
||||||
saved.PersistanceType = PersistanceType.LocalComputer;
|
saved.PersistanceType = PersistanceType.LocalComputer;
|
||||||
@@ -91,7 +91,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Delete()
|
public void Credential_Delete()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
new Win32Credential("username", "password", "target").Save();
|
new Win32Credential("username", "password", "target").Save();
|
||||||
Assert.True(new Win32Credential("username", "password", "target").Delete());
|
Assert.True(new Win32Credential("username", "password", "target").Delete());
|
||||||
@@ -101,7 +101,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Delete_NullTerminator()
|
public void Credential_Delete_NullTerminator()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Win32Credential credential = new Win32Credential((string)null, (string)null, "\0", CredentialType.None);
|
Win32Credential credential = new Win32Credential((string)null, (string)null, "\0", CredentialType.None);
|
||||||
credential.Description = (string)null;
|
credential.Description = (string)null;
|
||||||
@@ -112,7 +112,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Load()
|
public void Credential_Load()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
Win32Credential setup = new Win32Credential("username", "password", "target", CredentialType.Generic);
|
Win32Credential setup = new Win32Credential("username", "password", "target", CredentialType.Generic);
|
||||||
setup.Save();
|
setup.Save();
|
||||||
@@ -131,7 +131,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Credentials
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Credential_Exists_Target_ShouldNotBeNull()
|
public void Credential_Exists_Target_ShouldNotBeNull()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfWindows(() =>
|
RunIfWrapper.RunIfWindows(() =>
|
||||||
{
|
{
|
||||||
new Win32Credential { Username = "username", Password = "password", Target = "target" }.Save();
|
new Win32Credential { Username = "username", Password = "password", Target = "target" }.Save();
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class CellUpdateTests
|
public class CellUpdateTests
|
||||||
{
|
{
|
||||||
@@ -11,11 +11,12 @@ using Microsoft.SqlTools.ServiceLayer.EditData;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class Common
|
public class Common
|
||||||
{
|
{
|
||||||
@@ -75,7 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
: new[] { new object[] { "1", "2", "3" } };
|
: new[] { new object[] { "1", "2", "3" } };
|
||||||
var testResultSet = new TestResultSet(columns, rows);
|
var testResultSet = new TestResultSet(columns, rows);
|
||||||
var reader = new TestDbDataReader(new[] { testResultSet });
|
var reader = new TestDbDataReader(new[] { testResultSet });
|
||||||
var resultSet = new ResultSet(reader, 0, 0, QueryExecution.Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
var resultSet = new ResultSet(reader, 0, 0, MemoryFileSystem.GetFileStreamFactory());
|
||||||
resultSet.ReadResultToEnd(CancellationToken.None).Wait();
|
resultSet.ReadResultToEnd(CancellationToken.None).Wait();
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class RowCreateTests
|
public class RowCreateTests
|
||||||
{
|
{
|
||||||
@@ -10,7 +10,7 @@ using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class RowDeleteTests
|
public class RowDeleteTests
|
||||||
{
|
{
|
||||||
@@ -13,10 +13,11 @@ using Microsoft.SqlTools.ServiceLayer.EditData;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class RowEditBaseTests
|
public class RowEditBaseTests
|
||||||
{
|
{
|
||||||
@@ -103,7 +104,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
object[][] rows = {row};
|
object[][] rows = {row};
|
||||||
var testResultSet = new TestResultSet(columns, rows);
|
var testResultSet = new TestResultSet(columns, rows);
|
||||||
var testReader = new TestDbDataReader(new [] {testResultSet});
|
var testReader = new TestDbDataReader(new [] {testResultSet});
|
||||||
var resultSet = new ResultSet(testReader, 0,0, QueryExecution.Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
var resultSet = new ResultSet(testReader, 0,0, MemoryFileSystem.GetFileStreamFactory());
|
||||||
resultSet.ReadResultToEnd(CancellationToken.None).Wait();
|
resultSet.ReadResultToEnd(CancellationToken.None).Wait();
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class RowUpdateTests
|
public class RowUpdateTests
|
||||||
{
|
{
|
||||||
@@ -10,11 +10,12 @@ using Microsoft.SqlTools.ServiceLayer.EditData;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class ServiceIntegrationTests
|
public class ServiceIntegrationTests
|
||||||
{
|
{
|
||||||
@@ -114,20 +115,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
{
|
{
|
||||||
// Setup: Create an edit data service with a session
|
// Setup: Create an edit data service with a session
|
||||||
var eds = new EditDataService(null, null, null);
|
var eds = new EditDataService(null, null, null);
|
||||||
eds.ActiveSessions[Common.OwnerUri] = GetDefaultSession();
|
eds.ActiveSessions[Constants.OwnerUri] = GetDefaultSession();
|
||||||
|
|
||||||
// If: I validly ask to delete a row
|
// If: I validly ask to delete a row
|
||||||
var efv = new EventFlowValidator<EditDeleteRowResult>()
|
var efv = new EventFlowValidator<EditDeleteRowResult>()
|
||||||
.AddResultValidation(Assert.NotNull)
|
.AddResultValidation(Assert.NotNull)
|
||||||
.Complete();
|
.Complete();
|
||||||
await eds.HandleDeleteRowRequest(new EditDeleteRowParams {OwnerUri = Common.OwnerUri, RowId = 0}, efv.Object);
|
await eds.HandleDeleteRowRequest(new EditDeleteRowParams {OwnerUri = Constants.OwnerUri, RowId = 0}, efv.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should be successful
|
// ... It should be successful
|
||||||
efv.Validate();
|
efv.Validate();
|
||||||
|
|
||||||
// ... There should be a delete in the session
|
// ... There should be a delete in the session
|
||||||
Session s = eds.ActiveSessions[Common.OwnerUri];
|
Session s = eds.ActiveSessions[Constants.OwnerUri];
|
||||||
Assert.True(s.EditCache.Any(e => e.Value is RowDelete));
|
Assert.True(s.EditCache.Any(e => e.Value is RowDelete));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,20 +137,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
{
|
{
|
||||||
// Setup: Create an edit data service with a session
|
// Setup: Create an edit data service with a session
|
||||||
var eds = new EditDataService(null, null, null);
|
var eds = new EditDataService(null, null, null);
|
||||||
eds.ActiveSessions[Common.OwnerUri] = GetDefaultSession();
|
eds.ActiveSessions[Constants.OwnerUri] = GetDefaultSession();
|
||||||
|
|
||||||
// If: I ask to create a row from a non existant session
|
// If: I ask to create a row from a non existant session
|
||||||
var efv = new EventFlowValidator<EditCreateRowResult>()
|
var efv = new EventFlowValidator<EditCreateRowResult>()
|
||||||
.AddResultValidation(ecrr => { Assert.True(ecrr.NewRowId > 0); })
|
.AddResultValidation(ecrr => { Assert.True(ecrr.NewRowId > 0); })
|
||||||
.Complete();
|
.Complete();
|
||||||
await eds.HandleCreateRowRequest(new EditCreateRowParams { OwnerUri = Common.OwnerUri }, efv.Object);
|
await eds.HandleCreateRowRequest(new EditCreateRowParams { OwnerUri = Constants.OwnerUri }, efv.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should have been successful
|
// ... It should have been successful
|
||||||
efv.Validate();
|
efv.Validate();
|
||||||
|
|
||||||
// ... There should be a create in the session
|
// ... There should be a create in the session
|
||||||
Session s = eds.ActiveSessions[Common.OwnerUri];
|
Session s = eds.ActiveSessions[Constants.OwnerUri];
|
||||||
Assert.True(s.EditCache.Any(e => e.Value is RowCreate));
|
Assert.True(s.EditCache.Any(e => e.Value is RowCreate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,20 +161,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
var eds = new EditDataService(null, null, null);
|
var eds = new EditDataService(null, null, null);
|
||||||
var session = GetDefaultSession();
|
var session = GetDefaultSession();
|
||||||
session.EditCache[0] = new Mock<RowEditBase>().Object;
|
session.EditCache[0] = new Mock<RowEditBase>().Object;
|
||||||
eds.ActiveSessions[Common.OwnerUri] = session;
|
eds.ActiveSessions[Constants.OwnerUri] = session;
|
||||||
|
|
||||||
// If: I ask to revert a row that has a pending edit
|
// If: I ask to revert a row that has a pending edit
|
||||||
var efv = new EventFlowValidator<EditRevertRowResult>()
|
var efv = new EventFlowValidator<EditRevertRowResult>()
|
||||||
.AddResultValidation(Assert.NotNull)
|
.AddResultValidation(Assert.NotNull)
|
||||||
.Complete();
|
.Complete();
|
||||||
await eds.HandleRevertRowRequest(new EditRevertRowParams { OwnerUri = Common.OwnerUri, RowId = 0}, efv.Object);
|
await eds.HandleRevertRowRequest(new EditRevertRowParams { OwnerUri = Constants.OwnerUri, RowId = 0}, efv.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should have succeeded
|
// ... It should have succeeded
|
||||||
efv.Validate();
|
efv.Validate();
|
||||||
|
|
||||||
// ... The edit cache should be empty again
|
// ... The edit cache should be empty again
|
||||||
Session s = eds.ActiveSessions[Common.OwnerUri];
|
Session s = eds.ActiveSessions[Constants.OwnerUri];
|
||||||
Assert.Empty(s.EditCache);
|
Assert.Empty(s.EditCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +184,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
// Setup: Create an edit data service with a session
|
// Setup: Create an edit data service with a session
|
||||||
var eds = new EditDataService(null, null, null);
|
var eds = new EditDataService(null, null, null);
|
||||||
var session = GetDefaultSession();
|
var session = GetDefaultSession();
|
||||||
eds.ActiveSessions[Common.OwnerUri] = session;
|
eds.ActiveSessions[Constants.OwnerUri] = session;
|
||||||
var edit = new Mock<RowEditBase>();
|
var edit = new Mock<RowEditBase>();
|
||||||
edit.Setup(e => e.SetCell(It.IsAny<int>(), It.IsAny<string>())).Returns(new EditUpdateCellResult
|
edit.Setup(e => e.SetCell(It.IsAny<int>(), It.IsAny<string>())).Returns(new EditUpdateCellResult
|
||||||
{
|
{
|
||||||
@@ -204,7 +205,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
Assert.False(eucr.IsNull);
|
Assert.False(eucr.IsNull);
|
||||||
})
|
})
|
||||||
.Complete();
|
.Complete();
|
||||||
await eds.HandleUpdateCellRequest(new EditUpdateCellParams { OwnerUri = Common.OwnerUri, RowId = 0}, efv.Object);
|
await eds.HandleUpdateCellRequest(new EditUpdateCellParams { OwnerUri = Constants.OwnerUri, RowId = 0}, efv.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should be successful
|
// ... It should be successful
|
||||||
@@ -13,11 +13,11 @@ using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
{
|
{
|
||||||
public class SessionTests
|
public class SessionTests
|
||||||
{
|
{
|
||||||
@@ -87,8 +87,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.EditData
|
|||||||
ConnectionInfo ci = QueryExecution.Common.CreateConnectedConnectionInfo(results, false);
|
ConnectionInfo ci = QueryExecution.Common.CreateConnectedConnectionInfo(results, false);
|
||||||
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
||||||
|
|
||||||
var fsf = QueryExecution.Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fsf = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(QueryExecution.Common.StandardQuery, ci, new QueryExecutionSettings(), fsf);
|
Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(), fsf);
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.Extensibility;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Extensibility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Extensibility
|
||||||
{
|
{
|
||||||
public class ExtensionTests
|
public class ExtensionTests
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,7 @@ using System.Linq;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Extensibility;
|
using Microsoft.SqlTools.ServiceLayer.Extensibility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Extensibility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Extensibility
|
||||||
{
|
{
|
||||||
public class ServiceProviderTests
|
public class ServiceProviderTests
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
public class BinaryQueryExpressionFormatterTests : FormatterUnitTestsBase
|
public class BinaryQueryExpressionFormatterTests : FormatterUnitTestsBase
|
||||||
{
|
{
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class CommonTableExpressionFormatterTests : FormatterUnitTestsBase
|
public class CommonTableExpressionFormatterTests : FormatterUnitTestsBase
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class CreateProcedureFormatterTests : FormatterUnitTestsBase
|
public class CreateProcedureFormatterTests : FormatterUnitTestsBase
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class CreateTableFormatterTests : FormatterUnitTestsBase
|
public class CreateTableFormatterTests : FormatterUnitTestsBase
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class CreateViewFormatterTests : FormatterUnitTestsBase
|
public class CreateViewFormatterTests : FormatterUnitTestsBase
|
||||||
@@ -9,7 +9,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
public class FormatterSettingsTests
|
public class FormatterSettingsTests
|
||||||
{
|
{
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Extensibility;
|
using Microsoft.SqlTools.ServiceLayer.Extensibility;
|
||||||
@@ -14,7 +13,7 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
public class FormatterUnitTestsBase
|
public class FormatterUnitTestsBase
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
public class GeneralFormatterTests : FormatterUnitTestsBase
|
public class GeneralFormatterTests : FormatterUnitTestsBase
|
||||||
{
|
{
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class InsertFormatterTests : FormatterUnitTestsBase
|
public class InsertFormatterTests : FormatterUnitTestsBase
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
|
|
||||||
public class SqlSelectStatementFormatterTests : FormatterUnitTestsBase
|
public class SqlSelectStatementFormatterTests : FormatterUnitTestsBase
|
||||||
@@ -11,12 +11,12 @@ using Microsoft.SqlTools.ServiceLayer.Formatter.Contracts;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Formatter
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
|
||||||
{
|
{
|
||||||
public class TSqlFormatterServiceTests : FormatterUnitTestsBase
|
public class TSqlFormatterServiceTests : FormatterUnitTestsBase
|
||||||
{
|
{
|
||||||
@@ -13,14 +13,14 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
using GlobalCommon = Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the language service autocomplete component
|
/// Tests for the language service autocomplete component
|
||||||
@@ -65,7 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
|||||||
|
|
||||||
// set up file for returning the query
|
// set up file for returning the query
|
||||||
scriptFile = new Mock<ScriptFile>();
|
scriptFile = new Mock<ScriptFile>();
|
||||||
scriptFile.SetupGet(file => file.Contents).Returns(QueryExecution.Common.StandardQuery);
|
scriptFile.SetupGet(file => file.Contents).Returns(GlobalCommon.Constants.StandardQuery);
|
||||||
scriptFile.SetupGet(file => file.ClientFilePath).Returns(this.testScriptUri);
|
scriptFile.SetupGet(file => file.ClientFilePath).Returns(this.testScriptUri);
|
||||||
|
|
||||||
// set up workspace mock
|
// set up workspace mock
|
||||||
@@ -14,7 +14,7 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -16,7 +16,7 @@ using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
public class CompletionServiceTest
|
public class CompletionServiceTest
|
||||||
{
|
{
|
||||||
@@ -7,7 +7,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
public class InteractionMetricsTest
|
public class InteractionMetricsTest
|
||||||
{
|
{
|
||||||
@@ -3,15 +3,14 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the ServiceHost Language Service tests
|
/// Tests for the ServiceHost Language Service tests
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
// Copyright (c) Microsoft. All rights reserved.
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -18,14 +19,15 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Microsoft.SqlTools.Test.Utility;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using GlobalCommon = Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Location = Microsoft.SqlTools.ServiceLayer.Workspace.Contracts.Location;
|
using Location = Microsoft.SqlTools.ServiceLayer.Workspace.Contracts.Location;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the language service peek definition/ go to definition feature
|
/// Tests for the language service peek definition/ go to definition feature
|
||||||
@@ -48,8 +50,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
|||||||
|
|
||||||
private TextDocumentPosition textDocument;
|
private TextDocumentPosition textDocument;
|
||||||
|
|
||||||
private const string OwnerUri = "testFile1";
|
|
||||||
|
|
||||||
private void InitializeTestObjects()
|
private void InitializeTestObjects()
|
||||||
{
|
{
|
||||||
// initial cursor position in the script file
|
// initial cursor position in the script file
|
||||||
@@ -68,7 +68,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
|||||||
|
|
||||||
// set up file for returning the query
|
// set up file for returning the query
|
||||||
var fileMock = new Mock<ScriptFile>();
|
var fileMock = new Mock<ScriptFile>();
|
||||||
fileMock.SetupGet(file => file.Contents).Returns(QueryExecution.Common.StandardQuery);
|
fileMock.SetupGet(file => file.Contents).Returns(GlobalCommon.Constants.StandardQuery);
|
||||||
fileMock.SetupGet(file => file.ClientFilePath).Returns(this.testScriptUri);
|
fileMock.SetupGet(file => file.ClientFilePath).Returns(this.testScriptUri);
|
||||||
|
|
||||||
// set up workspace mock
|
// set up workspace mock
|
||||||
@@ -9,7 +9,7 @@ using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer
|
||||||
{
|
{
|
||||||
public class SqlCompletionItemTests
|
public class SqlCompletionItemTests
|
||||||
{
|
{
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
|
||||||
{
|
{
|
||||||
public class Common
|
public class Common
|
||||||
{
|
{
|
||||||
@@ -11,7 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
|
||||||
{
|
{
|
||||||
public class MessageDispatcherTests
|
public class MessageDispatcherTests
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
|
||||||
{
|
{
|
||||||
public class MessageReaderTests
|
public class MessageReaderTests
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
|
||||||
{
|
{
|
||||||
public class MessageWriterTests
|
public class MessageWriterTests
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Messaging
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
|
||||||
{
|
{
|
||||||
#region Request Types
|
#region Request Types
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>2d771d16-9d85-4053-9f79-e2034737deef</ProjectGuid>
|
<ProjectGuid>2d771d16-9d85-4053-9f79-e2034737deef</ProjectGuid>
|
||||||
<RootNamespace>Microsoft.SqlTools.ServiceLayer.Test</RootNamespace>
|
<RootNamespace>Microsoft.SqlTools.ServiceLayer.UnitTests</RootNamespace>
|
||||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'==''">.\obj</BaseIntermediateOutputPath>
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'==''">.\obj</BaseIntermediateOutputPath>
|
||||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
@@ -7,12 +7,13 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class CancelTests
|
public class CancelTests
|
||||||
{
|
{
|
||||||
@@ -21,17 +22,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request a query (doesn't matter what kind) and execute it
|
// ... I request a query (doesn't matter what kind) and execute it
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
|
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
queryService.ActiveQueries[Common.OwnerUri].HasExecuted = false; // Fake that it hasn't completed execution
|
queryService.ActiveQueries[Constants.OwnerUri].HasExecuted = false; // Fake that it hasn't completed execution
|
||||||
|
|
||||||
// ... And then I request to cancel the query
|
// ... And then I request to cancel the query
|
||||||
var cancelParams = new QueryCancelParams {OwnerUri = Common.OwnerUri};
|
var cancelParams = new QueryCancelParams {OwnerUri = Constants.OwnerUri};
|
||||||
var cancelRequest = new EventFlowValidator<QueryCancelResult>()
|
var cancelRequest = new EventFlowValidator<QueryCancelResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -50,16 +51,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request a query (doesn't matter what kind) and wait for execution
|
// ... I request a query (doesn't matter what kind) and wait for execution
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
|
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And then I request to cancel the query
|
// ... And then I request to cancel the query
|
||||||
var cancelParams = new QueryCancelParams {OwnerUri = Common.OwnerUri};
|
var cancelParams = new QueryCancelParams {OwnerUri = Constants.OwnerUri};
|
||||||
var cancelRequest = new EventFlowValidator<QueryCancelResult>()
|
var cancelRequest = new EventFlowValidator<QueryCancelResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -2,29 +2,27 @@
|
|||||||
// Copyright (c) Microsoft. All rights reserved.
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
using HostingProtocol = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class Common
|
public class Common
|
||||||
{
|
{
|
||||||
@@ -36,12 +34,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
public const int Ordinal = 100; // We'll pick something other than default(int)
|
public const int Ordinal = 100; // We'll pick something other than default(int)
|
||||||
|
|
||||||
public const string OwnerUri = "testFile";
|
|
||||||
|
|
||||||
public const int StandardColumns = 5;
|
public const int StandardColumns = 5;
|
||||||
|
|
||||||
public const string StandardQuery = "SELECT * FROM sys.objects";
|
|
||||||
|
|
||||||
public const int StandardRows = 5;
|
public const int StandardRows = 5;
|
||||||
|
|
||||||
public const string UdtQuery = "SELECT hierarchyid::Parse('/')";
|
public const string UdtQuery = "SELECT hierarchyid::Parse('/')";
|
||||||
@@ -78,14 +72,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
public static Batch GetBasicExecutedBatch()
|
public static Batch GetBasicExecutedBatch()
|
||||||
{
|
{
|
||||||
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Batch batch = new Batch(Constants.StandardQuery, SubsectionDocument, 1,
|
||||||
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
batch.Execute(CreateTestConnection(StandardTestDataSet, false), CancellationToken.None).Wait();
|
batch.Execute(CreateTestConnection(StandardTestDataSet, false), CancellationToken.None).Wait();
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Batch GetExecutedBatchWithExecutionPlan()
|
public static Batch GetExecutedBatchWithExecutionPlan()
|
||||||
{
|
{
|
||||||
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Batch batch = new Batch(Constants.StandardQuery, SubsectionDocument, 1,
|
||||||
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
batch.Execute(CreateTestConnection(ExecutionPlanTestDataSet, false), CancellationToken.None).Wait();
|
batch.Execute(CreateTestConnection(ExecutionPlanTestDataSet, false), CancellationToken.None).Wait();
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
@@ -98,7 +94,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// ConnectionInfo with the same URI as the query, so we will manually set it
|
// ConnectionInfo with the same URI as the query, so we will manually set it
|
||||||
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
||||||
|
|
||||||
Query query = new Query(StandardQuery, ci, new QueryExecutionSettings(), GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(),
|
||||||
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
return query;
|
return query;
|
||||||
@@ -112,7 +109,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// ConnectionInfo with the same URI as the query, so we will manually set it
|
// ConnectionInfo with the same URI as the query, so we will manually set it
|
||||||
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
||||||
|
|
||||||
Query query = new Query(StandardQuery, ci, querySettings, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Query query = new Query(Constants.StandardQuery, ci, querySettings,
|
||||||
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
query.Execute();
|
query.Execute();
|
||||||
query.ExecutionTask.Wait();
|
query.ExecutionTask.Wait();
|
||||||
return query;
|
return query;
|
||||||
@@ -124,7 +122,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async Task AwaitExecution(QueryExecutionService service, ExecuteDocumentSelectionParams qeParams,
|
public static async Task AwaitExecution(QueryExecutionService service, ExecuteDocumentSelectionParams qeParams,
|
||||||
RequestContext<ExecuteRequestResult> requestContext)
|
HostingProtocol.RequestContext<ExecuteRequestResult> requestContext)
|
||||||
{
|
{
|
||||||
await service.HandleExecuteRequest(qeParams, requestContext);
|
await service.HandleExecuteRequest(qeParams, requestContext);
|
||||||
if (service.ActiveQueries.ContainsKey(qeParams.OwnerUri) && service.ActiveQueries[qeParams.OwnerUri].ExecutionTask != null)
|
if (service.ActiveQueries.ContainsKey(qeParams.OwnerUri) && service.ActiveQueries[qeParams.OwnerUri].ExecutionTask != null)
|
||||||
@@ -135,28 +133,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region FileStreamWriteMocking
|
|
||||||
|
|
||||||
public static IFileStreamFactory GetFileStreamFactory(Dictionary<string, byte[]> storage)
|
|
||||||
{
|
|
||||||
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
|
||||||
mock.Setup(fsf => fsf.CreateFile())
|
|
||||||
.Returns(() =>
|
|
||||||
{
|
|
||||||
string fileName = Guid.NewGuid().ToString();
|
|
||||||
storage.Add(fileName, new byte[8192]);
|
|
||||||
return fileName;
|
|
||||||
});
|
|
||||||
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))
|
|
||||||
.Returns<string>(output => new ServiceBufferFileStreamReader(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
|
||||||
mock.Setup(fsf => fsf.GetWriter(It.IsAny<string>()))
|
|
||||||
.Returns<string>(output => new ServiceBufferFileStreamWriter(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
|
||||||
|
|
||||||
return mock.Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region DbConnection Mocking
|
#region DbConnection Mocking
|
||||||
|
|
||||||
public static DbCommand CreateTestCommand(TestResultSet[] data, bool throwOnRead)
|
public static DbCommand CreateTestCommand(TestResultSet[] data, bool throwOnRead)
|
||||||
@@ -208,7 +184,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// Create a connection info and add the default connection to it
|
// Create a connection info and add the default connection to it
|
||||||
ISqlConnectionFactory factory = CreateMockFactory(data, throwOnRead);
|
ISqlConnectionFactory factory = CreateMockFactory(data, throwOnRead);
|
||||||
ConnectionInfo ci = new ConnectionInfo(factory, OwnerUri, StandardConnectionDetails);
|
ConnectionInfo ci = new ConnectionInfo(factory, Constants.OwnerUri, StandardConnectionDetails);
|
||||||
ci.ConnectionTypeToConnectionMap[ConnectionType.Default] = factory.CreateSqlConnection(null);
|
ci.ConnectionTypeToConnectionMap[ConnectionType.Default] = factory.CreateSqlConnection(null);
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
@@ -222,12 +198,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
ConnectParams connectParams = new ConnectParams
|
ConnectParams connectParams = new ConnectParams
|
||||||
{
|
{
|
||||||
Connection = StandardConnectionDetails,
|
Connection = StandardConnectionDetails,
|
||||||
OwnerUri = OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
Type = type
|
Type = type
|
||||||
};
|
};
|
||||||
|
|
||||||
connectionService.Connect(connectParams).Wait();
|
connectionService.Connect(connectParams).Wait();
|
||||||
return connectionService.OwnerToConnectionMap[OwnerUri];
|
return connectionService.OwnerToConnectionMap[connectParams.OwnerUri];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -250,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
.OutCallback((string owner, out ConnectionInfo connInfo) => connInfo = isConnected ? ci : null)
|
.OutCallback((string owner, out ConnectionInfo connInfo) => connInfo = isConnected ? ci : null)
|
||||||
.Returns(isConnected);
|
.Returns(isConnected);
|
||||||
|
|
||||||
return new QueryExecutionService(connectionService.Object, workspaceService) { BufferFileStreamFactory = GetFileStreamFactory(storage) };
|
return new QueryExecutionService(connectionService.Object, workspaceService) { BufferFileStreamFactory = MemoryFileSystem.GetFileStreamFactory(storage) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] data, bool isConnected, bool throwOnRead, WorkspaceService<SqlToolsSettings> workspaceService)
|
public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] data, bool isConnected, bool throwOnRead, WorkspaceService<SqlToolsSettings> workspaceService)
|
||||||
@@ -10,10 +10,10 @@ using System.Text;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||||
{
|
{
|
||||||
public class SaveAsCsvFileStreamWriterTests
|
public class SaveAsCsvFileStreamWriterTests
|
||||||
{
|
{
|
||||||
@@ -8,11 +8,11 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||||
{
|
{
|
||||||
public class SaveAsJsonFileStreamWriterTests
|
public class SaveAsJsonFileStreamWriterTests
|
||||||
{
|
{
|
||||||
@@ -13,11 +13,11 @@ using System.Text.RegularExpressions;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||||
{
|
{
|
||||||
public class ReaderWriterPairTest
|
public class ReaderWriterPairTest
|
||||||
{
|
{
|
||||||
@@ -9,12 +9,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class DisposeTests
|
public class DisposeTests
|
||||||
{
|
{
|
||||||
@@ -38,15 +39,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request a query (doesn't matter what kind)
|
// ... I request a query (doesn't matter what kind)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And then I dispose of the query
|
// ... And then I dispose of the query
|
||||||
var disposeParams = new QueryDisposeParams {OwnerUri = Common.OwnerUri};
|
var disposeParams = new QueryDisposeParams {OwnerUri = Constants.OwnerUri};
|
||||||
var disposeRequest = new EventFlowValidator<QueryDisposeResult>()
|
var disposeRequest = new EventFlowValidator<QueryDisposeResult>()
|
||||||
.AddStandardQueryDisposeValidator()
|
.AddStandardQueryDisposeValidator()
|
||||||
.Complete();
|
.Complete();
|
||||||
@@ -65,7 +66,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// ... I attempt to dispose a query that doesn't exist
|
// ... I attempt to dispose a query that doesn't exist
|
||||||
var workspaceService = new Mock<WorkspaceService<SqlToolsSettings>>();
|
var workspaceService = new Mock<WorkspaceService<SqlToolsSettings>>();
|
||||||
var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService.Object);
|
var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService.Object);
|
||||||
var disposeParams = new QueryDisposeParams {OwnerUri = Common.OwnerUri};
|
var disposeParams = new QueryDisposeParams {OwnerUri = Constants.OwnerUri};
|
||||||
|
|
||||||
var disposeRequest = new EventFlowValidator<QueryDisposeResult>()
|
var disposeRequest = new EventFlowValidator<QueryDisposeResult>()
|
||||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||||
@@ -81,15 +82,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... We need a query service
|
// ... We need a query service
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
|
|
||||||
// If:
|
// If:
|
||||||
// ... I execute some bogus query
|
// ... I execute some bogus query
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri };
|
||||||
var requestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var requestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(queryParams, requestContext.Object);
|
await queryService.HandleExecuteRequest(queryParams, requestContext.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And it sticks around as an active query
|
// ... And it sticks around as an active query
|
||||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||||
@@ -13,9 +13,10 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||||
{
|
{
|
||||||
public class BatchTests
|
public class BatchTests
|
||||||
{
|
{
|
||||||
@@ -23,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
public void BatchCreationTest()
|
public void BatchCreationTest()
|
||||||
{
|
{
|
||||||
// If I create a new batch...
|
// If I create a new batch...
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, Common.GetFileStreamFactory(null));
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory());
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... The text of the batch should be stored
|
// ... The text of the batch should be stored
|
||||||
@@ -63,8 +64,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
List<ResultMessage> messages = new List<ResultMessage>();
|
List<ResultMessage> messages = new List<ResultMessage>();
|
||||||
|
|
||||||
// If I execute a query that should get no result sets
|
// If I execute a query that should get no result sets
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
||||||
BatchCallbackHelper(batch,
|
BatchCallbackHelper(batch,
|
||||||
b => batchStartCalls++,
|
b => batchStartCalls++,
|
||||||
b => batchEndCalls++,
|
b => batchEndCalls++,
|
||||||
@@ -99,8 +100,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false);
|
||||||
|
|
||||||
// If I execute a query that should get one result set
|
// If I execute a query that should get one result set
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
||||||
BatchCallbackHelper(batch,
|
BatchCallbackHelper(batch,
|
||||||
b => batchStartCalls++,
|
b => batchStartCalls++,
|
||||||
b => batchEndCalls++,
|
b => batchEndCalls++,
|
||||||
@@ -135,8 +136,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false);
|
||||||
|
|
||||||
// If I execute a query that should get two result sets
|
// If I execute a query that should get two result sets
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
||||||
BatchCallbackHelper(batch,
|
BatchCallbackHelper(batch,
|
||||||
b => batchStartCalls++,
|
b => batchStartCalls++,
|
||||||
b => batchEndCalls++,
|
b => batchEndCalls++,
|
||||||
@@ -167,8 +168,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
|
|
||||||
// If I execute a batch that is invalid
|
// If I execute a batch that is invalid
|
||||||
var ci = Common.CreateTestConnectionInfo(null, true);
|
var ci = Common.CreateTestConnectionInfo(null, true);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
||||||
BatchCallbackHelper(batch,
|
BatchCallbackHelper(batch,
|
||||||
b => batchStartCalls++,
|
b => batchStartCalls++,
|
||||||
b => batchEndCalls++,
|
b => batchEndCalls++,
|
||||||
@@ -202,8 +203,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false);
|
||||||
|
|
||||||
// If I execute a batch
|
// If I execute a batch
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory);
|
||||||
await batch.Execute(GetConnection(ci), CancellationToken.None);
|
await batch.Execute(GetConnection(ci), CancellationToken.None);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
@@ -235,7 +236,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... I create a batch that has an empty query
|
// ... I create a batch that has an empty query
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should throw an exception
|
// ... It should throw an exception
|
||||||
Assert.Throws<ArgumentException>(() => new Batch(query, Common.SubsectionDocument, Common.Ordinal, Common.GetFileStreamFactory(null)));
|
Assert.Throws<ArgumentException>(() => new Batch(query, Common.SubsectionDocument, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -255,7 +256,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... I create a batch has has an ordinal less than 0
|
// ... I create a batch has has an ordinal less than 0
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should throw an exception
|
// ... It should throw an exception
|
||||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Batch("stuff", Common.SubsectionDocument, -1, Common.GetFileStreamFactory(null)));
|
Assert.Throws<ArgumentOutOfRangeException>(() => new Batch("stuff", Common.SubsectionDocument, -1, MemoryFileSystem.GetFileStreamFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -263,7 +264,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I call the StatementCompletedHandler
|
// ... I call the StatementCompletedHandler
|
||||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, Common.GetFileStreamFactory(null));
|
Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory());
|
||||||
int messageCalls = 0;
|
int messageCalls = 0;
|
||||||
batch.BatchMessageSent += args =>
|
batch.BatchMessageSent += args =>
|
||||||
{
|
{
|
||||||
@@ -7,7 +7,7 @@ using System.Data.Common;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DbColumnWrapper tests
|
/// DbColumnWrapper tests
|
||||||
@@ -11,9 +11,10 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||||
{
|
{
|
||||||
public class QueryTests
|
public class QueryTests
|
||||||
{
|
{
|
||||||
@@ -24,8 +25,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a query
|
// ... I create a query
|
||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(Common.StandardQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... I should get back two batches to execute that haven't been executed
|
// ... I should get back two batches to execute that haven't been executed
|
||||||
@@ -42,7 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// Then:
|
// Then:
|
||||||
// ... It should throw an exception
|
// ... It should throw an exception
|
||||||
Assert.Throws<ArgumentException>(() =>
|
Assert.Throws<ArgumentException>(() =>
|
||||||
new Query(null, Common.CreateTestConnectionInfo(null, false), new QueryExecutionSettings(), Common.GetFileStreamFactory(null)));
|
new Query(null, Common.CreateTestConnectionInfo(null, false), new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -52,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... I create a query that has a null connection info
|
// ... I create a query that has a null connection info
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should throw an exception
|
// ... It should throw an exception
|
||||||
Assert.Throws<ArgumentNullException>(() => new Query("Some Query", null, new QueryExecutionSettings(), Common.GetFileStreamFactory(null)));
|
Assert.Throws<ArgumentNullException>(() => new Query("Some Query", null, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -63,7 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// Then:
|
// Then:
|
||||||
// ... It should throw an exception
|
// ... It should throw an exception
|
||||||
Assert.Throws<ArgumentNullException>(() =>
|
Assert.Throws<ArgumentNullException>(() =>
|
||||||
new Query("Some query", Common.CreateTestConnectionInfo(null, false), null, Common.GetFileStreamFactory(null)));
|
new Query("Some query", Common.CreateTestConnectionInfo(null, false), null, MemoryFileSystem.GetFileStreamFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -89,8 +90,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a query from a single batch (without separator)
|
// ... I create a query from a single batch (without separator)
|
||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(Common.StandardQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
BatchCallbackHelper(query,
|
BatchCallbackHelper(query,
|
||||||
b => batchStartCallbacksReceived++,
|
b => batchStartCallbacksReceived++,
|
||||||
b => batchCompleteCallbacksReceived++,
|
b => batchCompleteCallbacksReceived++,
|
||||||
@@ -117,7 +118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void QueryExecuteSingleNoOpBatch()
|
public async Task QueryExecuteSingleNoOpBatch()
|
||||||
{
|
{
|
||||||
// Setup: Keep track of all the messages received
|
// Setup: Keep track of all the messages received
|
||||||
List<ResultMessage> messages = new List<ResultMessage>();
|
List<ResultMessage> messages = new List<ResultMessage>();
|
||||||
@@ -125,7 +126,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a query from a single batch that does nothing
|
// ... I create a query from a single batch that does nothing
|
||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(Common.NoOpQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(Common.NoOpQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
BatchCallbackHelper(query,
|
BatchCallbackHelper(query,
|
||||||
b => { throw new Exception("Batch startup callback should not have been called."); },
|
b => { throw new Exception("Batch startup callback should not have been called."); },
|
||||||
@@ -135,6 +136,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I Then execute the query
|
// ... I Then execute the query
|
||||||
query.Execute();
|
query.Execute();
|
||||||
|
await query.ExecutionTask;
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... There should be no batches
|
// ... There should be no batches
|
||||||
@@ -160,8 +162,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... I create a query from two batches (with separator)
|
// ... I create a query from two batches (with separator)
|
||||||
ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false);
|
ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false);
|
||||||
|
|
||||||
string queryText = string.Format("{0}\r\nGO\r\n{0}", Common.StandardQuery);
|
string queryText = string.Format("{0}\r\nGO\r\n{0}", Constants.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
BatchCallbackHelper(query,
|
BatchCallbackHelper(query,
|
||||||
b => batchStartCallbacksReceived++,
|
b => batchStartCallbacksReceived++,
|
||||||
@@ -189,7 +191,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void QueryExecuteMultipleBatchesWithNoOp()
|
public async Task QueryExecuteMultipleBatchesWithNoOp()
|
||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... Keep track of how many times callbacks are called
|
// ... Keep track of how many times callbacks are called
|
||||||
@@ -199,9 +201,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
|
|
||||||
// If:
|
// If:
|
||||||
// ... I create a query from a two batches (with separator)
|
// ... I create a query from a two batches (with separator)
|
||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false);
|
||||||
string queryText = string.Format("{0}\r\nGO\r\n{1}", Common.StandardQuery, Common.NoOpQuery);
|
string queryText = string.Format("{0}\r\nGO\r\n{1}", Constants.StandardQuery, Common.NoOpQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
BatchCallbackHelper(query,
|
BatchCallbackHelper(query,
|
||||||
b => batchStartCallbacksReceived++,
|
b => batchStartCallbacksReceived++,
|
||||||
@@ -210,23 +212,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
|
|
||||||
// .. I then execute the query
|
// .. I then execute the query
|
||||||
query.Execute();
|
query.Execute();
|
||||||
|
await query.ExecutionTask;
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... I should get back a query with two batches
|
// ... I should get back a query with two batches
|
||||||
Assert.NotEmpty(query.Batches);
|
Assert.NotEmpty(query.Batches);
|
||||||
Assert.Equal(2, query.Batches.Length);
|
Assert.Equal(2, query.Batches.Length);
|
||||||
|
|
||||||
//// ... The query shouldn't have completed successfully unless all batches were executed
|
// ... The query should have completed successfully
|
||||||
Assert.False(query.HasExecuted);
|
Assert.True(query.HasExecuted);
|
||||||
|
|
||||||
//// ... The batch callbacks should have been called 0 times
|
// ... The batch callbacks should have been called 2 times (for each no op batch)
|
||||||
Assert.Equal(0, batchStartCallbacksReceived);
|
Assert.Equal(2, batchStartCallbacksReceived);
|
||||||
Assert.Equal(0, batchCompletionCallbacksReceived);
|
Assert.Equal(2, batchCompletionCallbacksReceived);
|
||||||
Assert.Equal(0, batchMessageCallbacksReceived);
|
Assert.Equal(2, batchMessageCallbacksReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void QueryExecuteMultipleNoOpBatches()
|
public async Task QueryExecuteMultipleNoOpBatches()
|
||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... Keep track of how many messages were sent
|
// ... Keep track of how many messages were sent
|
||||||
@@ -236,7 +239,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... I create a query from a two batches (with separator)
|
// ... I create a query from a two batches (with separator)
|
||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false);
|
||||||
string queryText = string.Format("{0}\r\nGO\r\n{1}", Common.NoOpQuery, Common.NoOpQuery);
|
string queryText = string.Format("{0}\r\nGO\r\n{1}", Common.NoOpQuery, Common.NoOpQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
BatchCallbackHelper(query,
|
BatchCallbackHelper(query,
|
||||||
b => { throw new Exception("Batch start handler was called"); },
|
b => { throw new Exception("Batch start handler was called"); },
|
||||||
@@ -245,6 +248,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
|
|
||||||
// .. I then execute the query
|
// .. I then execute the query
|
||||||
query.Execute();
|
query.Execute();
|
||||||
|
await query.ExecutionTask;
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... I should get back a query with no batches
|
// ... I should get back a query with no batches
|
||||||
@@ -271,7 +275,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, true);
|
ConnectionInfo ci = Common.CreateTestConnectionInfo(null, true);
|
||||||
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci;
|
||||||
|
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
Query query = new Query(Common.InvalidQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
Query query = new Query(Common.InvalidQuery, ci, new QueryExecutionSettings(), fileStreamFactory);
|
||||||
BatchCallbackHelper(query,
|
BatchCallbackHelper(query,
|
||||||
b => batchStartCallbacksReceived++,
|
b => batchStartCallbacksReceived++,
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -12,10 +11,11 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||||
{
|
{
|
||||||
public class ResultSetTests
|
public class ResultSetTests
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new result set with a valid db data reader
|
// ... I create a new result set with a valid db data reader
|
||||||
DbDataReader mockReader = GetReader(null, false, string.Empty);
|
DbDataReader mockReader = GetReader(null, false, string.Empty);
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory());
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... There should not be any data read yet
|
// ... There should not be any data read yet
|
||||||
@@ -65,8 +65,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new resultset with a valid db data reader that has data
|
// ... I create a new resultset with a valid db data reader that has data
|
||||||
// ... and I read it to the end
|
// ... and I read it to the end
|
||||||
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
resultSet.ResultCompletion += callback;
|
resultSet.ResultCompletion += callback;
|
||||||
await resultSet.ReadResultToEnd(CancellationToken.None);
|
await resultSet.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -109,8 +109,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new resultset with a valid db data reader that is FOR XML/JSON
|
// ... I create a new resultset with a valid db data reader that is FOR XML/JSON
|
||||||
// ... and I read it to the end
|
// ... and I read it to the end
|
||||||
DbDataReader mockReader = GetReader(dataSets, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(dataSets, false, Constants.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
resultSet.ResultCompletion += callback;
|
resultSet.ResultCompletion += callback;
|
||||||
await resultSet.ReadResultToEnd(CancellationToken.None);
|
await resultSet.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -139,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new result set with a valid db data reader without executing it
|
// ... I create a new result set with a valid db data reader without executing it
|
||||||
DbDataReader mockReader = GetReader(null, false, string.Empty);
|
DbDataReader mockReader = GetReader(null, false, string.Empty);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
@@ -156,8 +156,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new result set with a valid db data reader
|
// ... I create a new result set with a valid db data reader
|
||||||
// ... And execute the result
|
// ... And execute the result
|
||||||
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
await resultSet.ReadResultToEnd(CancellationToken.None);
|
await resultSet.ReadResultToEnd(CancellationToken.None);
|
||||||
|
|
||||||
@@ -177,8 +177,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new result set with a valid db data reader
|
// ... I create a new result set with a valid db data reader
|
||||||
// ... And execute the result set
|
// ... And execute the result set
|
||||||
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
await resultSet.ReadResultToEnd(CancellationToken.None);
|
await resultSet.ReadResultToEnd(CancellationToken.None);
|
||||||
|
|
||||||
@@ -8,12 +8,13 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||||
{
|
{
|
||||||
public class ServiceIntegrationTests
|
public class ServiceIntegrationTests
|
||||||
{
|
{
|
||||||
@@ -27,12 +28,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... Create a workspace service with a multi-line constructed query
|
// ... Create a workspace service with a multi-line constructed query
|
||||||
// ... Create a query execution service without a connection service (we won't be
|
// ... Create a query execution service without a connection service (we won't be
|
||||||
// executing queries), and the previously created workspace service
|
// executing queries), and the previously created workspace service
|
||||||
string query = string.Format("{0}{1}GO{1}{0}", Common.StandardQuery, Environment.NewLine);
|
string query = string.Format("{0}{1}GO{1}{0}", Constants.StandardQuery, Environment.NewLine);
|
||||||
var workspaceService = GetDefaultWorkspaceService(query);
|
var workspaceService = GetDefaultWorkspaceService(query);
|
||||||
var queryService = new QueryExecutionService(null, workspaceService);
|
var queryService = new QueryExecutionService(null, workspaceService);
|
||||||
|
|
||||||
// If: I attempt to get query text from execute document params (entire document)
|
// If: I attempt to get query text from execute document params (entire document)
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
var queryText = queryService.GetSqlText(queryParams);
|
var queryText = queryService.GetSqlText(queryParams);
|
||||||
|
|
||||||
// Then: The text should match the constructed query
|
// Then: The text should match the constructed query
|
||||||
@@ -44,12 +45,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... Create a workspace service with a multi-line constructed query
|
// ... Create a workspace service with a multi-line constructed query
|
||||||
string query = string.Format("{0}{1}GO{1}{0}", Common.StandardQuery, Environment.NewLine);
|
string query = string.Format("{0}{1}GO{1}{0}", Constants.StandardQuery, Environment.NewLine);
|
||||||
var workspaceService = GetDefaultWorkspaceService(query);
|
var workspaceService = GetDefaultWorkspaceService(query);
|
||||||
var queryService = new QueryExecutionService(null, workspaceService);
|
var queryService = new QueryExecutionService(null, workspaceService);
|
||||||
|
|
||||||
// If: I attempt to get query text from execute document params (partial document)
|
// If: I attempt to get query text from execute document params (partial document)
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.SubsectionDocument };
|
var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Constants.OwnerUri, QuerySelection = Common.SubsectionDocument};
|
||||||
var queryText = queryService.GetSqlText(queryParams);
|
var queryText = queryService.GetSqlText(queryParams);
|
||||||
|
|
||||||
// Then: The text should be a subset of the constructed query
|
// Then: The text should be a subset of the constructed query
|
||||||
@@ -65,11 +66,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
var queryService = new QueryExecutionService(null, null);
|
var queryService = new QueryExecutionService(null, null);
|
||||||
|
|
||||||
// If: I attempt to get query text from execute string params
|
// If: I attempt to get query text from execute string params
|
||||||
var queryParams = new ExecuteStringParams { OwnerUri = Common.OwnerUri, Query = Common.StandardQuery };
|
var queryParams = new ExecuteStringParams {OwnerUri = Constants.OwnerUri, Query = Constants.StandardQuery};
|
||||||
var queryText = queryService.GetSqlText(queryParams);
|
var queryText = queryService.GetSqlText(queryParams);
|
||||||
|
|
||||||
// Then: The text should match the standard query
|
// Then: The text should match the standard query
|
||||||
Assert.Equal(Common.StandardQuery, queryText);
|
Assert.Equal(Constants.StandardQuery, queryText);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -128,7 +129,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If: I call the inter-service API to dispose a query with a null success function
|
// If: I call the inter-service API to dispose a query with a null success function
|
||||||
// Then: It should throw
|
// Then: It should throw
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>(
|
await Assert.ThrowsAsync<ArgumentNullException>(
|
||||||
() => qes.InterServiceDisposeQuery(Common.OwnerUri, null, failureFunc));
|
() => qes.InterServiceDisposeQuery(Constants.OwnerUri, null, failureFunc));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -141,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If: I call the inter-service API to dispose a query with a null success function
|
// If: I call the inter-service API to dispose a query with a null success function
|
||||||
// Then: It should throw
|
// Then: It should throw
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>(
|
await Assert.ThrowsAsync<ArgumentNullException>(
|
||||||
() => qes.InterServiceDisposeQuery(Common.OwnerUri, successFunc, null));
|
() => qes.InterServiceDisposeQuery(Constants.OwnerUri, successFunc, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -157,7 +158,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// ... I request to execute a valid query with all batches as no op
|
// ... I request to execute a valid query with all batches as no op
|
||||||
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.NoOpQuery));
|
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.NoOpQuery));
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri };
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddStandardQueryResultValidator()
|
.AddStandardQueryResultValidator()
|
||||||
@@ -170,7 +171,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
.AddEventValidation(QueryCompleteEvent.Type, p =>
|
.AddEventValidation(QueryCompleteEvent.Type, p =>
|
||||||
{
|
{
|
||||||
// Validate OwnerURI matches
|
// Validate OwnerURI matches
|
||||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||||
Assert.NotNull(p.BatchSummaries);
|
Assert.NotNull(p.BatchSummaries);
|
||||||
Assert.Equal(2, p.BatchSummaries.Length);
|
Assert.Equal(2, p.BatchSummaries.Length);
|
||||||
Assert.All(p.BatchSummaries, bs => Assert.Equal(0, bs.ResultSetSummaries.Length));
|
Assert.All(p.BatchSummaries, bs => Assert.Equal(0, bs.ResultSetSummaries.Length));
|
||||||
@@ -190,9 +191,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a valid query with no results
|
// ... I request to execute a valid query with no results
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri };
|
var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddStandardQueryResultValidator()
|
.AddStandardQueryResultValidator()
|
||||||
@@ -217,10 +218,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a valid query with results
|
// ... I request to execute a valid query with results
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false,
|
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false,
|
||||||
workspaceService);
|
workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddStandardQueryResultValidator()
|
.AddStandardQueryResultValidator()
|
||||||
@@ -245,10 +246,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a valid query with one batch and multiple result sets
|
// ... I request to execute a valid query with one batch and multiple result sets
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var dataset = new[] {Common.StandardTestResultSet, Common.StandardTestResultSet};
|
var dataset = new[] {Common.StandardTestResultSet, Common.StandardTestResultSet};
|
||||||
var queryService = Common.GetPrimedExecutionService(dataset, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(dataset, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddStandardQueryResultValidator()
|
.AddStandardQueryResultValidator()
|
||||||
@@ -273,9 +274,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request a to execute a valid query with multiple batches
|
// ... I request a to execute a valid query with multiple batches
|
||||||
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.StandardQuery));
|
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Constants.StandardQuery));
|
||||||
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddStandardQueryResultValidator()
|
.AddStandardQueryResultValidator()
|
||||||
@@ -305,7 +306,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// Given:
|
// Given:
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a query using a file URI that isn't connected
|
// ... I request to execute a query using a file URI that isn't connected
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = "notConnected", QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = "notConnected", QuerySelection = Common.WholeDocument };
|
||||||
|
|
||||||
@@ -327,16 +328,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a query
|
// ... I request to execute a query
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
// Note, we don't care about the results of the first request
|
// Note, we don't care about the results of the first request
|
||||||
var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await Common.AwaitExecution(queryService, queryParams, firstRequestContext.Object);
|
await Common.AwaitExecution(queryService, queryParams, firstRequestContext.Object);
|
||||||
|
|
||||||
// ... And then I request another query without waiting for the first to complete
|
// ... And then I request another query without waiting for the first to complete
|
||||||
queryService.ActiveQueries[Common.OwnerUri].HasExecuted = false; // Simulate query hasn't finished
|
queryService.ActiveQueries[Constants.OwnerUri].HasExecuted = false; // Simulate query hasn't finished
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||||
.Complete();
|
.Complete();
|
||||||
@@ -355,9 +356,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a query
|
// ... I request to execute a query
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
// Note, we don't care about the results of the first request
|
// Note, we don't care about the results of the first request
|
||||||
var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
@@ -391,7 +392,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I request to execute a query with a missing query string
|
// ... I request to execute a query with a missing query string
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = null };
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = null};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddErrorValidation<string>(Assert.NotEmpty)
|
.AddErrorValidation<string>(Assert.NotEmpty)
|
||||||
@@ -411,9 +412,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I request to execute a query that is invalid
|
// ... I request to execute a query that is invalid
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, true, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, true, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument };
|
var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
.AddStandardQueryResultValidator()
|
.AddStandardQueryResultValidator()
|
||||||
@@ -456,7 +457,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
return efv.AddEventValidation(BatchStartEvent.Type, p =>
|
return efv.AddEventValidation(BatchStartEvent.Type, p =>
|
||||||
{
|
{
|
||||||
// Validate OwnerURI and batch summary is returned
|
// Validate OwnerURI and batch summary is returned
|
||||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||||
Assert.NotNull(p.BatchSummary);
|
Assert.NotNull(p.BatchSummary);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -467,7 +468,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
return efv.AddEventValidation(BatchCompleteEvent.Type, p =>
|
return efv.AddEventValidation(BatchCompleteEvent.Type, p =>
|
||||||
{
|
{
|
||||||
// Validate OwnerURI and result summary are returned
|
// Validate OwnerURI and result summary are returned
|
||||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||||
Assert.NotNull(p.BatchSummary);
|
Assert.NotNull(p.BatchSummary);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -478,7 +479,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
return efv.AddEventValidation(MessageEvent.Type, p =>
|
return efv.AddEventValidation(MessageEvent.Type, p =>
|
||||||
{
|
{
|
||||||
// Validate OwnerURI and message are returned
|
// Validate OwnerURI and message are returned
|
||||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||||
Assert.NotNull(p.Message);
|
Assert.NotNull(p.Message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -489,7 +490,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
return efv.AddEventValidation(ResultSetCompleteEvent.Type, p =>
|
return efv.AddEventValidation(ResultSetCompleteEvent.Type, p =>
|
||||||
{
|
{
|
||||||
// Validate OwnerURI and summary are returned
|
// Validate OwnerURI and summary are returned
|
||||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||||
Assert.NotNull(p.ResultSetSummary);
|
Assert.NotNull(p.ResultSetSummary);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -499,7 +500,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
return efv.AddEventValidation(QueryCompleteEvent.Type, p =>
|
return efv.AddEventValidation(QueryCompleteEvent.Type, p =>
|
||||||
{
|
{
|
||||||
Assert.Equal(Common.OwnerUri, p.OwnerUri);
|
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||||
Assert.NotNull(p.BatchSummaries);
|
Assert.NotNull(p.BatchSummaries);
|
||||||
Assert.Equal(expectedBatches, p.BatchSummaries.Length);
|
Assert.Equal(expectedBatches, p.BatchSummaries.Length);
|
||||||
});
|
});
|
||||||
@@ -9,11 +9,12 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class ExecutionPlanTests
|
public class ExecutionPlanTests
|
||||||
{
|
{
|
||||||
@@ -136,12 +137,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I have a query that has results in the form of an execution plan
|
// ... I have a query that has results in the form of an execution plan
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams
|
var executeParams = new ExecuteDocumentSelectionParams
|
||||||
{
|
{
|
||||||
QuerySelection = null,
|
QuerySelection = null,
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||||
{
|
{
|
||||||
IncludeActualExecutionPlanXml = false,
|
IncludeActualExecutionPlanXml = false,
|
||||||
@@ -150,10 +151,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
};
|
};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for a valid execution plan
|
// ... And I then ask for a valid execution plan
|
||||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, BatchIndex = 0, ResultSetIndex = 0 };
|
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, BatchIndex = 0, ResultSetIndex = 0 };
|
||||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -170,9 +171,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I ask for an execution plan for a file that hasn't executed a query
|
// ... I ask for an execution plan for a file that hasn't executed a query
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||||
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
||||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||||
@@ -184,12 +185,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I have a query that hasn't finished executing (doesn't matter what)
|
// ... I have a query that hasn't finished executing (doesn't matter what)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams
|
var executeParams = new ExecuteDocumentSelectionParams
|
||||||
{
|
{
|
||||||
QuerySelection = null,
|
QuerySelection = null,
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||||
{
|
{
|
||||||
IncludeActualExecutionPlanXml = false,
|
IncludeActualExecutionPlanXml = false,
|
||||||
@@ -198,11 +199,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
};
|
};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
queryService.ActiveQueries[Common.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;
|
queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;
|
||||||
|
|
||||||
// ... And I then ask for a valid execution plan from it
|
// ... And I then ask for a valid execution plan from it
|
||||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||||
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
||||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||||
@@ -214,12 +215,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I have a query that doesn't have any result sets
|
// ... I have a query that doesn't have any result sets
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams
|
var executeParams = new ExecuteDocumentSelectionParams
|
||||||
{
|
{
|
||||||
QuerySelection = null,
|
QuerySelection = null,
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
ExecutionPlanOptions = new ExecutionPlanOptions
|
ExecutionPlanOptions = new ExecutionPlanOptions
|
||||||
{
|
{
|
||||||
IncludeActualExecutionPlanXml = false,
|
IncludeActualExecutionPlanXml = false,
|
||||||
@@ -228,10 +229,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
};
|
};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for an execution plan from a result set
|
// ... And I then ask for an execution plan from a result set
|
||||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||||
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
.AddErrorValidation<string>(Assert.NotNull).Complete();
|
||||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||||
@@ -8,7 +8,7 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||||
{
|
{
|
||||||
public class BatchTests
|
public class BatchTests
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,7 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||||
{
|
{
|
||||||
public class QueryTests
|
public class QueryTests
|
||||||
{
|
{
|
||||||
@@ -12,11 +12,12 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||||
{
|
{
|
||||||
public class ResultSetTests
|
public class ResultSetTests
|
||||||
{
|
{
|
||||||
@@ -27,10 +28,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then: I should get a null argument exception
|
// Then: I should get a null argument exception
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(null, false, Common.NoOpQuery), Common.Ordinal, Common.Ordinal,
|
GetReader(null, false, Common.NoOpQuery), Common.Ordinal, Common.Ordinal,
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
Assert.Throws<ArgumentNullException>(() => rs.SaveAs(
|
Assert.Throws<ArgumentNullException>(() => rs.SaveAs(
|
||||||
null,
|
null,
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()),
|
MemoryFileSystem.GetFileStreamFactory(),
|
||||||
null, null));
|
null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then: I should get a null argument exception
|
// Then: I should get a null argument exception
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(null, false, Common.NoOpQuery), Common.Ordinal, Common.Ordinal,
|
GetReader(null, false, Common.NoOpQuery), Common.Ordinal, Common.Ordinal,
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
Assert.Throws<ArgumentNullException>(() => rs.SaveAs(
|
Assert.Throws<ArgumentNullException>(() => rs.SaveAs(
|
||||||
new SaveResultsRequestParams(),
|
new SaveResultsRequestParams(),
|
||||||
null, null, null));
|
null, null, null));
|
||||||
@@ -54,10 +55,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then: I should get an invalid operation exception
|
// Then: I should get an invalid operation exception
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(null, false, Common.NoOpQuery), Common.Ordinal, Common.Ordinal,
|
GetReader(null, false, Common.NoOpQuery), Common.Ordinal, Common.Ordinal,
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
Assert.Throws<InvalidOperationException>(() => rs.SaveAs(
|
Assert.Throws<InvalidOperationException>(() => rs.SaveAs(
|
||||||
new SaveResultsRequestParams(),
|
new SaveResultsRequestParams(),
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()),
|
MemoryFileSystem.GetFileStreamFactory(),
|
||||||
null, null));
|
null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,16 +68,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Setup:
|
// Setup:
|
||||||
// ... Create a result set that has been executed
|
// ... Create a result set that has been executed
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(Common.StandardTestDataSet, false, Common.StandardQuery),
|
GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery),
|
||||||
Common.Ordinal, Common.Ordinal,
|
Common.Ordinal, Common.Ordinal,
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
MemoryFileSystem.GetFileStreamFactory());
|
||||||
|
|
||||||
// ... Insert a non-started task into the save as tasks
|
// ... Insert a non-started task into the save as tasks
|
||||||
rs.SaveTasks.AddOrUpdate(Common.OwnerUri, new Task(() => { }), (s, t) => null);
|
rs.SaveTasks.AddOrUpdate(Constants.OwnerUri, new Task(() => { }), (s, t) => null);
|
||||||
|
|
||||||
// If: I attempt to save results with the same name as the non-completed task
|
// If: I attempt to save results with the same name as the non-completed task
|
||||||
// Then: I should get an invalid operation exception
|
// Then: I should get an invalid operation exception
|
||||||
var requestParams = new SaveResultsRequestParams {FilePath = Common.OwnerUri};
|
var requestParams = new SaveResultsRequestParams {FilePath = Constants.OwnerUri};
|
||||||
Assert.Throws<InvalidOperationException>(() => rs.SaveAs(
|
Assert.Throws<InvalidOperationException>(() => rs.SaveAs(
|
||||||
requestParams, GetMockFactory(GetMockWriter().Object, null),
|
requestParams, GetMockFactory(GetMockWriter().Object, null),
|
||||||
null, null));
|
null, null));
|
||||||
@@ -86,15 +87,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
public async Task SaveAsWithoutRowSelection()
|
public async Task SaveAsWithoutRowSelection()
|
||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... Create a fake place to store data
|
|
||||||
Dictionary<string, byte[]> mockFs = new Dictionary<string, byte[]>();
|
|
||||||
|
|
||||||
// ... Create a mock reader/writer for reading the result
|
// ... Create a mock reader/writer for reading the result
|
||||||
IFileStreamFactory resultFactory = Common.GetFileStreamFactory(mockFs);
|
IFileStreamFactory resultFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
|
|
||||||
// ... Create a result set with dummy data and read to the end
|
// ... Create a result set with dummy data and read to the end
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(Common.StandardTestDataSet, false, Common.StandardQuery),
|
GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery),
|
||||||
Common.Ordinal, Common.Ordinal,
|
Common.Ordinal, Common.Ordinal,
|
||||||
resultFactory);
|
resultFactory);
|
||||||
await rs.ReadResultToEnd(CancellationToken.None);
|
await rs.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -104,13 +102,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
IFileStreamFactory saveFactory = GetMockFactory(saveWriter.Object, resultFactory.GetReader);
|
IFileStreamFactory saveFactory = GetMockFactory(saveWriter.Object, resultFactory.GetReader);
|
||||||
|
|
||||||
// If: I attempt to save results and await completion
|
// If: I attempt to save results and await completion
|
||||||
rs.SaveAs(new SaveResultsRequestParams {FilePath = Common.OwnerUri}, saveFactory, null, null);
|
rs.SaveAs(new SaveResultsRequestParams {FilePath = Constants.OwnerUri}, saveFactory, null, null);
|
||||||
Assert.True(rs.SaveTasks.ContainsKey(Common.OwnerUri));
|
Assert.True(rs.SaveTasks.ContainsKey(Constants.OwnerUri));
|
||||||
await rs.SaveTasks[Common.OwnerUri];
|
await rs.SaveTasks[Constants.OwnerUri];
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... The task should have completed successfully
|
// ... The task should have completed successfully
|
||||||
Assert.Equal(TaskStatus.RanToCompletion, rs.SaveTasks[Common.OwnerUri].Status);
|
Assert.Equal(TaskStatus.RanToCompletion, rs.SaveTasks[Constants.OwnerUri].Status);
|
||||||
|
|
||||||
// ... All the rows should have been written successfully
|
// ... All the rows should have been written successfully
|
||||||
saveWriter.Verify(
|
saveWriter.Verify(
|
||||||
@@ -122,15 +120,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
public async Task SaveAsWithRowSelection()
|
public async Task SaveAsWithRowSelection()
|
||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... Create a fake place to store data
|
|
||||||
Dictionary<string, byte[]> mockFs = new Dictionary<string, byte[]>();
|
|
||||||
|
|
||||||
// ... Create a mock reader/writer for reading the result
|
// ... Create a mock reader/writer for reading the result
|
||||||
IFileStreamFactory resultFactory = Common.GetFileStreamFactory(mockFs);
|
IFileStreamFactory resultFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||||
|
|
||||||
// ... Create a result set with dummy data and read to the end
|
// ... Create a result set with dummy data and read to the end
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(Common.StandardTestDataSet, false, Common.StandardQuery),
|
GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery),
|
||||||
Common.Ordinal, Common.Ordinal,
|
Common.Ordinal, Common.Ordinal,
|
||||||
resultFactory);
|
resultFactory);
|
||||||
await rs.ReadResultToEnd(CancellationToken.None);
|
await rs.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -142,19 +137,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// If: I attempt to save results that has a selection made
|
// If: I attempt to save results that has a selection made
|
||||||
var saveParams = new SaveResultsRequestParams
|
var saveParams = new SaveResultsRequestParams
|
||||||
{
|
{
|
||||||
FilePath = Common.OwnerUri,
|
FilePath = Constants.OwnerUri,
|
||||||
RowStartIndex = 1,
|
RowStartIndex = 1,
|
||||||
RowEndIndex = Common.StandardRows - 2,
|
RowEndIndex = Common.StandardRows - 2,
|
||||||
ColumnStartIndex = 0, // Column start/end doesn't matter, but are required to be
|
ColumnStartIndex = 0, // Column start/end doesn't matter, but are required to be
|
||||||
ColumnEndIndex = 10 // considered a "save selection"
|
ColumnEndIndex = 10 // considered a "save selection"
|
||||||
};
|
};
|
||||||
rs.SaveAs(saveParams, saveFactory, null, null);
|
rs.SaveAs(saveParams, saveFactory, null, null);
|
||||||
Assert.True(rs.SaveTasks.ContainsKey(Common.OwnerUri));
|
Assert.True(rs.SaveTasks.ContainsKey(Constants.OwnerUri));
|
||||||
await rs.SaveTasks[Common.OwnerUri];
|
await rs.SaveTasks[Constants.OwnerUri];
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... The task should have completed successfully
|
// ... The task should have completed successfully
|
||||||
Assert.Equal(TaskStatus.RanToCompletion, rs.SaveTasks[Common.OwnerUri].Status);
|
Assert.Equal(TaskStatus.RanToCompletion, rs.SaveTasks[Constants.OwnerUri].Status);
|
||||||
|
|
||||||
// ... All the rows should have been written successfully
|
// ... All the rows should have been written successfully
|
||||||
saveWriter.Verify(
|
saveWriter.Verify(
|
||||||
@@ -6,18 +6,18 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||||
{
|
{
|
||||||
public class ServiceIntegrationTests
|
public class ServiceIntegrationTests
|
||||||
{
|
{
|
||||||
@@ -25,7 +25,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SaveResultsCsvNonExistentQuery()
|
public async Task SaveResultsCsvNonExistentQuery()
|
||||||
|
|
||||||
{
|
{
|
||||||
// Given: A working query and workspace service
|
// Given: A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(null);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(null);
|
||||||
@@ -34,20 +33,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// If: I attempt to save a result set from a query that doesn't exist
|
// If: I attempt to save a result set from a query that doesn't exist
|
||||||
SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
|
SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
|
||||||
{
|
{
|
||||||
OwnerUri = Common.OwnerUri // Won't exist because nothing has executed
|
OwnerUri = Constants.OwnerUri // Won't exist because nothing has executed
|
||||||
};
|
};
|
||||||
object error = null;
|
var evf = new EventFlowValidator<SaveResultRequestResult>()
|
||||||
var requestContext = RequestContextMocks.Create<SaveResultRequestResult>(null)
|
.AddStandardErrorValidator()
|
||||||
.AddErrorHandling(o => error = o);
|
.Complete();
|
||||||
await qes.HandleSaveResultsAsCsvRequest(saveParams, requestContext.Object);
|
await qes.HandleSaveResultsAsCsvRequest(saveParams, evf.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... An error event should have been fired
|
// ... An error event should have been fired
|
||||||
// ... No success event should have been fired
|
// ... No success event should have been fired
|
||||||
VerifyResponseCalls(requestContext, false, true);
|
evf.Validate();
|
||||||
Assert.IsType<SaveResultRequestError>(error);
|
|
||||||
Assert.NotNull(error);
|
|
||||||
Assert.NotNull(((SaveResultRequestError)error).message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -55,22 +51,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
{
|
{
|
||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
||||||
SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
|
SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
|
||||||
{
|
{
|
||||||
BatchIndex = 0,
|
BatchIndex = 0,
|
||||||
FilePath = "qqq",
|
FilePath = "qqq",
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
ResultSetIndex = 0,
|
ResultSetIndex = 0,
|
||||||
ColumnStartIndex = -1,
|
ColumnStartIndex = -1,
|
||||||
ColumnEndIndex = 100,
|
ColumnEndIndex = 100,
|
||||||
@@ -78,10 +74,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
RowEndIndex = 5
|
RowEndIndex = 5
|
||||||
};
|
};
|
||||||
qes.CsvFileFactory = GetCsvStreamFactory(storage, saveParams);
|
qes.CsvFileFactory = GetCsvStreamFactory(storage, saveParams);
|
||||||
object error = null;
|
var efv = new EventFlowValidator<SaveResultRequestResult>()
|
||||||
var requestContext = RequestContextMocks.Create<SaveResultRequestResult>(null)
|
.AddStandardErrorValidator()
|
||||||
.AddErrorHandling(e => error = e);
|
.Complete();
|
||||||
await qes.HandleSaveResultsAsCsvRequest(saveParams, requestContext.Object);
|
|
||||||
|
|
||||||
|
await qes.HandleSaveResultsAsCsvRequest(saveParams, efv.Object);
|
||||||
await qes.ActiveQueries[saveParams.OwnerUri]
|
await qes.ActiveQueries[saveParams.OwnerUri]
|
||||||
.Batches[saveParams.BatchIndex]
|
.Batches[saveParams.BatchIndex]
|
||||||
.ResultSets[saveParams.ResultSetIndex]
|
.ResultSets[saveParams.ResultSetIndex]
|
||||||
@@ -90,10 +88,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then:
|
// Then:
|
||||||
// ... An error event should have been fired
|
// ... An error event should have been fired
|
||||||
// ... No success event should have been fired
|
// ... No success event should have been fired
|
||||||
VerifyResponseCalls(requestContext, false, true);
|
efv.Validate();
|
||||||
Assert.IsType<SaveResultRequestError>(error);
|
|
||||||
Assert.NotNull(error);
|
|
||||||
Assert.NotNull(((SaveResultRequestError)error).message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -101,28 +96,30 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
{
|
{
|
||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set from a query
|
// If: I attempt to save a result set from a query
|
||||||
SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
|
SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
|
||||||
{
|
{
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
FilePath = "qqq",
|
FilePath = "qqq",
|
||||||
BatchIndex = 0,
|
BatchIndex = 0,
|
||||||
ResultSetIndex = 0
|
ResultSetIndex = 0
|
||||||
};
|
};
|
||||||
qes.CsvFileFactory = GetCsvStreamFactory(storage, saveParams);
|
qes.CsvFileFactory = GetCsvStreamFactory(storage, saveParams);
|
||||||
SaveResultRequestResult result = null;
|
var efv = new EventFlowValidator<SaveResultRequestResult>()
|
||||||
var requestContext = RequestContextMocks.Create<SaveResultRequestResult>(r => result = r);
|
.AddStandardResultValidator()
|
||||||
await qes.HandleSaveResultsAsCsvRequest(saveParams, requestContext.Object);
|
.Complete();
|
||||||
|
|
||||||
|
await qes.HandleSaveResultsAsCsvRequest(saveParams, efv.Object);
|
||||||
await qes.ActiveQueries[saveParams.OwnerUri]
|
await qes.ActiveQueries[saveParams.OwnerUri]
|
||||||
.Batches[saveParams.BatchIndex]
|
.Batches[saveParams.BatchIndex]
|
||||||
.ResultSets[saveParams.ResultSetIndex]
|
.ResultSets[saveParams.ResultSetIndex]
|
||||||
@@ -131,9 +128,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then:
|
// Then:
|
||||||
// ... I should have a successful result
|
// ... I should have a successful result
|
||||||
// ... There should not have been an error
|
// ... There should not have been an error
|
||||||
VerifyResponseCalls(requestContext, true, false);
|
efv.Validate();
|
||||||
Assert.NotNull(result);
|
|
||||||
Assert.Null(result.Messages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -151,20 +146,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// If: I attempt to save a result set from a query that doesn't exist
|
// If: I attempt to save a result set from a query that doesn't exist
|
||||||
SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams
|
SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams
|
||||||
{
|
{
|
||||||
OwnerUri = Common.OwnerUri // Won't exist because nothing has executed
|
OwnerUri = Constants.OwnerUri // Won't exist because nothing has executed
|
||||||
};
|
};
|
||||||
object error = null;
|
var efv = new EventFlowValidator<SaveResultRequestResult>()
|
||||||
var requestContext = RequestContextMocks.Create<SaveResultRequestResult>(null)
|
.AddStandardErrorValidator()
|
||||||
.AddErrorHandling(o => error = o);
|
.Complete();
|
||||||
await qes.HandleSaveResultsAsJsonRequest(saveParams, requestContext.Object);
|
await qes.HandleSaveResultsAsJsonRequest(saveParams, efv.Object);
|
||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... An error event should have been fired
|
// ... An error event should have been fired
|
||||||
// ... No success event should have been fired
|
// ... No success event should have been fired
|
||||||
VerifyResponseCalls(requestContext, false, true);
|
efv.Validate();
|
||||||
Assert.IsType<SaveResultRequestError>(error);
|
|
||||||
Assert.NotNull(error);
|
|
||||||
Assert.NotNull(((SaveResultRequestError)error).message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -172,22 +164,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
{
|
{
|
||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
// If: I attempt to save a result set and get it to throw because of invalid column selection
|
||||||
SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams
|
SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams
|
||||||
{
|
{
|
||||||
BatchIndex = 0,
|
BatchIndex = 0,
|
||||||
FilePath = "qqq",
|
FilePath = "qqq",
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
ResultSetIndex = 0,
|
ResultSetIndex = 0,
|
||||||
ColumnStartIndex = -1,
|
ColumnStartIndex = -1,
|
||||||
ColumnEndIndex = 100,
|
ColumnEndIndex = 100,
|
||||||
@@ -195,10 +187,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
RowEndIndex = 5
|
RowEndIndex = 5
|
||||||
};
|
};
|
||||||
qes.JsonFileFactory = GetJsonStreamFactory(storage, saveParams);
|
qes.JsonFileFactory = GetJsonStreamFactory(storage, saveParams);
|
||||||
object error = null;
|
var efv = new EventFlowValidator<SaveResultRequestResult>()
|
||||||
var requestContext = RequestContextMocks.Create<SaveResultRequestResult>(null)
|
.AddStandardErrorValidator()
|
||||||
.AddErrorHandling(e => error = e);
|
.Complete();
|
||||||
await qes.HandleSaveResultsAsJsonRequest(saveParams, requestContext.Object);
|
await qes.HandleSaveResultsAsJsonRequest(saveParams, efv.Object);
|
||||||
await qes.ActiveQueries[saveParams.OwnerUri]
|
await qes.ActiveQueries[saveParams.OwnerUri]
|
||||||
.Batches[saveParams.BatchIndex]
|
.Batches[saveParams.BatchIndex]
|
||||||
.ResultSets[saveParams.ResultSetIndex]
|
.ResultSets[saveParams.ResultSetIndex]
|
||||||
@@ -207,10 +199,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then:
|
// Then:
|
||||||
// ... An error event should have been fired
|
// ... An error event should have been fired
|
||||||
// ... No success event should have been fired
|
// ... No success event should have been fired
|
||||||
VerifyResponseCalls(requestContext, false, true);
|
efv.Validate();
|
||||||
Assert.IsType<SaveResultRequestError>(error);
|
|
||||||
Assert.NotNull(error);
|
|
||||||
Assert.NotNull(((SaveResultRequestError)error).message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -218,28 +207,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
{
|
{
|
||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await qes.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await qes.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// If: I attempt to save a result set from a query
|
// If: I attempt to save a result set from a query
|
||||||
SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams
|
SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams
|
||||||
{
|
{
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = Constants.OwnerUri,
|
||||||
FilePath = "qqq",
|
FilePath = "qqq",
|
||||||
BatchIndex = 0,
|
BatchIndex = 0,
|
||||||
ResultSetIndex = 0
|
ResultSetIndex = 0
|
||||||
};
|
};
|
||||||
qes.JsonFileFactory = GetJsonStreamFactory(storage, saveParams);
|
qes.JsonFileFactory = GetJsonStreamFactory(storage, saveParams);
|
||||||
SaveResultRequestResult result = null;
|
var efv = new EventFlowValidator<SaveResultRequestResult>()
|
||||||
var requestContext = RequestContextMocks.Create<SaveResultRequestResult>(r => result = r);
|
.AddStandardResultValidator()
|
||||||
await qes.HandleSaveResultsAsJsonRequest(saveParams, requestContext.Object);
|
.Complete();
|
||||||
|
await qes.HandleSaveResultsAsJsonRequest(saveParams, efv.Object);
|
||||||
await qes.ActiveQueries[saveParams.OwnerUri]
|
await qes.ActiveQueries[saveParams.OwnerUri]
|
||||||
.Batches[saveParams.BatchIndex]
|
.Batches[saveParams.BatchIndex]
|
||||||
.ResultSets[saveParams.ResultSetIndex]
|
.ResultSets[saveParams.ResultSetIndex]
|
||||||
@@ -248,23 +238,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Then:
|
// Then:
|
||||||
// ... I should have a successful result
|
// ... I should have a successful result
|
||||||
// ... There should not have been an error
|
// ... There should not have been an error
|
||||||
VerifyResponseCalls(requestContext, true, false);
|
efv.Validate();
|
||||||
Assert.NotNull(result);
|
|
||||||
Assert.Null(result.Messages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Helpers
|
#region Private Helpers
|
||||||
|
|
||||||
private static void VerifyResponseCalls(Mock<RequestContext<SaveResultRequestResult>> requestContext, bool successCalled, bool errorCalled)
|
|
||||||
{
|
|
||||||
requestContext.Verify(rc => rc.SendResult(It.IsAny<SaveResultRequestResult>()),
|
|
||||||
successCalled ? Times.Once() : Times.Never());
|
|
||||||
requestContext.Verify(rc => rc.SendError(It.IsAny<object>()),
|
|
||||||
errorCalled ? Times.Once() : Times.Never());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IFileStreamFactory GetCsvStreamFactory(IDictionary<string, byte[]> storage, SaveResultsAsCsvRequestParams saveParams)
|
private static IFileStreamFactory GetCsvStreamFactory(IDictionary<string, byte[]> storage, SaveResultsAsCsvRequestParams saveParams)
|
||||||
{
|
{
|
||||||
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
||||||
@@ -297,4 +277,27 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SaveResultEventFlowValidatorExtensions
|
||||||
|
{
|
||||||
|
public static EventFlowValidator<SaveResultRequestResult> AddStandardErrorValidator(
|
||||||
|
this EventFlowValidator<SaveResultRequestResult> efv)
|
||||||
|
{
|
||||||
|
return efv.AddErrorValidation<SaveResultRequestError>(e =>
|
||||||
|
{
|
||||||
|
Assert.NotNull(e);
|
||||||
|
Assert.NotNull(e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EventFlowValidator<SaveResultRequestResult> AddStandardResultValidator(
|
||||||
|
this EventFlowValidator<SaveResultRequestResult> efv)
|
||||||
|
{
|
||||||
|
return efv.AddResultValidation(r =>
|
||||||
|
{
|
||||||
|
Assert.NotNull(r);
|
||||||
|
Assert.Null(r.Messages);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class SettingsTests
|
public class SettingsTests
|
||||||
{
|
{
|
||||||
@@ -4,10 +4,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class SpecialActionTests
|
public class SpecialActionTests
|
||||||
{
|
{
|
||||||
@@ -4,16 +4,16 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
{
|
{
|
||||||
public class SubsetTests
|
public class SubsetTests
|
||||||
{
|
{
|
||||||
@@ -64,7 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// ... I have a resultset that hasn't been executed and I request a valid result set from it
|
// ... I have a resultset that hasn't been executed and I request a valid result set from it
|
||||||
// Then:
|
// Then:
|
||||||
// ... It should throw an exception for having not been read
|
// ... It should throw an exception for having not been read
|
||||||
ResultSet rs = new ResultSet(new TestDbDataReader(null), Common.Ordinal, Common.Ordinal, Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
ResultSet rs = new ResultSet(new TestDbDataReader(null), Common.Ordinal, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory());
|
||||||
await Assert.ThrowsAsync<InvalidOperationException>(() => rs.GetSubset(0, 1));
|
await Assert.ThrowsAsync<InvalidOperationException>(() => rs.GetSubset(0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,15 +130,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I have a query that has results (doesn't matter what)
|
// ... I have a query that has results (doesn't matter what)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for a valid set of results from it
|
// ... And I then ask for a valid set of results from it
|
||||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -155,9 +155,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I ask for a set of results for a file that hasn't executed a query
|
// ... I ask for a set of results for a file that hasn't executed a query
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -174,16 +174,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I have a query that hasn't finished executing (doesn't matter what)
|
// ... I have a query that hasn't finished executing (doesn't matter what)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
queryService.ActiveQueries[Common.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;
|
queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;
|
||||||
|
|
||||||
// ... And I then ask for a valid set of results from it
|
// ... And I then ask for a valid set of results from it
|
||||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -200,15 +200,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
{
|
{
|
||||||
// If:
|
// If:
|
||||||
// ... I have a query that doesn't have any result sets
|
// ... I have a query that doesn't have any result sets
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;
|
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||||
|
|
||||||
// ... And I then ask for a set of results from it
|
// ... And I then ask for a set of results from it
|
||||||
var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||||
.AddResultValidation(r =>
|
.AddResultValidation(r =>
|
||||||
{
|
{
|
||||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
public class AsyncLockTests
|
public class AsyncLockTests
|
||||||
{
|
{
|
||||||
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
public class AsyncQueueTests
|
public class AsyncQueueTests
|
||||||
{
|
{
|
||||||
@@ -4,11 +4,11 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers;
|
||||||
using HostingMessage = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts.Message;
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using HostingMessage = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts.Message;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
public class TestMessageContents
|
public class TestMessageContents
|
||||||
{
|
{
|
||||||
@@ -8,7 +8,7 @@ using System.Linq;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logger test cases
|
/// Logger test cases
|
||||||
@@ -3,13 +3,11 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ScriptFile test case
|
/// ScriptFile test case
|
||||||
@@ -10,7 +10,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
public class ServiceHostTests
|
public class ServiceHostTests
|
||||||
{
|
{
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ServiceHost
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ScriptFile test case
|
/// ScriptFile test case
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SqlContext
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the SqlContext settins
|
/// Tests for the SqlContext settins
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.Test.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the CommandOptions class
|
/// Tests for the CommandOptions class
|
||||||
@@ -11,7 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||||
{
|
{
|
||||||
public class EventFlowValidator<TRequestContext>
|
public class EventFlowValidator<TRequestContext>
|
||||||
{
|
{
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.Test.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for the LongList class
|
/// Tests for the LongList class
|
||||||
@@ -7,7 +7,7 @@ using System.Reflection;
|
|||||||
using Moq.Language;
|
using Moq.Language;
|
||||||
using Moq.Language.Flow;
|
using Moq.Language.Flow;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||||
{
|
{
|
||||||
public static class MoqExtensions
|
public static class MoqExtensions
|
||||||
{
|
{
|
||||||
@@ -9,7 +9,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||||
{
|
{
|
||||||
public static class RequestContextMocks
|
public static class RequestContextMocks
|
||||||
{
|
{
|
||||||
@@ -3,10 +3,9 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using Microsoft.SqlTools.ServiceLayer;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.Test.Utility
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
||||||
{
|
{
|
||||||
public class SrTests
|
public class SrTests
|
||||||
{
|
{
|
||||||
@@ -16,10 +15,10 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void SrPropertiesTest()
|
public void SrPropertiesTest()
|
||||||
{
|
{
|
||||||
Assert.NotNull(SR.QueryServiceSubsetBatchNotCompleted);
|
Assert.NotNull(ServiceLayer.SR.QueryServiceSubsetBatchNotCompleted);
|
||||||
Assert.NotNull(SR.QueryServiceFileWrapperWriteOnly);
|
Assert.NotNull(ServiceLayer.SR.QueryServiceFileWrapperWriteOnly);
|
||||||
Assert.NotNull(SR.QueryServiceFileWrapperNotInitialized);
|
Assert.NotNull(ServiceLayer.SR.QueryServiceFileWrapperNotInitialized);
|
||||||
Assert.NotNull(SR.QueryServiceColumnNull);
|
Assert.NotNull(ServiceLayer.SR.QueryServiceColumnNull);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user