diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
index 577ec559..dec645d6 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs
@@ -5,9 +5,11 @@
using System;
using System.Collections.Generic;
+using System.Data.Common;
using System.Data.SqlClient;
using System.Threading.Tasks;
using Microsoft.SqlTools.EditorServices.Utility;
+using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
@@ -63,15 +65,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
///
/// Active connections lazy dictionary instance
///
- private Lazy> activeConnections
- = new Lazy>(()
- => new Dictionary());
+ private readonly Lazy> activeConnections
+ = new Lazy>(()
+ => new Dictionary());
///
/// Callback for onconnection handler
///
///
- public delegate Task OnConnectionHandler(ISqlConnection sqlConnection);
+ public delegate Task OnConnectionHandler(DbConnection sqlConnection);
///
/// List of onconnection handlers
@@ -81,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
///
/// Gets the active connection map
///
- public Dictionary ActiveConnections
+ public Dictionary ActiveConnections
{
get
{
@@ -127,10 +129,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
string connectionString = BuildConnectionString(connectionDetails);
// create a sql connection instance
- ISqlConnection connection = this.ConnectionFactory.CreateSqlConnection();
+ DbConnection connection = this.ConnectionFactory.CreateSqlConnection(connectionString);
// open the database
- connection.OpenDatabaseConnection(connectionString);
+ connection.Open();
// map the connection id to the connection object for future lookups
this.ActiveConnections.Add(++maxConnectionId, connection);
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionMessages.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionMessages.cs
similarity index 96%
rename from src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionMessages.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionMessages.cs
index a2b506aa..0ade2b39 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionMessages.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionMessages.cs
@@ -5,7 +5,7 @@
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
-namespace Microsoft.SqlTools.ServiceLayer.Connection
+namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
{
///
/// Message format for the initial connection request
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnection.cs
deleted file mode 100644
index 3e5fbdfe..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnection.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System.Collections.Generic;
-
-namespace Microsoft.SqlTools.ServiceLayer.Connection
-{
- ///
- /// Interface for the SQL Connection factory
- ///
- public interface ISqlConnectionFactory
- {
- ///
- /// Create a new SQL Connection object
- ///
- ISqlConnection CreateSqlConnection();
- }
-
- ///
- /// Interface for the SQL Connection wrapper
- ///
- public interface ISqlConnection
- {
- ///
- /// Open a connection to the provided connection string
- ///
- ///
- void OpenDatabaseConnection(string connectionString);
-
- IEnumerable GetServerObjects();
- }
-}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnectionFactory.cs
new file mode 100644
index 00000000..ed0cc01b
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnectionFactory.cs
@@ -0,0 +1,20 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System.Data.Common;
+
+namespace Microsoft.SqlTools.ServiceLayer.Connection
+{
+ ///
+ /// Interface for the SQL Connection factory
+ ///
+ public interface ISqlConnectionFactory
+ {
+ ///
+ /// Create a new SQL Connection object
+ ///
+ DbConnection CreateSqlConnection(string connectionString);
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnection.cs
deleted file mode 100644
index 6ad90b39..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnection.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System.Collections.Generic;
-using System.Data;
-using System.Data.SqlClient;
-
-namespace Microsoft.SqlTools.ServiceLayer.Connection
-{
- ///
- /// Factory class to create SqlClientConnections
- /// The purpose of the factory is to make it easier to mock out the database
- /// in 'offline' unit test scenarios.
- ///
- public class SqlConnectionFactory : ISqlConnectionFactory
- {
- ///
- /// Creates a new SqlClientConnection object
- ///
- public ISqlConnection CreateSqlConnection()
- {
- return new SqlClientConnection();
- }
- }
-
- ///
- /// Wrapper class that implements ISqlConnection and hosts a SqlConnection.
- /// This wrapper exists primarily for decoupling to support unit testing.
- ///
- public class SqlClientConnection : ISqlConnection
- {
- ///
- /// the underlying SQL connection
- ///
- private SqlConnection connection;
-
- ///
- /// Opens a SqlConnection using provided connection string
- ///
- ///
- public void OpenDatabaseConnection(string connectionString)
- {
- this.connection = new SqlConnection(connectionString);
- this.connection.Open();
- }
-
- ///
- /// Gets a list of database server schema objects
- ///
- ///
- public IEnumerable GetServerObjects()
- {
- // Select the values from sys.tables to give a super basic
- // autocomplete experience. This will be replaced by SMO.
- SqlCommand command = connection.CreateCommand();
- command.CommandText = "SELECT name FROM sys.tables";
- command.CommandTimeout = 15;
- command.CommandType = CommandType.Text;
- var reader = command.ExecuteReader();
-
- List results = new List();
- while (reader.Read())
- {
- results.Add(reader[0].ToString());
- }
-
- return results;
- }
- }
-}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnectionFactory.cs
new file mode 100644
index 00000000..cffb690d
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnectionFactory.cs
@@ -0,0 +1,26 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System.Data.Common;
+using System.Data.SqlClient;
+
+namespace Microsoft.SqlTools.ServiceLayer.Connection
+{
+ ///
+ /// Factory class to create SqlClientConnections
+ /// The purpose of the factory is to make it easier to mock out the database
+ /// in 'offline' unit test scenarios.
+ ///
+ public class SqlConnectionFactory : ISqlConnectionFactory
+ {
+ ///
+ /// Creates a new SqlConnection object
+ ///
+ public DbConnection CreateSqlConnection(string connectionString)
+ {
+ return new SqlConnection(connectionString);
+ }
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs
index 67981ae5..9af007a6 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs
@@ -5,8 +5,10 @@
using System;
using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
using System.Threading.Tasks;
-using Microsoft.SqlTools.ServiceLayer.Connection;
+using Microsoft.SqlTools.ServiceLayer.ConnectionServices;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
@@ -60,11 +62,24 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
///
/// Update the cached autocomplete candidate list when the user connects to a database
+ /// TODO: Update with refactoring/async
///
///
- public async Task UpdateAutoCompleteCache(ISqlConnection connection)
+ public async Task UpdateAutoCompleteCache(DbConnection connection)
{
- AutoCompleteList = connection.GetServerObjects();
+ DbCommand command = connection.CreateCommand();
+ command.CommandText = "SELECT name FROM sys.tables";
+ command.CommandTimeout = 15;
+ command.CommandType = CommandType.Text;
+ var reader = await command.ExecuteReaderAsync();
+
+ List results = new List();
+ while (await reader.ReadAsync())
+ {
+ results.Add(reader[0].ToString());
+ }
+
+ AutoCompleteList = results;
await Task.FromResult(0);
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs
index eb643c0c..77890bef 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
+using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SqlTools.EditorServices.Utility;
@@ -17,7 +18,8 @@ using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
using System.Linq;
using Microsoft.SqlServer.Management.SqlParser.Parser;
using Location = Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts.Location;
-using Microsoft.SqlTools.ServiceLayer.Connection;
+using Microsoft.SqlTools.ServiceLayer.ConnectionServices;
+using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{
@@ -308,7 +310,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// Callback for when a user connection is done processing
///
///
- public async Task OnConnection(ISqlConnection sqlConnection)
+ public async Task OnConnection(DbConnection sqlConnection)
{
await AutoCompleteService.Instance.UpdateAutoCompleteCache(sqlConnection);
await Task.FromResult(true);
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Program.cs b/src/Microsoft.SqlTools.ServiceLayer/Program.cs
index dc77f769..5711e8b3 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Program.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Program.cs
@@ -7,7 +7,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
-using Microsoft.SqlTools.ServiceLayer.Connection;
+using Microsoft.SqlTools.ServiceLayer.ConnectionServices;
namespace Microsoft.SqlTools.ServiceLayer
{
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferPosition.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferPosition.cs
index f74ade68..713736a7 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferPosition.cs
@@ -5,7 +5,7 @@
using System.Diagnostics;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Provides details about a position in a file buffer. All
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs
index 99316fe5..f8253d02 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs
@@ -6,7 +6,7 @@
using System;
using System.Diagnostics;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Provides details about a range between two positions in
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/Configuration.cs
similarity index 89%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/Configuration.cs
index ff1e5096..af50835f 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/Configuration.cs
@@ -5,7 +5,7 @@
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
public class DidChangeConfigurationNotification
{
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FileChange.cs
similarity index 93%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FileChange.cs
index 7e1af148..e3d49471 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FileChange.cs
@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Contains details relating to a content change in an open file.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FilePosition.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FilePosition.cs
index 01ed012d..65fe268a 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FilePosition.cs
@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Provides details and operations for a buffer position in a
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFile.cs
similarity index 99%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFile.cs
index 708bae70..8db022cc 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFile.cs
@@ -9,7 +9,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Contains the details and contents of an open script file.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFileMarker.cs
similarity index 95%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFileMarker.cs
index 35ba21fa..743ef3d6 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFileMarker.cs
@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Defines the message level of a script file marker.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptRegion.cs
similarity index 97%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptRegion.cs
index 1ac56d01..e68400e9 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptRegion.cs
@@ -5,7 +5,7 @@
//using System.Management.Automation.Language;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Contains details about a specific region of text in script file.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs
index 0708316d..75b542cd 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs
@@ -6,7 +6,7 @@
using System.Diagnostics;
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
///
/// Defines a base parameter class for identifying a text document.
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs
similarity index 95%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs
index 1b7731eb..22445c03 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs
@@ -5,7 +5,7 @@
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts
+namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
{
public enum SymbolKind
{
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs
index 921ecc7c..560805d7 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs
@@ -10,9 +10,9 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using Microsoft.SqlTools.EditorServices.Utility;
-using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
+using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
+namespace Microsoft.SqlTools.ServiceLayer.Workspace
{
///
/// Manages a "workspace" of script files that are open for a particular
diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs
rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs
index 96878f45..701fa6f5 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs
@@ -11,9 +11,9 @@ using System.Threading.Tasks;
using Microsoft.SqlTools.EditorServices.Utility;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
-using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
+using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
-namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices
+namespace Microsoft.SqlTools.ServiceLayer.Workspace
{
///
/// Class for handling requests/events that deal with the state of the workspace, including the
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs
index bab3fa6e..ad560d4d 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs
@@ -115,7 +115,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
var connectionService = TestObjects.GetTestConnectionService();
var connectionResult = connectionService.Connect(TestObjects.GetTestConnectionDetails());
var sqlConnection = connectionService.ActiveConnections[connectionResult.ConnectionId];
- autocompleteService.UpdateAutoCompleteCache(sqlConnection);
+ autocompleteService.UpdateAutoCompleteCache(sqlConnection).Wait();
}
#endregion
diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs
index c506d600..6bf4d738 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs
@@ -5,9 +5,17 @@
//#define USE_LIVE_CONNECTION
+using System;
+using System.Collections;
using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Threading;
using System.Threading.Tasks;
-using Microsoft.SqlTools.ServiceLayer.Connection;
+using Microsoft.SqlTools.ServiceLayer.ConnectionServices;
+using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Xunit;
@@ -80,18 +88,253 @@ namespace Microsoft.SqlTools.Test.Utility
}
}
+ public class TestDataReader : DbDataReader
+ {
+
+ #region Test Specific Implementations
+
+ internal string SqlCommandText { get; set; }
+
+ private const string tableNameTestCommand = "SELECT name FROM sys.tables";
+
+ private List> tableNamesTest = new List>
+ {
+ new Dictionary { {"name", "table1"} },
+ new Dictionary { {"name", "table2"} }
+ };
+
+ private IEnumerator> tableEnumerator;
+
+ #endregion
+
+ public override bool GetBoolean(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override byte GetByte(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override char GetChar(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override string GetDataTypeName(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override DateTime GetDateTime(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override decimal GetDecimal(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override double GetDouble(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override IEnumerator GetEnumerator()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int GetOrdinal(string name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override string GetName(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override long GetInt64(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int GetInt32(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override short GetInt16(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override Guid GetGuid(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override float GetFloat(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override Type GetFieldType(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override string GetString(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override object GetValue(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int GetValues(object[] values)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool IsDBNull(int ordinal)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool NextResult()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool Read()
+ {
+ if (tableEnumerator == null)
+ {
+ switch (SqlCommandText)
+ {
+ case tableNameTestCommand:
+ tableEnumerator = ((IEnumerable>)tableNamesTest).GetEnumerator();
+ break;
+ default:
+ throw new NotImplementedException();
+ }
+ }
+ return tableEnumerator.MoveNext();
+ }
+
+ public override int Depth { get; }
+ public override bool IsClosed { get; }
+ public override int RecordsAffected { get; }
+
+ public override object this[string name]
+ {
+ get { return tableEnumerator.Current[name]; }
+ }
+
+ public override object this[int ordinal]
+ {
+ get { return tableEnumerator.Current[tableEnumerator.Current.Keys.ToArray()[ordinal]]; }
+ }
+
+ public override int FieldCount { get; }
+ public override bool HasRows { get; }
+ }
+
+ ///
+ /// Test mock class for IDbCommand
+ ///
+ public class TestSqlCommand : DbCommand
+ {
+ public override void Cancel()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int ExecuteNonQuery()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override object ExecuteScalar()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Prepare()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override string CommandText { get; set; }
+ public override int CommandTimeout { get; set; }
+ public override CommandType CommandType { get; set; }
+ public override UpdateRowSource UpdatedRowSource { get; set; }
+ protected override DbConnection DbConnection { get; set; }
+ protected override DbParameterCollection DbParameterCollection { get; }
+ protected override DbTransaction DbTransaction { get; set; }
+ public override bool DesignTimeVisible { get; set; }
+
+ protected override DbParameter CreateDbParameter()
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
+ {
+ return new TestDataReader {SqlCommandText = CommandText};
+ }
+ }
+
///
/// Test mock class for SqlConnection wrapper
///
- public class TestSqlConnection : ISqlConnection
+ public class TestSqlConnection : DbConnection
{
- public void OpenDatabaseConnection(string connectionString)
+ protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
{
+ throw new NotImplementedException();
}
- public IEnumerable GetServerObjects()
+ public override void Close()
{
- return null;
+ throw new NotImplementedException();
+ }
+
+ public override void Open()
+ {
+ // No Op
+ }
+
+ public override string ConnectionString { get; set; }
+ public override string Database { get; }
+ public override ConnectionState State { get; }
+ public override string DataSource { get; }
+ public override string ServerVersion { get; }
+
+ protected override DbCommand CreateDbCommand()
+ {
+ return new TestSqlCommand();
+ }
+
+ public override void ChangeDatabase(string databaseName)
+ {
+ throw new NotImplementedException();
}
}
@@ -100,9 +343,12 @@ namespace Microsoft.SqlTools.Test.Utility
///
public class TestSqlConnectionFactory : ISqlConnectionFactory
{
- public ISqlConnection CreateSqlConnection()
+ public DbConnection CreateSqlConnection(string connectionString)
{
- return new TestSqlConnection();
+ return new TestSqlConnection()
+ {
+ ConnectionString = connectionString
+ };
}
}
}