diff --git a/sqltoolsservice.sln b/sqltoolsservice.sln index b993537f..828baca9 100644 --- a/sqltoolsservice.sln +++ b/sqltoolsservice.sln @@ -11,9 +11,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ServiceHost", "src\ServiceHost\ServiceHost.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 -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ServiceHost.Test", "test\ServiceHost.Test\ServiceHost.Test.xproj", "{2D771D16-9D85-4053-9F79-E2034737DEEF}" +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}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/ServiceHost/ConnectionServices/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs similarity index 68% rename from src/ServiceHost/ConnectionServices/ConnectionService.cs rename to src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs index d7f11fe1..90b7c61f 100644 --- a/src/ServiceHost/ConnectionServices/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs @@ -5,14 +5,14 @@ using System; using System.Collections.Generic; -using System.Data; using System.Data.SqlClient; -using System.Linq; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; -using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; +using Microsoft.SqlTools.ServiceLayer.SqlContext; +using Microsoft.SqlTools.ServiceLayer.WorkspaceServices; namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices { @@ -56,12 +56,17 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// private ISqlConnectionFactory connectionFactory; + /// + /// The current connection id that was previously used + /// + private int maxConnectionId = 0; + /// /// Active connections lazy dictionary instance /// - private Lazy> activeConnections - = new Lazy>(() - => new Dictionary()); + private Lazy> activeConnections + = new Lazy>(() + => new Dictionary()); /// /// Callback for onconnection handler @@ -77,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// /// Gets the active connection map /// - public Dictionary ActiveConnections + public Dictionary ActiveConnections { get { @@ -117,56 +122,40 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// Open a connection with the specified connection details /// /// - public async Task Connect(ConnectionDetails connectionDetails) + public ConnectionResult Connect(ConnectionDetails connectionDetails) { // build the connection string from the input parameters string connectionString = BuildConnectionString(connectionDetails); // create a sql connection instance - ISqlConnection connection = ConnectionFactory.CreateSqlConnection(connectionString); + ISqlConnection connection = this.ConnectionFactory.CreateSqlConnection(connectionString); // open the database - await connection.OpenAsync(); + connection.Open(); // map the connection id to the connection object for future lookups - Guid connectionId = Guid.NewGuid(); - ActiveConnections.Add(connectionId, connection); + this.ActiveConnections.Add(++maxConnectionId, connection); // invoke callback notifications - var onConnectionCallbackTasks = onConnectionActivities.Select(t => t(connection)); - await Task.WhenAll(onConnectionCallbackTasks); - // TODO: Evaulate if we want to avoid waiting here. We'll need error handling on the other side if we don't wait + foreach (var activity in this.onConnectionActivities) + { + activity(connection); + } // return the connection result - return new ConnectionResult + return new ConnectionResult() { - ConnectionId = connectionId + ConnectionId = maxConnectionId }; } - /// - /// Closes an active connection and removes it from the active connections list - /// - /// ID of the connection to close - public void Disconnect(Guid connectionId) - { - if (!ActiveConnections.ContainsKey(connectionId)) - { - // TODO: Should this possibly be a throw condition? - return; - } - - ActiveConnections[connectionId].Close(); - ActiveConnections.Remove(connectionId); - } - - public void Initialize(ServiceHost serviceHost) + public void InitializeService(ServiceHost serviceHost) { // Register request and event handlers with the Service Host serviceHost.SetRequestHandler(ConnectionRequest.Type, HandleConnectRequest); - - // Register the shutdown handler - serviceHost.RegisterShutdownTask(HandleShutdownRequest); + + // Register the configuration update handler + WorkspaceService.Instance.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification); } /// @@ -178,15 +167,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices onConnectionActivities.Add(activity); } - public ISqlConnection GetConnection(Guid connectionId) - { - if (!ActiveConnections.ContainsKey(connectionId)) - { - throw new ArgumentException("Connection with provided ID could not be found"); - } - return ActiveConnections[connectionId]; - } - #endregion #region Request Handlers @@ -203,24 +183,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices { Logger.Write(LogLevel.Verbose, "HandleConnectRequest"); - // open connection base on request details - ConnectionResult result = await Connect(connectionDetails); - - await requestContext.SendResult(result); + try + { + // open connection base on request details + ConnectionResult result = ConnectionService.Instance.Connect(connectionDetails); + await requestContext.SendResult(result); + } + catch(Exception ex) + { + await requestContext.SendError(ex.Message); + } } - /// - /// Handles shutdown event by closing out any active connections - /// - protected async Task HandleShutdownRequest(object shutdownObj, RequestContext shutdownContext) - { - // Go through all the existing connections and close them out - foreach (ISqlConnection conn in ActiveConnections.Values) - { - conn.Close(); - } + #endregion - await Task.FromResult(0); + #region Handlers for Events from Other Services + + public Task HandleDidChangeConfigurationNotification( + SqlToolsSettings newSettings, + SqlToolsSettings oldSettings, + EventContext eventContext) + { + return Task.FromResult(true); } #endregion diff --git a/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ConnectionMessages.cs similarity index 92% rename from src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs rename to src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ConnectionMessages.cs index 20463704..7f5c6492 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ConnectionMessages.cs @@ -3,10 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using System; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices { /// /// Message format for the initial connection request @@ -43,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// /// Gets or sets the connection id /// - public Guid ConnectionId { get; set; } + public int ConnectionId { get; set; } /// /// Gets or sets any connection error messages diff --git a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnection.cs similarity index 100% rename from src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs rename to src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnection.cs diff --git a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs similarity index 100% rename from src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs rename to src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs diff --git a/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnection.cs similarity index 100% rename from src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs rename to src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnection.cs diff --git a/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs similarity index 100% rename from src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs rename to src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs diff --git a/src/ServiceHost/Hosting/Contracts/ClientCapabilities.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/ClientCapabilities.cs similarity index 100% rename from src/ServiceHost/Hosting/Contracts/ClientCapabilities.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/ClientCapabilities.cs diff --git a/src/ServiceHost/Hosting/Contracts/Initialize.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/Initialize.cs similarity index 100% rename from src/ServiceHost/Hosting/Contracts/Initialize.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/Initialize.cs diff --git a/src/ServiceHost/Hosting/Contracts/ServerCapabilities.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/ServerCapabilities.cs similarity index 100% rename from src/ServiceHost/Hosting/Contracts/ServerCapabilities.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/ServerCapabilities.cs diff --git a/src/ServiceHost/Hosting/Contracts/Shutdown.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/Shutdown.cs similarity index 100% rename from src/ServiceHost/Hosting/Contracts/Shutdown.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Contracts/Shutdown.cs diff --git a/src/ServiceHost/Hosting/Protocol/Channel/ChannelBase.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Channel/ChannelBase.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Channel/ChannelBase.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Channel/ChannelBase.cs diff --git a/src/ServiceHost/Hosting/Protocol/Channel/StdioClientChannel.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Channel/StdioClientChannel.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Channel/StdioClientChannel.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Channel/StdioClientChannel.cs diff --git a/src/ServiceHost/Hosting/Protocol/Channel/StdioServerChannel.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Channel/StdioServerChannel.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Channel/StdioServerChannel.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Channel/StdioServerChannel.cs diff --git a/src/ServiceHost/Hosting/Protocol/Constants.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Constants.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Constants.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Constants.cs diff --git a/src/ServiceHost/Hosting/Protocol/Contracts/EventType.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Contracts/EventType.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Contracts/EventType.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Contracts/EventType.cs diff --git a/src/ServiceHost/Hosting/Protocol/Contracts/Message.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Contracts/Message.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Contracts/Message.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Contracts/Message.cs diff --git a/src/ServiceHost/Hosting/Protocol/Contracts/RequestType.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Contracts/RequestType.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Contracts/RequestType.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Contracts/RequestType.cs diff --git a/src/ServiceHost/Hosting/Protocol/EventContext.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/EventContext.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/EventContext.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/EventContext.cs diff --git a/src/ServiceHost/Hosting/Protocol/IMessageSender.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/IMessageSender.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/IMessageSender.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/IMessageSender.cs diff --git a/src/ServiceHost/Hosting/Protocol/MessageDispatcher.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageDispatcher.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/MessageDispatcher.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageDispatcher.cs diff --git a/src/ServiceHost/Hosting/Protocol/MessageParseException.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageParseException.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/MessageParseException.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageParseException.cs diff --git a/src/ServiceHost/Hosting/Protocol/MessageProtocolType.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageProtocolType.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/MessageProtocolType.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageProtocolType.cs diff --git a/src/ServiceHost/Hosting/Protocol/MessageReader.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageReader.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/MessageReader.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageReader.cs diff --git a/src/ServiceHost/Hosting/Protocol/MessageWriter.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageWriter.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/MessageWriter.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/MessageWriter.cs diff --git a/src/ServiceHost/Hosting/Protocol/ProtocolEndpoint.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/ProtocolEndpoint.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/ProtocolEndpoint.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/ProtocolEndpoint.cs diff --git a/src/ServiceHost/Hosting/Protocol/RequestContext.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/RequestContext.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/RequestContext.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/RequestContext.cs diff --git a/src/ServiceHost/Hosting/Protocol/Serializers/IMessageSerializer.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Serializers/IMessageSerializer.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Serializers/IMessageSerializer.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Serializers/IMessageSerializer.cs diff --git a/src/ServiceHost/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Serializers/JsonRpcMessageSerializer.cs diff --git a/src/ServiceHost/Hosting/Protocol/Serializers/V8MessageSerializer.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Serializers/V8MessageSerializer.cs similarity index 100% rename from src/ServiceHost/Hosting/Protocol/Serializers/V8MessageSerializer.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/Protocol/Serializers/V8MessageSerializer.cs diff --git a/src/ServiceHost/Hosting/ServiceHost.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHost.cs similarity index 100% rename from src/ServiceHost/Hosting/ServiceHost.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHost.cs diff --git a/src/ServiceHost/Hosting/ServiceHostBase.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHostBase.cs similarity index 100% rename from src/ServiceHost/Hosting/ServiceHostBase.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHostBase.cs diff --git a/src/ServiceHost/Hosting/ServiceHostEditorOperations.cs b/src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHostEditorOperations.cs similarity index 100% rename from src/ServiceHost/Hosting/ServiceHostEditorOperations.cs rename to src/Microsoft.SqlTools.ServiceLayer/Hosting/ServiceHostEditorOperations.cs diff --git a/src/ServiceHost/LanguageServices/AutoCompleteService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs similarity index 100% rename from src/ServiceHost/LanguageServices/AutoCompleteService.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/Completion.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Completion.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/Completion.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Completion.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/Definition.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Definition.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/Definition.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Definition.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/Diagnostics.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Diagnostics.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/Diagnostics.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Diagnostics.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/DocumentHighlight.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/DocumentHighlight.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/DocumentHighlight.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/DocumentHighlight.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/ExpandAliasRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/ExpandAliasRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/ExpandAliasRequest.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/ExpandAliasRequest.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/FindModuleRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/FindModuleRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/FindModuleRequest.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/FindModuleRequest.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/Hover.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Hover.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/Hover.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/Hover.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/InstallModuleRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/InstallModuleRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/InstallModuleRequest.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/InstallModuleRequest.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/References.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/References.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/References.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/References.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/ShowOnlineHelpRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/ShowOnlineHelpRequest.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/ShowOnlineHelpRequest.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/ShowOnlineHelpRequest.cs diff --git a/src/ServiceHost/LanguageServices/Contracts/SignatureHelp.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/SignatureHelp.cs similarity index 100% rename from src/ServiceHost/LanguageServices/Contracts/SignatureHelp.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/Contracts/SignatureHelp.cs diff --git a/src/ServiceHost/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs similarity index 100% rename from src/ServiceHost/LanguageServices/LanguageService.cs rename to src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs diff --git a/src/ServiceHost/ServiceHost.xproj b/src/Microsoft.SqlTools.ServiceLayer/Microsoft.SqlTools.ServiceLayer.xproj similarity index 100% rename from src/ServiceHost/ServiceHost.xproj rename to src/Microsoft.SqlTools.ServiceLayer/Microsoft.SqlTools.ServiceLayer.xproj diff --git a/src/ServiceHost/Program.cs b/src/Microsoft.SqlTools.ServiceLayer/Program.cs similarity index 96% rename from src/ServiceHost/Program.cs rename to src/Microsoft.SqlTools.ServiceLayer/Program.cs index aa040bad..5711e8b3 100644 --- a/src/ServiceHost/Program.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Program.cs @@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer WorkspaceService.Instance.InitializeService(serviceHost); AutoCompleteService.Instance.InitializeService(serviceHost); LanguageService.Instance.InitializeService(serviceHost, sqlToolsContext); - ConnectionService.Instance.Initialize(serviceHost); + ConnectionService.Instance.InitializeService(serviceHost); serviceHost.Initialize(); serviceHost.WaitForExit(); diff --git a/src/ServiceHost/Properties/AssemblyInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs similarity index 96% rename from src/ServiceHost/Properties/AssemblyInfo.cs rename to src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs index ee34cfc1..33b9e4a8 100644 --- a/src/ServiceHost/Properties/AssemblyInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Properties/AssemblyInfo.cs @@ -41,4 +41,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0.0")] -[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceHost.Test")] +[assembly: InternalsVisibleTo("Microsoft.SqlTools.ServiceLayer.Test")] diff --git a/src/ServiceHost/SqlContext/HostDetails.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/HostDetails.cs similarity index 100% rename from src/ServiceHost/SqlContext/HostDetails.cs rename to src/Microsoft.SqlTools.ServiceLayer/SqlContext/HostDetails.cs diff --git a/src/ServiceHost/SqlContext/ProfilePaths.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/ProfilePaths.cs similarity index 100% rename from src/ServiceHost/SqlContext/ProfilePaths.cs rename to src/Microsoft.SqlTools.ServiceLayer/SqlContext/ProfilePaths.cs diff --git a/src/ServiceHost/SqlContext/SqlToolsContext.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsContext.cs similarity index 100% rename from src/ServiceHost/SqlContext/SqlToolsContext.cs rename to src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsContext.cs diff --git a/src/ServiceHost/SqlContext/SqlToolsSettings.cs b/src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs similarity index 100% rename from src/ServiceHost/SqlContext/SqlToolsSettings.cs rename to src/Microsoft.SqlTools.ServiceLayer/SqlContext/SqlToolsSettings.cs diff --git a/src/ServiceHost/Utility/AsyncContext.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncContext.cs similarity index 100% rename from src/ServiceHost/Utility/AsyncContext.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncContext.cs diff --git a/src/ServiceHost/Utility/AsyncContextThread.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncContextThread.cs similarity index 100% rename from src/ServiceHost/Utility/AsyncContextThread.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncContextThread.cs diff --git a/src/ServiceHost/Utility/AsyncLock.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncLock.cs similarity index 100% rename from src/ServiceHost/Utility/AsyncLock.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncLock.cs diff --git a/src/ServiceHost/Utility/AsyncQueue.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncQueue.cs similarity index 100% rename from src/ServiceHost/Utility/AsyncQueue.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/AsyncQueue.cs diff --git a/src/ServiceHost/Utility/Extensions.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/Extensions.cs similarity index 100% rename from src/ServiceHost/Utility/Extensions.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/Extensions.cs diff --git a/src/ServiceHost/Utility/Logger.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/Logger.cs similarity index 100% rename from src/ServiceHost/Utility/Logger.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/Logger.cs diff --git a/src/ServiceHost/Utility/ThreadSynchronizationContext.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/ThreadSynchronizationContext.cs similarity index 100% rename from src/ServiceHost/Utility/ThreadSynchronizationContext.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/ThreadSynchronizationContext.cs diff --git a/src/ServiceHost/Utility/Validate.cs b/src/Microsoft.SqlTools.ServiceLayer/Utility/Validate.cs similarity index 100% rename from src/ServiceHost/Utility/Validate.cs rename to src/Microsoft.SqlTools.ServiceLayer/Utility/Validate.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/BufferPosition.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/BufferPosition.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/BufferRange.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/BufferRange.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/Configuration.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/Configuration.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/FileChange.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/FileChange.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/FilePosition.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/FilePosition.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/ScriptFile.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/ScriptFile.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/ScriptFileMarker.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/ScriptFileMarker.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/ScriptRegion.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/ScriptRegion.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/TextDocument.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/TextDocument.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs diff --git a/src/ServiceHost/WorkspaceServices/Contracts/WorkspaceSymbols.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Contracts/WorkspaceSymbols.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs diff --git a/src/ServiceHost/WorkspaceServices/Workspace.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/Workspace.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs diff --git a/src/ServiceHost/WorkspaceServices/WorkspaceService.cs b/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs similarity index 100% rename from src/ServiceHost/WorkspaceServices/WorkspaceService.cs rename to src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs diff --git a/src/ServiceHost/project.json b/src/Microsoft.SqlTools.ServiceLayer/project.json similarity index 91% rename from src/ServiceHost/project.json rename to src/Microsoft.SqlTools.ServiceLayer/project.json index bd889b55..b690fd26 100644 --- a/src/ServiceHost/project.json +++ b/src/Microsoft.SqlTools.ServiceLayer/project.json @@ -1,5 +1,5 @@ { - "name": "Microsoft.SqlTools.ServiceHost", + "name": "Microsoft.SqlTools.ServiceLayer", "version": "1.0.0-*", "buildOptions": { "debugType": "portable", diff --git a/test/ServiceHost.Test/App.config b/test/Microsoft.SqlTools.ServiceLayer.Test/App.config similarity index 100% rename from test/ServiceHost.Test/App.config rename to test/Microsoft.SqlTools.ServiceLayer.Test/App.config diff --git a/test/ServiceHost.Test/Connection/ConnectionServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ConnectionServiceTests.cs similarity index 100% rename from test/ServiceHost.Test/Connection/ConnectionServiceTests.cs rename to test/Microsoft.SqlTools.ServiceLayer.Test/Connection/ConnectionServiceTests.cs diff --git a/test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs similarity index 98% rename from test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs rename to test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs index 8f85869d..ad560d4d 100644 --- a/test/ServiceHost.Test/LanguageServer/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs @@ -8,7 +8,7 @@ using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; using Microsoft.SqlTools.Test.Utility; using Xunit; -namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer +namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices { /// /// Tests for the ServiceHost Language Service tests @@ -115,7 +115,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer 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/ServiceHost.Test/Message/MessageReaderWriterTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Message/MessageReaderWriterTests.cs similarity index 100% rename from test/ServiceHost.Test/Message/MessageReaderWriterTests.cs rename to test/Microsoft.SqlTools.ServiceLayer.Test/Message/MessageReaderWriterTests.cs diff --git a/test/ServiceHost.Test/Message/TestMessageTypes.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Message/TestMessageTypes.cs similarity index 100% rename from test/ServiceHost.Test/Message/TestMessageTypes.cs rename to test/Microsoft.SqlTools.ServiceLayer.Test/Message/TestMessageTypes.cs diff --git a/test/ServiceHost.Test/ServiceHost.Test.xproj b/test/Microsoft.SqlTools.ServiceLayer.Test/Microsoft.SqlTools.ServiceLayer.Test.xproj similarity index 100% rename from test/ServiceHost.Test/ServiceHost.Test.xproj rename to test/Microsoft.SqlTools.ServiceLayer.Test/Microsoft.SqlTools.ServiceLayer.Test.xproj diff --git a/test/ServiceHost.Test/Properties/AssemblyInfo.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Properties/AssemblyInfo.cs similarity index 100% rename from test/ServiceHost.Test/Properties/AssemblyInfo.cs rename to test/Microsoft.SqlTools.ServiceLayer.Test/Properties/AssemblyInfo.cs diff --git a/test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/ServiceHost/JsonRpcMessageSerializerTests.cs similarity index 100% rename from test/ServiceHost.Test/ServiceHost/JsonRpcMessageSerializerTests.cs rename to test/Microsoft.SqlTools.ServiceLayer.Test/ServiceHost/JsonRpcMessageSerializerTests.cs diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs new file mode 100644 index 00000000..02f69532 --- /dev/null +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs @@ -0,0 +1,419 @@ +// +// 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; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; +using Microsoft.SqlTools.ServiceLayer.LanguageServices; +using Microsoft.SqlTools.ServiceLayer.SqlContext; +using Xunit; + +namespace Microsoft.SqlTools.Test.Utility +{ + /// + /// Tests for the ServiceHost Connection Service tests + /// + public class TestObjects + { + /// + /// Creates a test connection service + /// + public static ConnectionService GetTestConnectionService() + { +#if !USE_LIVE_CONNECTION + // use mock database connection + return new ConnectionService(new TestSqlConnectionFactory()); +#else + // connect to a real server instance + return ConnectionService.Instance; +#endif + } + + /// + /// Creates a test connection details object + /// + public static ConnectionDetails GetTestConnectionDetails() + { + return new ConnectionDetails() + { + UserName = "sa", + Password = "Yukon900", + DatabaseName = "AdventureWorks2016CTP3_2", + ServerName = "sqltools11" + }; + } + + /// + /// Create a test language service instance + /// + /// + public static LanguageService GetTestLanguageService() + { + return new LanguageService(); + } + + /// + /// Creates a test autocomplete service instance + /// + public static AutoCompleteService GetAutoCompleteService() + { + return AutoCompleteService.Instance; + } + + /// + /// Creates a test sql connection factory instance + /// + public static ISqlConnectionFactory GetTestSqlConnectionFactory() + { +#if !USE_LIVE_CONNECTION + // use mock database connection + return new TestSqlConnectionFactory(); +#else + // connect to a real server instance + return ConnectionService.Instance.ConnectionFactory; +#endif + + } + } + + public class TestSqlReader : IDataReader + { + + #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 bool GetBoolean(int i) + { + throw new NotImplementedException(); + } + + public byte GetByte(int i) + { + throw new NotImplementedException(); + } + + public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) + { + throw new NotImplementedException(); + } + + public char GetChar(int i) + { + throw new NotImplementedException(); + } + + public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) + { + throw new NotImplementedException(); + } + + public IDataReader GetData(int i) + { + throw new NotImplementedException(); + } + + public string GetDataTypeName(int i) + { + throw new NotImplementedException(); + } + + public DateTime GetDateTime(int i) + { + throw new NotImplementedException(); + } + + public decimal GetDecimal(int i) + { + throw new NotImplementedException(); + } + + public double GetDouble(int i) + { + throw new NotImplementedException(); + } + + public Type GetFieldType(int i) + { + throw new NotImplementedException(); + } + + public float GetFloat(int i) + { + throw new NotImplementedException(); + } + + public Guid GetGuid(int i) + { + throw new NotImplementedException(); + } + + public short GetInt16(int i) + { + throw new NotImplementedException(); + } + + public int GetInt32(int i) + { + throw new NotImplementedException(); + } + + public long GetInt64(int i) + { + throw new NotImplementedException(); + } + + public string GetName(int i) + { + throw new NotImplementedException(); + } + + public int GetOrdinal(string name) + { + throw new NotImplementedException(); + } + + public string GetString(int i) + { + throw new NotImplementedException(); + } + + public object GetValue(int i) + { + throw new NotImplementedException(); + } + + public int GetValues(object[] values) + { + throw new NotImplementedException(); + } + + public bool IsDBNull(int i) + { + throw new NotImplementedException(); + } + + public int FieldCount { get; } + + object IDataRecord.this[string name] + { + get { return tableEnumerator.Current[name]; } + } + + object IDataRecord.this[int i] + { + get { return tableEnumerator.Current[tableEnumerator.Current.Keys.ToArray()[i]]; } + } + + public void Dispose() + { + throw new NotImplementedException(); + } + + public void Close() + { + throw new NotImplementedException(); + } + + public DataTable GetSchemaTable() + { + throw new NotImplementedException(); + } + + public bool NextResult() + { + throw new NotImplementedException(); + } + + public bool Read() + { + if (tableEnumerator == null) + { + switch (SqlCommandText) + { + case tableNameTestCommand: + tableEnumerator = ((IEnumerable>)tableNamesTest).GetEnumerator(); + break; + default: + throw new NotImplementedException(); + } + } + return tableEnumerator.MoveNext(); + } + + public int Depth { get; } + public bool IsClosed { get; } + public int RecordsAffected { get; } + } + + /// + /// Test mock class for IDbCommand + /// + public class TestSqlCommand : IDbCommand + { + + public string CommandText { get; set; } + + public int CommandTimeout { get; set; } + + public CommandType CommandType { get; set; } + + public IDbConnection Connection { get; set; } + + public IDataParameterCollection Parameters + { + get + { + throw new NotImplementedException(); + } + } + + public IDbTransaction Transaction { get; set; } + + public UpdateRowSource UpdatedRowSource { get; set; } + + public void Cancel() + { + throw new NotImplementedException(); + } + + public IDbDataParameter CreateParameter() + { + throw new NotImplementedException(); + } + + public void Dispose() + { + } + + public int ExecuteNonQuery() + { + throw new NotImplementedException(); + } + + public IDataReader ExecuteReader() + { + return new TestSqlReader + { + SqlCommandText = CommandText + }; + } + + public IDataReader ExecuteReader(CommandBehavior behavior) + { + throw new NotImplementedException(); + } + + public object ExecuteScalar() + { + throw new NotImplementedException(); + } + + public void Prepare() + { + throw new NotImplementedException(); + } + } + + /// + /// Test mock class for SqlConnection wrapper + /// + public class TestSqlConnection : ISqlConnection + { + public TestSqlConnection(string connectionString) + { + + } + + public void Dispose() + { + throw new System.NotImplementedException(); + } + + public IDbTransaction BeginTransaction() + { + throw new System.NotImplementedException(); + } + + public IDbTransaction BeginTransaction(IsolationLevel il) + { + throw new System.NotImplementedException(); + } + + public void Close() + { + throw new System.NotImplementedException(); + } + + public IDbCommand CreateCommand() + { + return new TestSqlCommand {Connection = this}; + } + + public void Open() + { + // No Op. + } + + public string ConnectionString { get; set; } + public int ConnectionTimeout { get; } + public string Database { get; } + public ConnectionState State { get; } + + public void ChangeDatabase(string databaseName) + { + throw new System.NotImplementedException(); + } + + public string DataSource { get; } + public string ServerVersion { get; } + public void ClearPool() + { + throw new System.NotImplementedException(); + } + + public async Task OpenAsync() + { + // No Op. + await Task.FromResult(0); + } + + public Task OpenAsync(CancellationToken token) + { + throw new System.NotImplementedException(); + } + } + + /// + /// Test mock class for SqlConnection factory + /// + public class TestSqlConnectionFactory : ISqlConnectionFactory + { + public ISqlConnection CreateSqlConnection(string connectionString) + { + return new TestSqlConnection(connectionString); + } + } +} diff --git a/test/ServiceHost.Test/packages.config b/test/Microsoft.SqlTools.ServiceLayer.Test/packages.config similarity index 100% rename from test/ServiceHost.Test/packages.config rename to test/Microsoft.SqlTools.ServiceLayer.Test/packages.config diff --git a/test/ServiceHost.Test/project.json b/test/Microsoft.SqlTools.ServiceLayer.Test/project.json similarity index 87% rename from test/ServiceHost.Test/project.json rename to test/Microsoft.SqlTools.ServiceLayer.Test/project.json index a32fe523..792ec095 100644 --- a/test/ServiceHost.Test/project.json +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/project.json @@ -1,5 +1,5 @@ { - "name": "Microsoft.SqlTools.ServiceHost.Test", + "name": "Microsoft.SqlTools.ServiceLayer.Test", "version": "1.0.0-*", "buildOptions": { "debugType": "portable" @@ -11,7 +11,7 @@ "System.Data.SqlClient": "4.1.0", "xunit": "2.1.0", "dotnet-test-xunit": "1.0.0-rc2-192208-24", - "ServiceHost": { + "Microsoft.SqlTools.ServiceLayer": { "target": "project" } }, diff --git a/test/ServiceHost.Test/Utility/TestObjects.cs b/test/ServiceHost.Test/Utility/TestObjects.cs deleted file mode 100644 index c506d600..00000000 --- a/test/ServiceHost.Test/Utility/TestObjects.cs +++ /dev/null @@ -1,108 +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.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.Connection; -using Microsoft.SqlTools.ServiceLayer.LanguageServices; -using Microsoft.SqlTools.ServiceLayer.SqlContext; -using Xunit; - -namespace Microsoft.SqlTools.Test.Utility -{ - /// - /// Tests for the ServiceHost Connection Service tests - /// - public class TestObjects - { - /// - /// Creates a test connection service - /// - public static ConnectionService GetTestConnectionService() - { -#if !USE_LIVE_CONNECTION - // use mock database connection - return new ConnectionService(new TestSqlConnectionFactory()); -#else - // connect to a real server instance - return ConnectionService.Instance; -#endif - } - - /// - /// Creates a test connection details object - /// - public static ConnectionDetails GetTestConnectionDetails() - { - return new ConnectionDetails() - { - UserName = "sa", - Password = "Yukon900", - DatabaseName = "AdventureWorks2016CTP3_2", - ServerName = "sqltools11" - }; - } - - /// - /// Create a test language service instance - /// - /// - public static LanguageService GetTestLanguageService() - { - return new LanguageService(); - } - - /// - /// Creates a test autocomplete service instance - /// - public static AutoCompleteService GetAutoCompleteService() - { - return AutoCompleteService.Instance; - } - - /// - /// Creates a test sql connection factory instance - /// - public static ISqlConnectionFactory GetTestSqlConnectionFactory() - { -#if !USE_LIVE_CONNECTION - // use mock database connection - return new TestSqlConnectionFactory(); -#else - // connect to a real server instance - return ConnectionService.Instance.ConnectionFactory; -#endif - - } - } - - /// - /// Test mock class for SqlConnection wrapper - /// - public class TestSqlConnection : ISqlConnection - { - public void OpenDatabaseConnection(string connectionString) - { - } - - public IEnumerable GetServerObjects() - { - return null; - } - } - - /// - /// Test mock class for SqlConnection factory - /// - public class TestSqlConnectionFactory : ISqlConnectionFactory - { - public ISqlConnection CreateSqlConnection() - { - return new TestSqlConnection(); - } - } -}