diff --git a/sqltoolsservice.sln b/sqltoolsservice.sln
index 630d13a2..0d94b3dc 100644
--- a/sqltoolsservice.sln
+++ b/sqltoolsservice.sln
@@ -53,28 +53,45 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeCoverage", "CodeCoverag
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.PerfTests", "test\Microsoft.SqlTools.ServiceLayer.PerfTests\Microsoft.SqlTools.ServiceLayer.PerfTests.xproj", "{7E5968AB-83D7-4738-85A2-416A50F13D2F}"
EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.IntegrationTests", "test\Microsoft.SqlTools.ServiceLayer.IntegrationTests\Microsoft.SqlTools.ServiceLayer.IntegrationTests.xproj", "{08AF0209-D598-47BB-9DFD-FC9E74C0FE56}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
+ Integration|Any CPU = Integration|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0D61DC2B-DA66-441D-B9D0-F76C98F780F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D61DC2B-DA66-441D-B9D0-F76C98F780F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0D61DC2B-DA66-441D-B9D0-F76C98F780F9}.Integration|Any CPU.ActiveCfg = Integration|Any CPU
+ {0D61DC2B-DA66-441D-B9D0-F76C98F780F9}.Integration|Any CPU.Build.0 = Integration|Any CPU
{0D61DC2B-DA66-441D-B9D0-F76C98F780F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D61DC2B-DA66-441D-B9D0-F76C98F780F9}.Release|Any CPU.Build.0 = Release|Any CPU
{2D771D16-9D85-4053-9F79-E2034737DEEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D771D16-9D85-4053-9F79-E2034737DEEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2D771D16-9D85-4053-9F79-E2034737DEEF}.Integration|Any CPU.ActiveCfg = Integration|Any CPU
+ {2D771D16-9D85-4053-9F79-E2034737DEEF}.Integration|Any CPU.Build.0 = Integration|Any CPU
{2D771D16-9D85-4053-9F79-E2034737DEEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D771D16-9D85-4053-9F79-E2034737DEEF}.Release|Any CPU.Build.0 = Release|Any CPU
{CC785604-6277-4878-8DA9-360C47158E96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC785604-6277-4878-8DA9-360C47158E96}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CC785604-6277-4878-8DA9-360C47158E96}.Integration|Any CPU.ActiveCfg = Release|Any CPU
+ {CC785604-6277-4878-8DA9-360C47158E96}.Integration|Any CPU.Build.0 = Release|Any CPU
{CC785604-6277-4878-8DA9-360C47158E96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC785604-6277-4878-8DA9-360C47158E96}.Release|Any CPU.Build.0 = Release|Any CPU
{7E5968AB-83D7-4738-85A2-416A50F13D2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E5968AB-83D7-4738-85A2-416A50F13D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7E5968AB-83D7-4738-85A2-416A50F13D2F}.Integration|Any CPU.ActiveCfg = Release|Any CPU
+ {7E5968AB-83D7-4738-85A2-416A50F13D2F}.Integration|Any CPU.Build.0 = Release|Any CPU
{7E5968AB-83D7-4738-85A2-416A50F13D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E5968AB-83D7-4738-85A2-416A50F13D2F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56}.Integration|Any CPU.ActiveCfg = Integration|Any CPU
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56}.Integration|Any CPU.Build.0 = Integration|Any CPU
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -86,5 +103,6 @@ Global
{B7D21727-2926-452B-9610-3ADB0BB6D789} = {F9978D78-78FE-4E92-A7D6-D436B7683EF6}
{87D9C7D9-18F4-4AB9-B20D-66C02B6075E2} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
{7E5968AB-83D7-4738-85A2-416A50F13D2F} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
+ {08AF0209-D598-47BB-9DFD-FC9E74C0FE56} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
EndGlobalSection
EndGlobal
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs
index 33b9e4a8..83fec0a4 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs
@@ -42,3 +42,4 @@ using System.Runtime.InteropServices;
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test")]
+[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.IntegrationTests")]
diff --git a/test/CodeCoverage/codecoverage.bat b/test/CodeCoverage/codecoverage.bat
index 4e0920e2..626980df 100644
--- a/test/CodeCoverage/codecoverage.bat
+++ b/test/CodeCoverage/codecoverage.bat
@@ -18,6 +18,7 @@ dotnet build %WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\project.json
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.TestDriver\project.json %DOTNETCONFIG%
+dotnet build %WORKINGDIR%..\..\test\Microsoft.SqlTools.ServiceLayer.IntegrationTests\project.json %DOTNETCONFIG%
SET TEST_SERVER=localhost
SET SQLTOOLSSERVICE_EXE=%WORKINGDIR%..\..\src\Microsoft.SqlTools.ServiceLayer\bin\Integration\netcoreapp1.0\win7-x64\Microsoft.SqlTools.ServiceLayer.exe
@@ -33,6 +34,8 @@ 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.Test\project.json %DOTNETCONFIG%" -oldstyle -filter:"+[Microsoft.SqlTools.*]* -[xunit*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.Test\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*]*" -output:coverage.xml -searchdirs:%WORKINGDIR%..\Microsoft.SqlTools.ServiceLayer.IntegrationTests\bin\Debug\netcoreapp1.0
+
"%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"
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/App.config b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/App.config
new file mode 100644
index 00000000..570b96df
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/App.config
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/AssemblyInfo.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/AssemblyInfo.cs
new file mode 100644
index 00000000..70421c18
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/AssemblyInfo.cs
@@ -0,0 +1,8 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Xunit;
+
+[assembly: CollectionBehavior(DisableTestParallelization = true)]
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs
similarity index 99%
rename from test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs
rename to test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs
index 65ff5eaf..4a1f7f3c 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ReliableConnectionTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Connection/ReliableConnectionTests.cs
@@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-#if LIVE_CONNECTION_TESTS
-
using System;
using System.Collections.Generic;
using System.Data;
@@ -24,7 +22,7 @@ using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.Retry
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy.TimeBasedRetryPolicy;
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.SqlSchemaModelErrorCodes;
-namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
+namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
{
///
/// Tests for the ReliableConnection module.
@@ -951,6 +949,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
command.StatementCompleted -= handler;
}
}
-}
-
-#endif // LIVE_CONNECTION_TESTS
+}
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs
new file mode 100644
index 00000000..27000d83
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/LanguageServiceTests.cs
@@ -0,0 +1,139 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using Microsoft.SqlServer.Management.SqlParser.Parser;
+using Microsoft.SqlTools.ServiceLayer.Connection;
+using Microsoft.SqlTools.ServiceLayer.LanguageServices;
+using Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion;
+using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
+using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
+using Microsoft.SqlTools.Test.Utility;
+using Xunit;
+
+namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServer
+{
+ ///
+ /// Tests for the ServiceHost Language Service tests
+ ///
+ public class LanguageServiceTests
+ {
+ private static void GetLiveAutoCompleteTestObjects(
+ out TextDocumentPosition textDocument,
+ out ScriptFile scriptFile,
+ out ConnectionInfo connInfo)
+ {
+ textDocument = new TextDocumentPosition
+ {
+ TextDocument = new TextDocumentIdentifier { Uri = TestObjects.ScriptUri },
+ Position = new Position
+ {
+ Line = 0,
+ Character = 0
+ }
+ };
+
+ connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
+ }
+
+ ///
+ /// Test the service initialization code path and verify nothing throws
+ ///
+ [Fact]
+ public void ServiceInitialization()
+ {
+ try
+ {
+ TestObjects.InitializeTestServices();
+ }
+ catch (System.ArgumentException)
+ {
+
+ }
+ Assert.True(LanguageService.Instance.Context != null);
+ Assert.True(LanguageService.ConnectionServiceInstance != null);
+ Assert.True(LanguageService.Instance.CurrentSettings != null);
+ Assert.True(LanguageService.Instance.CurrentWorkspace != null);
+ }
+
+ ///
+ /// Test the service initialization code path and verify nothing throws
+ ///
+ [Fact]
+ public void PrepopulateCommonMetadata()
+ {
+ ScriptFile scriptFile;
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
+
+ ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
+
+ AutoCompleteHelper.PrepopulateCommonMetadata(connInfo, scriptInfo, null);
+ }
+
+ // This test currently requires a live database connection to initialize
+ // SMO connected metadata provider. Since we don't want a live DB dependency
+ // in the CI unit tests this scenario is currently disabled.
+ [Fact]
+ public void AutoCompleteFindCompletions()
+ {
+ TextDocumentPosition textDocument;
+ ConnectionInfo connInfo;
+ ScriptFile scriptFile;
+ GetLiveAutoCompleteTestObjects(out textDocument, out scriptFile, out connInfo);
+
+ textDocument.Position.Character = 7;
+ scriptFile.Contents = "select ";
+
+ var autoCompleteService = LanguageService.Instance;
+ var completions = autoCompleteService.GetCompletionItems(
+ textDocument,
+ scriptFile,
+ connInfo);
+
+ Assert.True(completions.Length > 0);
+ }
+
+ ///
+ /// Verify that GetSignatureHelp returns not null when the provided TextDocumentPosition
+ /// has an associated ScriptParseInfo and the provided query has a function that should
+ /// provide signature help.
+ ///
+ [Fact]
+ public async void GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
+ {
+ // When we make a connection to a live database
+ ScriptFile scriptFile;
+ Hosting.ServiceHost.SendEventIgnoreExceptions = true;
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
+
+ // And we place the cursor after a function that should prompt for signature help
+ string queryWithFunction = "EXEC sys.fn_isrolemember ";
+ scriptFile.Contents = queryWithFunction;
+ TextDocumentPosition textDocument = new TextDocumentPosition
+ {
+ TextDocument = new TextDocumentIdentifier
+ {
+ Uri = scriptFile.ClientFilePath
+ },
+ Position = new Position
+ {
+ Line = 0,
+ Character = queryWithFunction.Length
+ }
+ };
+
+ // If the SQL has already been parsed
+ var service = LanguageService.Instance;
+ await service.UpdateLanguageServiceOnConnection(connInfo);
+
+ // We should get back a non-null ScriptParseInfo
+ ScriptParseInfo parseInfo = service.GetScriptParseInfo(scriptFile.ClientFilePath);
+ Assert.NotNull(parseInfo);
+
+ // And we should get back a non-null SignatureHelp
+ SignatureHelp signatureHelp = service.GetSignatureHelp(textDocument, scriptFile);
+ Assert.NotNull(signatureHelp);
+ }
+ }
+}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs
new file mode 100644
index 00000000..79030d22
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/LanguageServer/PeekDefinitionTests.cs
@@ -0,0 +1,344 @@
+//
+// 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.IO;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+using Microsoft.SqlServer.Management.Common;
+using Microsoft.SqlServer.Management.SqlParser.Binder;
+using Microsoft.SqlServer.Management.SqlParser.Intellisense;
+using Microsoft.SqlServer.Management.SqlParser.MetadataProvider;
+using Microsoft.SqlServer.Management.SqlParser.Parser;
+using Microsoft.SqlTools.ServiceLayer.Connection;
+using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
+using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
+using Microsoft.SqlTools.ServiceLayer.LanguageServices;
+using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
+using Microsoft.SqlTools.ServiceLayer.SqlContext;
+using Microsoft.SqlTools.ServiceLayer.QueryExecution;
+using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
+using Microsoft.SqlTools.ServiceLayer.Workspace;
+using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
+using Microsoft.SqlTools.Test.Utility;
+using Moq;
+using Xunit;
+using Location = Microsoft.SqlTools.ServiceLayer.Workspace.Contracts.Location;
+
+namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageServices
+{
+ ///
+ /// Tests for the language service peek definition/ go to definition feature
+ ///
+ public class PeekDefinitionTests
+ {
+ private const int TaskTimeout = 30000;
+
+ private readonly string testScriptUri = TestObjects.ScriptUri;
+
+ private readonly string testConnectionKey = "testdbcontextkey";
+
+ private Mock bindingQueue;
+
+ private Mock> workspaceService;
+
+ private Mock> requestContext;
+
+ private Mock binder;
+
+ private TextDocumentPosition textDocument;
+
+ private const string OwnerUri = "testFile1";
+
+ ///
+ /// Test get definition for a table object with active connection
+ ///
+ [Fact]
+ public void GetValidTableDefinitionTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "spt_monitor";
+
+ string schemaName = null;
+ string objectType = "TABLE";
+
+ // Get locations for valid table object
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetTableScripts, objectName, schemaName, objectType);
+ Assert.NotNull(locations);
+ Cleanup(locations);
+ }
+
+ ///
+ /// Test get definition for a invalid table object with active connection
+ ///
+ [Fact]
+ public void GetTableDefinitionInvalidObjectTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "test_invalid";
+ string schemaName = null;
+ string objectType = "TABLE";
+
+ // Get locations for invalid table object
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetTableScripts, objectName, schemaName, objectType);
+ Assert.Null(locations);
+ }
+
+ ///
+ /// Test get definition for a valid table object with schema and active connection
+ ///
+ [Fact]
+ public void GetTableDefinitionWithSchemaTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "spt_monitor";
+
+ string schemaName = "dbo";
+ string objectType = "TABLE";
+
+ // Get locations for valid table object with schema name
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetTableScripts, objectName, schemaName, objectType);
+ Assert.NotNull(locations);
+ Cleanup(locations);
+ }
+
+ ///
+ /// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
+ ///
+ [Fact]
+ public void GetUnsupportedDefinitionErrorTest()
+ {
+ ScriptFile scriptFile;
+ TextDocumentPosition textDocument = new TextDocumentPosition
+ {
+ TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
+ Position = new Position
+ {
+ Line = 0,
+ // test for 'dbo'
+ Character = 16
+ }
+ };
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
+ scriptFile.Contents = "select * from dbo.func ()";
+ var languageService = new LanguageService();
+ ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
+ languageService.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
+
+ // When I call the language service
+ var result = languageService.GetDefinition(textDocument, scriptFile, connInfo);
+
+ // Then I expect null locations and an error to be reported
+ Assert.NotNull(result);
+ Assert.True(result.IsErrorResult);
+ }
+
+ ///
+ /// Get Definition for a object with no definition. Expect a error result
+ ///
+ [Fact]
+ public void GetDefinitionWithNoResultsFoundError()
+ {
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "from";
+
+ List declarations = new List();
+ DefinitionResult result = peekDefinition.GetScript(declarations, objectName, null);
+
+ Assert.NotNull(result);
+ Assert.True(result.IsErrorResult);
+ Assert.Equal(SR.PeekDefinitionNoResultsError, result.Message);
+ }
+
+ ///
+ /// Test GetDefinition with a forced timeout. Expect a error result.
+ ///
+ [Fact]
+ public void GetDefinitionTimeoutTest()
+ {
+ // Given a binding queue that will automatically time out
+ var languageService = new LanguageService();
+ Mock queueMock = new Mock();
+ languageService.BindingQueue = queueMock.Object;
+ ManualResetEvent mre = new ManualResetEvent(true); // Do not block
+ Mock itemMock = new Mock();
+ itemMock.Setup(i => i.ItemProcessed).Returns(mre);
+
+ DefinitionResult timeoutResult = null;
+
+ queueMock.Setup(q => q.QueueBindingOperation(
+ It.IsAny(),
+ It.IsAny>(),
+ It.IsAny>(),
+ It.IsAny(),
+ It.IsAny()))
+ .Callback, Func, int?, int?>(
+ (key, bindOperation, timeoutOperation, blah, blah2) =>
+ {
+ timeoutResult = (DefinitionResult) timeoutOperation((IBindingContext)null);
+ itemMock.Object.Result = timeoutResult;
+ })
+ .Returns(() => itemMock.Object);
+
+ ScriptFile scriptFile;
+ TextDocumentPosition textDocument = new TextDocumentPosition
+ {
+ TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
+ Position = new Position
+ {
+ Line = 0,
+ Character = 20
+ }
+ };
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
+ scriptFile.Contents = "select * from dbo.func ()";
+
+ ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
+ languageService.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
+
+ // When I call the language service
+ var result = languageService.GetDefinition(textDocument, scriptFile, connInfo);
+
+ // Then I expect null locations and an error to be reported
+ Assert.NotNull(result);
+ Assert.True(result.IsErrorResult);
+ // Check timeout message
+ Assert.Equal(SR.PeekDefinitionTimedoutError, result.Message);
+ }
+
+ ///
+ /// Test get definition for a view object with active connection
+ ///
+ [Fact]
+ public void GetValidViewDefinitionTest()
+ {
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "objects";
+ string schemaName = "sys";
+ string objectType = "VIEW";
+
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetViewScripts, objectName, schemaName, objectType);
+ Assert.NotNull(locations);
+ Cleanup(locations);
+ }
+
+ ///
+ /// Test get definition for an invalid view object with no schema name and with active connection
+ ///
+ [Fact]
+ public void GetViewDefinitionInvalidObjectTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "objects";
+ string schemaName = null;
+ string objectType = "VIEW";
+
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetViewScripts, objectName, schemaName, objectType);
+ Assert.Null(locations);
+ }
+
+ ///
+ /// Test get definition for a stored procedure object with active connection
+ ///
+ [Fact]
+ public void GetStoredProcedureDefinitionTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "sp_MSrepl_startup";
+
+ string schemaName = "dbo";
+ string objectType = "PROCEDURE";
+
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetStoredProcedureScripts, objectName, schemaName, objectType);
+ Assert.NotNull(locations);
+ Cleanup(locations);
+ }
+
+ ///
+ /// Test get definition for a stored procedure object that does not exist with active connection
+ ///
+ [Fact]
+ public void GetStoredProcedureDefinitionFailureTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "SP2";
+ string schemaName = "dbo";
+ string objectType = "PROCEDURE";
+
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetStoredProcedureScripts, objectName, schemaName, objectType);
+ Assert.Null(locations);
+ }
+
+ ///
+ /// Test get definition for a stored procedure object with active connection and no schema
+ ///
+ [Fact]
+ public void GetStoredProcedureDefinitionWithoutSchemaTest()
+ {
+ // Get live connectionInfo and serverConnection
+ ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
+ ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
+
+ PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
+ string objectName = "sp_MSrepl_startup";
+ string schemaName = null;
+ string objectType = "PROCEDURE";
+
+ Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetStoredProcedureScripts, objectName, schemaName, objectType);
+ Assert.NotNull(locations);
+ Cleanup(locations);
+ }
+
+ ///
+ /// Helper method to clean up script files
+ ///
+ private void Cleanup(Location[] locations)
+ {
+ Uri fileUri = new Uri(locations[0].Uri);
+ if (File.Exists(fileUri.LocalPath))
+ {
+ try
+ {
+ File.Delete(fileUri.LocalPath);
+ }
+ catch(Exception)
+ {
+
+ }
+ }
+ }
+ }
+}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.xproj b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.xproj
new file mode 100644
index 00000000..1713736a
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Microsoft.SqlTools.ServiceLayer.IntegrationTests.xproj
@@ -0,0 +1,22 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ 08af0209-d598-47bb-9dfd-fc9e74c0fe56
+ Microsoft.SqlTools.ServiceLayer.IntegrationTests
+ .\obj
+ .\bin\
+ v4.5.2
+
+
+ 2.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Properties/AssemblyInfo.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..a1587015
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,41 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("SqlToolsEditorServices.Test.Transport.Stdio")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SqlToolsEditorServices.Test.Transport.Stdio")]
+[assembly: AssemblyCopyright("Copyright � 2015")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("07137FCA-76D0-4CE7-9764-C21DB7A57093")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/DataStorage/StorageDataReaderTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs
similarity index 96%
rename from test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/DataStorage/StorageDataReaderTests.cs
rename to test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs
index 567e1a7a..b139e180 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/QueryExecution/DataStorage/StorageDataReaderTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/QueryExecution/DataStorage/StorageDataReaderTests.cs
@@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-#if LIVE_CONNECTION_TESTS
-
using System;
using System.Data.Common;
using Microsoft.SqlTools.ServiceLayer.Connection;
@@ -13,7 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Microsoft.SqlTools.Test.Utility;
using Xunit;
-namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
+namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataStorage
{
public class StorageDataReaderTests
{
@@ -105,6 +103,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
Assert.True(writer.ToString().Equals(output + '.'));
}
}
-}
-
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/packages.config b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/packages.config
new file mode 100644
index 00000000..d01e8969
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/packages.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/project.json b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/project.json
new file mode 100644
index 00000000..9644d367
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/project.json
@@ -0,0 +1,47 @@
+{
+ "name": "Microsoft.SqlTools.ServiceLayer.IntegrationTests",
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable"
+ },
+ "configurations": {
+ "Integration": {
+ "buildOptions": {
+ "define": [
+ "WINDOWS_ONLY_BUILD" ]
+ }
+ }
+ },
+ "dependencies": {
+ "Newtonsoft.Json": "9.0.1",
+ "System.Runtime.Serialization.Primitives": "4.1.1",
+ "System.Data.Common": "4.1.0",
+ "System.Data.SqlClient": "4.4.0-sqltools-24613-04",
+ "Microsoft.SqlServer.Smo": "140.1.12",
+ "System.Security.SecureString": "4.0.0",
+ "System.Collections.Specialized": "4.0.1",
+ "System.ComponentModel.TypeConverter": "4.1.0",
+ "xunit": "2.1.0",
+ "dotnet-test-xunit": "1.0.0-rc2-192208-24",
+ "Microsoft.SqlTools.ServiceLayer": {
+ "target": "project"
+ },
+ "Moq": "4.6.36-alpha",
+ "Microsoft.SqlTools.ServiceLayer.Test": "1.0.0-*"
+ },
+ "testRunner": "xunit",
+ "frameworks": {
+ "netcoreapp1.0": {
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.0.0"
+ }
+ },
+ "imports": [
+ "dotnet5.4",
+ "portable-net451+win8"
+ ]
+ }
+ }
+}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs
index adba7602..35f697d1 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs
@@ -18,9 +18,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
///
public class LanguageServiceTests
{
- #region "Diagnostics tests"
-
-
///
/// Verify that the latest SqlParser (2016 as of this writing) is used by default
///
@@ -197,134 +194,5 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
AutoCompleteHelper.GetDefaultCompletionItems(scriptDocumentInfo, false);
}
-
- #endregion
-
- #region "General Language Service tests"
-
-#if LIVE_CONNECTION_TESTS
-
- private static void GetLiveAutoCompleteTestObjects(
- out TextDocumentPosition textDocument,
- out ScriptFile scriptFile,
- out ConnectionInfo connInfo)
- {
- textDocument = new TextDocumentPosition
- {
- TextDocument = new TextDocumentIdentifier {Uri = TestObjects.ScriptUri},
- Position = new Position
- {
- Line = 0,
- Character = 0
- }
- };
-
- connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
- }
-
- ///
- /// Test the service initialization code path and verify nothing throws
- ///
- [Fact]
- public void ServiceInitialization()
- {
- try
- {
- TestObjects.InitializeTestServices();
- }
- catch (System.ArgumentException)
- {
-
- }
- Assert.True(LanguageService.Instance.Context != null);
- Assert.True(LanguageService.ConnectionServiceInstance != null);
- Assert.True(LanguageService.Instance.CurrentSettings != null);
- Assert.True(LanguageService.Instance.CurrentWorkspace != null);
- }
-
- ///
- /// Test the service initialization code path and verify nothing throws
- ///
- [Fact]
- public void PrepopulateCommonMetadata()
- {
- ScriptFile scriptFile;
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
-
- ScriptParseInfo scriptInfo = new ScriptParseInfo {IsConnected = true};
-
- AutoCompleteHelper.PrepopulateCommonMetadata(connInfo, scriptInfo, null);
- }
-
- // This test currently requires a live database connection to initialize
- // SMO connected metadata provider. Since we don't want a live DB dependency
- // in the CI unit tests this scenario is currently disabled.
- [Fact]
- public void AutoCompleteFindCompletions()
- {
- TextDocumentPosition textDocument;
- ConnectionInfo connInfo;
- ScriptFile scriptFile;
- GetLiveAutoCompleteTestObjects(out textDocument, out scriptFile, out connInfo);
-
- textDocument.Position.Character = 7;
- scriptFile.Contents = "select ";
-
- var autoCompleteService = LanguageService.Instance;
- var completions = autoCompleteService.GetCompletionItems(
- textDocument,
- scriptFile,
- connInfo);
-
- Assert.True(completions.Length > 0);
- }
-
- ///
- /// Verify that GetSignatureHelp returns not null when the provided TextDocumentPosition
- /// has an associated ScriptParseInfo and the provided query has a function that should
- /// provide signature help.
- ///
-
- // turn-off broken test until it can be fixed
- //[Fact]
- public async void GetSignatureHelpReturnsNotNullIfParseInfoInitialized()
- {
- // When we make a connection to a live database
- ScriptFile scriptFile;
- Hosting.ServiceHost.SendEventIgnoreExceptions = true;
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
-
- // And we place the cursor after a function that should prompt for signature help
- string queryWithFunction = "EXEC sys.fn_isrolemember ";
- scriptFile.Contents = queryWithFunction;
- TextDocumentPosition textDocument = new TextDocumentPosition
- {
- TextDocument = new TextDocumentIdentifier
- {
- Uri = scriptFile.ClientFilePath
- },
- Position = new Position
- {
- Line = 0,
- Character = queryWithFunction.Length
- }
- };
-
- // If the SQL has already been parsed
- var service = LanguageService.Instance;
- await service.UpdateLanguageServiceOnConnection(connInfo);
-
- // We should get back a non-null ScriptParseInfo
- ScriptParseInfo parseInfo = service.GetScriptParseInfo(scriptFile.ClientFilePath);
- Assert.NotNull(parseInfo);
-
- // And we should get back a non-null SignatureHelp
- SignatureHelp signatureHelp = service.GetSignatureHelp(textDocument, scriptFile);
- Assert.NotNull(signatureHelp);
- }
-
-#endif
-
- #endregion
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/PeekDefinitionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/PeekDefinitionTests.cs
index a4490505..99fd4a65 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/PeekDefinitionTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/PeekDefinitionTests.cs
@@ -221,295 +221,5 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
// Expected not to throw any exception
languageService.DeletePeekDefinitionScripts();
}
-
-#if LIVE_CONNECTION_TESTS
- ///
- /// Test get definition for a table object with active connection
- ///
- [Fact]
- public void GetValidTableDefinitionTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "spt_monitor";
-
- string schemaName = null;
- string objectType = "TABLE";
-
- // Get locations for valid table object
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetTableScripts, objectName, schemaName, objectType);
- Assert.NotNull(locations);
- Cleanup(locations);
- }
-
- ///
- /// Test get definition for a invalid table object with active connection
- ///
- [Fact]
- public void GetTableDefinitionInvalidObjectTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "test_invalid";
- string schemaName = null;
- string objectType = "TABLE";
-
- // Get locations for invalid table object
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetTableScripts, objectName, schemaName, objectType);
- Assert.Null(locations);
- }
-
- ///
- /// Test get definition for a valid table object with schema and active connection
- ///
- [Fact]
- public void GetTableDefinitionWithSchemaTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "spt_monitor";
-
- string schemaName = "dbo";
- string objectType = "TABLE";
-
- // Get locations for valid table object with schema name
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetTableScripts, objectName, schemaName, objectType);
- Assert.NotNull(locations);
- Cleanup(locations);
- }
-
- ///
- /// Test GetDefinition with an unsupported type(schema - dbo). Expect a error result.
- ///
- [Fact]
- public void GetUnsupportedDefinitionErrorTest()
- {
- ScriptFile scriptFile;
- TextDocumentPosition textDocument = new TextDocumentPosition
- {
- TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
- Position = new Position
- {
- Line = 0,
- // test for 'dbo'
- Character = 16
- }
- };
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
- scriptFile.Contents = "select * from dbo.func ()";
- var languageService = new LanguageService();
- ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
- languageService.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
-
- // When I call the language service
- var result = languageService.GetDefinition(textDocument, scriptFile, connInfo);
-
- // Then I expect null locations and an error to be reported
- Assert.NotNull(result);
- Assert.True(result.IsErrorResult);
- }
-
- ///
- /// Get Definition for a object with no definition. Expect a error result
- ///
- [Fact]
- public void GetDefinitionWithNoResultsFoundError()
- {
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "from";
-
- List declarations = new List();
- DefinitionResult result = peekDefinition.GetScript(declarations, objectName, null);
-
- Assert.NotNull(result);
- Assert.True(result.IsErrorResult);
- Assert.Equal(SR.PeekDefinitionNoResultsError, result.Message);
- }
-
- ///
- /// Test GetDefinition with a forced timeout. Expect a error result.
- ///
- [Fact]
- public void GetDefinitionTimeoutTest()
- {
- // Given a binding queue that will automatically time out
- var languageService = new LanguageService();
- Mock queueMock = new Mock();
- languageService.BindingQueue = queueMock.Object;
- ManualResetEvent mre = new ManualResetEvent(true); // Do not block
- Mock itemMock = new Mock();
- itemMock.Setup(i => i.ItemProcessed).Returns(mre);
-
- DefinitionResult timeoutResult = null;
-
- queueMock.Setup(q => q.QueueBindingOperation(
- It.IsAny(),
- It.IsAny>(),
- It.IsAny>(),
- It.IsAny(),
- It.IsAny()))
- .Callback, Func, int?, int?>(
- (key, bindOperation, timeoutOperation, blah, blah2) =>
- {
- timeoutResult = (DefinitionResult) timeoutOperation((IBindingContext)null);
- itemMock.Object.Result = timeoutResult;
- })
- .Returns(() => itemMock.Object);
-
- ScriptFile scriptFile;
- TextDocumentPosition textDocument = new TextDocumentPosition
- {
- TextDocument = new TextDocumentIdentifier { Uri = OwnerUri },
- Position = new Position
- {
- Line = 0,
- Character = 20
- }
- };
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile);
- scriptFile.Contents = "select * from dbo.func ()";
-
- ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
- languageService.ScriptParseInfoMap.Add(OwnerUri, scriptInfo);
-
- // When I call the language service
- var result = languageService.GetDefinition(textDocument, scriptFile, connInfo);
-
- // Then I expect null locations and an error to be reported
- Assert.NotNull(result);
- Assert.True(result.IsErrorResult);
- // Check timeout message
- Assert.Equal(SR.PeekDefinitionTimedoutError, result.Message);
- }
-
- ///
- /// Test get definition for a view object with active connection
- ///
- [Fact]
- public void GetValidViewDefinitionTest()
- {
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "objects";
- string schemaName = "sys";
- string objectType = "VIEW";
-
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetViewScripts, objectName, schemaName, objectType);
- Assert.NotNull(locations);
- Cleanup(locations);
- }
-
- ///
- /// Test get definition for an invalid view object with no schema name and with active connection
- ///
- [Fact]
- public void GetViewDefinitionInvalidObjectTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "objects";
- string schemaName = null;
- string objectType = "VIEW";
-
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetViewScripts, objectName, schemaName, objectType);
- Assert.Null(locations);
- }
-
- ///
- /// Test get definition for a stored procedure object with active connection
- ///
- [Fact]
- public void GetStoredProcedureDefinitionTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "sp_MSrepl_startup";
-
- string schemaName = "dbo";
- string objectType = "PROCEDURE";
-
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetStoredProcedureScripts, objectName, schemaName, objectType);
- Assert.NotNull(locations);
- Cleanup(locations);
- }
-
- ///
- /// Test get definition for a stored procedure object that does not exist with active connection
- ///
- [Fact]
- public void GetStoredProcedureDefinitionFailureTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "SP2";
- string schemaName = "dbo";
- string objectType = "PROCEDURE";
-
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetStoredProcedureScripts, objectName, schemaName, objectType);
- Assert.Null(locations);
- }
-
- ///
- /// Test get definition for a stored procedure object with active connection and no schema
- ///
- [Fact]
- public void GetStoredProcedureDefinitionWithoutSchemaTest()
- {
- // Get live connectionInfo and serverConnection
- ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfoForDefinition();
- ServerConnection serverConnection = TestObjects.InitLiveServerConnectionForDefinition(connInfo);
-
- PeekDefinition peekDefinition = new PeekDefinition(serverConnection, connInfo);
- string objectName = "sp_MSrepl_startup";
- string schemaName = null;
- string objectType = "PROCEDURE";
-
- Location[] locations = peekDefinition.GetSqlObjectDefinition(peekDefinition.GetStoredProcedureScripts, objectName, schemaName, objectType);
- Assert.NotNull(locations);
- Cleanup(locations);
- }
-
- ///
- /// Helper method to clean up script files
- ///
- private void Cleanup(Location[] locations)
- {
- Uri fileUri = new Uri(locations[0].Uri);
- if (File.Exists(fileUri.LocalPath))
- {
- try
- {
- File.Delete(fileUri.LocalPath);
- }
- catch(Exception)
- {
-
- }
- }
- }
-#endif
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/project.json b/test/Microsoft.SqlTools.ServiceLayer.Test/project.json
index d294d099..cf4d78a3 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/project.json
+++ b/test/Microsoft.SqlTools.ServiceLayer.Test/project.json
@@ -8,7 +8,6 @@
"Integration": {
"buildOptions": {
"define": [
- "LIVE_CONNECTION_TESTS",
"WINDOWS_ONLY_BUILD"
]
}