mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-04 17:24:56 -05:00
Port Azure code from SSDT to the tools service (#477)
Porting of the vast majority of Azure-related code from SSDT. This is very large, so I want to put this out as one large "lift and shift" PR before I do the tools-service specific JSON-RPC service handlers, connect a new account handler (as the code to get necessary info from accounts and subscriptions isn't fully complete) and add tests over these **What's in this PR**: - Created 3 new projects: - Microsoft.SqlTools.ResourceProvider will host the executable that accepts requests for Azure-related actions over the JSON-RPC protocol. This must be separate from other DLLs since a direct dependency on the Azure SDK DLLs fails (they're NetStandard 1.4 and you can't reference them if you have RuntimeIdentifiers in your .csproj file) - Microsoft.SqlTools.ResourceProvider.Core is where all the main business logic is, including definitions and logic on how to navigate over resources and create firewall rules, etc. - Microsoft.SqlTools.ResourceProvider.DefaultImpl is the actual Azure implementation of the resource provider APIs. The reason for separating this is to support eventual integration back into other tools (since their Azure and Identity services will be different). - Implemented the AzureResourceManager that connects to Azure via ARM APIs and handles creating firewall rule and querying databases. The dependent DLLs have had major breaking changes, so will need additional verification to ensure this works as expected - Ported the unit tests for all code that was not a viewmodel. Viewmodel test code will be ported in a future update as we plumb through a service-equivalent to these. Also, the DependencyManager code which has overlap with our service provider code is commented out. Will work to uncomment in a future update as it has value to test some scenarios **What's not in this PR**: - Identity Services. We currently just have a stub for the interface, and even that will likely change a little - anything JSON-RPC or registered service related. These will be adapted from the viewmodels and added in a separate PR
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// 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.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Extensibility;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
[Exportable(ServerTypes.SqlServer, Categories.Azure,
|
||||
typeof(IAccountManager),
|
||||
"Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes.FakeAccountManager", 1)]
|
||||
public class FakeAccountManager : IAccountManager
|
||||
{
|
||||
public FakeAccountManager(IExportableMetadata metadata)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
public ITrace Trace { get; set; }
|
||||
public Task<bool> GetUserNeedsReauthenticationAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> AuthenticateAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsCachExpired { get; private set; }
|
||||
public bool SessionIsCached { get; private set; }
|
||||
public void ResetSession()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> AddUserAccountAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> SetCurrentAccountAsync(object account)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> SetCurrentAccountFromLoginDialogAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> GetCurrentAccountAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool HasLoginDialog { get; }
|
||||
|
||||
public event EventHandler CurrentAccountChanged;
|
||||
|
||||
public IUserAccount SetCurrentAccount(object account)
|
||||
{
|
||||
if (CurrentAccountChanged != null)
|
||||
{
|
||||
CurrentAccountChanged(this, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetServiceProvider(IMultiServiceProvider provider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IExportableMetadata Metadata { get; set; }
|
||||
public ExportableStatus Status { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// 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.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Extensibility;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
[Exportable("SqlServer", "Network",
|
||||
typeof(IAccountManager), "Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes.FakeAccountManager2", 2)]
|
||||
public class FakeAccountManager2 : IAccountManager
|
||||
{
|
||||
public FakeAccountManager2(IExportableMetadata metadata)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
public ITrace Trace { get; set; }
|
||||
public Task<bool> GetUserNeedsReauthenticationAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> AuthenticateAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsCachExpired { get; private set; }
|
||||
public bool SessionIsCached { get; private set; }
|
||||
public void ResetSession()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> AddUserAccountAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> SetCurrentAccountAsync(object account)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> SetCurrentAccountFromLoginDialogAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<IUserAccount> GetCurrentAccountAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool HasLoginDialog { get; }
|
||||
|
||||
public event EventHandler CurrentAccountChanged;
|
||||
|
||||
public IUserAccount SetCurrentAccount(object account)
|
||||
{
|
||||
if (CurrentAccountChanged != null)
|
||||
{
|
||||
CurrentAccountChanged(this, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetServiceProvider(IMultiServiceProvider provider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IExportableMetadata Metadata { get; set; }
|
||||
public ExportableStatus Status { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// 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.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure;
|
||||
using Moq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
internal static class FakeDataFactory
|
||||
{
|
||||
//public static ExtensionProperties CreateServiceProperties(IList<Lazy<IServerDiscoveryProvider, IExportableMetadata>> exports)
|
||||
//{
|
||||
// FakeExportProvider fakeProvider = new FakeExportProvider(f => ((FakeInstanceExportDefinition)f).Instance);
|
||||
// foreach (var export in exports)
|
||||
// {
|
||||
// var metadata = new Dictionary<string, object>()
|
||||
// {
|
||||
// {"ServerType", export.Metadata.ServerType},
|
||||
// {"Category", export.Metadata.Category},
|
||||
// {"Id", export.Metadata.Id },
|
||||
// {"Priority", export.Metadata.Priority}
|
||||
// };
|
||||
|
||||
// var definition = new FakeInstanceExportDefinition(typeof(IServerDiscoveryProvider), export.Value, metadata);
|
||||
// fakeProvider.AddExportDefinitions(definition);
|
||||
// }
|
||||
// var trace = new Mock<ITrace>();
|
||||
// trace.Setup(x => x.TraceEvent(It.IsAny<TraceEventType>(), It.IsAny<int>(), It.IsAny<string>(), It.IsAny<object[]>()))
|
||||
// .Returns(true);
|
||||
|
||||
// var metadata2 = new Dictionary<string, object>()
|
||||
// {
|
||||
// {"Id", Guid.NewGuid().ToString()},
|
||||
// {"Priority", 0}
|
||||
// };
|
||||
// var traceDefinition = new FakeInstanceExportDefinition(typeof(ITrace), trace, metadata2);
|
||||
// fakeProvider.AddExportDefinitions(traceDefinition);
|
||||
|
||||
// ExtensionProperties serviceProperties = new ExtensionProperties(false);
|
||||
// serviceProperties.Providers = new ExportProvider[] { fakeProvider };
|
||||
// TypeCatalog typeCatalog = new TypeCatalog(typeof(FakeTrace));
|
||||
// serviceProperties.AddCatalog(typeCatalog);
|
||||
// return serviceProperties;
|
||||
//}
|
||||
|
||||
internal static AzureDatabaseDiscoveryProvider CreateAzureDatabaseDiscoveryProvider(
|
||||
Dictionary<string, List<string>> subscriptionToDatabaseMap)
|
||||
{
|
||||
AzureTestContext testContext = new AzureTestContext(subscriptionToDatabaseMap);
|
||||
|
||||
AzureDatabaseDiscoveryProvider databaseDiscoveryProvider = new AzureDatabaseDiscoveryProvider();
|
||||
databaseDiscoveryProvider.AccountManager = testContext.AzureAccountManager;
|
||||
databaseDiscoveryProvider.AzureResourceManager = testContext.AzureResourceManager;
|
||||
|
||||
return databaseDiscoveryProvider;
|
||||
}
|
||||
|
||||
internal static AzureSqlServerDiscoveryProvider CreateAzureServerDiscoveryProvider(Dictionary<string, List<string>> subscriptionToDatabaseMap)
|
||||
{
|
||||
AzureTestContext testContext = new AzureTestContext(subscriptionToDatabaseMap);
|
||||
|
||||
AzureSqlServerDiscoveryProvider serverDiscoveryProvider = new AzureSqlServerDiscoveryProvider();
|
||||
serverDiscoveryProvider.AccountManager = testContext.AzureAccountManager;
|
||||
serverDiscoveryProvider.AzureResourceManager = testContext.AzureResourceManager;
|
||||
|
||||
return serverDiscoveryProvider;
|
||||
}
|
||||
|
||||
//internal static IDependencyManager AddDependencyProvider<T>(T provider,
|
||||
// ServerDefinition serverDefinition, IDependencyManager existingDependencyManager = null)
|
||||
// where T : IExportable
|
||||
//{
|
||||
// return AddDependencyProviders(new Dictionary<T,ServerDefinition>() {{ provider, serverDefinition}}, existingDependencyManager);
|
||||
//}
|
||||
|
||||
//internal static IDependencyManager AddDependencyProviders<T>(Dictionary<T, ServerDefinition> providers, IDependencyManager existingDependencyManager = null)
|
||||
// where T : IExportable
|
||||
//{
|
||||
// IDependencyManager dependencyManager = existingDependencyManager ?? new Mock<IDependencyManager>();
|
||||
|
||||
// IEnumerable<ExportableDescriptor<T>> exportableDescriptors =
|
||||
// providers.Select(x => new ExportableDescriptorImpl<T>(
|
||||
// new ExtensionDescriptor<T, IExportableMetadata>(
|
||||
// new Lazy<T, IExportableMetadata>(
|
||||
// () => x.Key,
|
||||
// new ExportableAttribute(x.Value.ServerType, x.Value.Category,
|
||||
// typeof (T), Guid.NewGuid().ToString())))));
|
||||
|
||||
// dependencyManager.Setup(x => x.GetServiceDescriptors<T>()).Returns(exportableDescriptors);
|
||||
|
||||
// return dependencyManager;
|
||||
//}
|
||||
|
||||
internal static ServiceResponse<ServerInstanceInfo> CreateServerInstanceResponse(int numberOfServers, ServerDefinition serverDefinition, Exception exception = null)
|
||||
{
|
||||
List<ServerInstanceInfo> servers = new List<ServerInstanceInfo>();
|
||||
for (int i = 0; i < numberOfServers; i++)
|
||||
{
|
||||
servers.Add(new ServerInstanceInfo(serverDefinition)
|
||||
{
|
||||
Name = Guid.NewGuid().ToString(),
|
||||
FullyQualifiedDomainName = Guid.NewGuid().ToString()
|
||||
});
|
||||
}
|
||||
ServiceResponse<ServerInstanceInfo> response;
|
||||
if (exception != null)
|
||||
{
|
||||
response = new ServiceResponse<ServerInstanceInfo>(servers, new List<Exception> { exception });
|
||||
}
|
||||
else
|
||||
{
|
||||
response = new ServiceResponse<ServerInstanceInfo>(servers);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
internal static ServiceResponse<DatabaseInstanceInfo> CreateDatabaseInstanceResponse(int numberOfServers, ServerDefinition serverDefinition = null,
|
||||
string serverName = "", Exception exception = null)
|
||||
{
|
||||
serverDefinition = serverDefinition ?? ServerDefinition.Default;
|
||||
List<DatabaseInstanceInfo> databases = new List<DatabaseInstanceInfo>();
|
||||
for (int i = 0; i < numberOfServers; i++)
|
||||
{
|
||||
databases.Add(new DatabaseInstanceInfo(serverDefinition, serverName, Guid.NewGuid().ToString()));
|
||||
}
|
||||
ServiceResponse<DatabaseInstanceInfo> response;
|
||||
if (exception != null)
|
||||
{
|
||||
response = new ServiceResponse<DatabaseInstanceInfo>(databases, new List<Exception> { exception });
|
||||
}
|
||||
else
|
||||
{
|
||||
response = new ServiceResponse<DatabaseInstanceInfo>(databases);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
//internal static UIConnectionInfo CreateUiConnectionInfo(string baseDbName)
|
||||
//{
|
||||
// SqlConnectionStringBuilder connectionStringBuilder = CreateConnectionStringBuilder(baseDbName);
|
||||
// return CreateUiConnectionInfo(connectionStringBuilder);
|
||||
//}
|
||||
//internal static UIConnectionInfo CreateUiConnectionInfo(SqlConnectionStringBuilder connectionStringBuilder)
|
||||
//{
|
||||
// UIConnectionInfo ci = UIConnectionInfoUtil.GetUIConnectionInfoFromConnectionString(connectionStringBuilder.ConnectionString, (new SqlServerType()));
|
||||
// ci.PersistPassword = connectionStringBuilder.PersistSecurityInfo;
|
||||
// return ci;
|
||||
//}
|
||||
|
||||
|
||||
//internal static SqlConnectionStringBuilder CreateConnectionStringBuilder(string baseDbName)
|
||||
//{
|
||||
// return CreateConnectionStringBuilder(baseDbName, InstanceManager.DefaultSql2011);
|
||||
//}
|
||||
|
||||
|
||||
//internal static SqlConnectionStringBuilder CreateConnectionStringBuilder(string baseDbName, InstanceInfo dbInstance)
|
||||
//{
|
||||
// string dbName = ConnectionDialogHelper.CreateTestDatabase(baseDbName, dbInstance);
|
||||
// string dbConnectionString = dbInstance.BuildConnectionString(dbName);
|
||||
// SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(dbConnectionString);
|
||||
// connectionStringBuilder.ApplicationName = Guid.NewGuid().ToString();
|
||||
// connectionStringBuilder.ConnectTimeout = 123;
|
||||
// connectionStringBuilder.Encrypt = true;
|
||||
// connectionStringBuilder.ApplicationIntent = ApplicationIntent.ReadWrite;
|
||||
// connectionStringBuilder.AsynchronousProcessing = true;
|
||||
// connectionStringBuilder.MaxPoolSize = 45;
|
||||
// connectionStringBuilder.MinPoolSize = 3;
|
||||
// connectionStringBuilder.PacketSize = 600;
|
||||
// connectionStringBuilder.Pooling = true;
|
||||
// connectionStringBuilder.TrustServerCertificate = false;
|
||||
// return connectionStringBuilder;
|
||||
//}
|
||||
|
||||
//internal static ConnectionInfo CreateConnectionInfo(string baseDbName, IEventsChannel eventsChannel = null)
|
||||
//{
|
||||
// ConnectionInfo connectionInfo = new ConnectionInfo(eventsChannel);
|
||||
// UIConnectionInfo uiConnectionInfo = CreateUiConnectionInfo(baseDbName);
|
||||
// connectionInfo.UpdateConnectionInfo(uiConnectionInfo);
|
||||
// return connectionInfo;
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// 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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Extensibility;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
/// <summary>
|
||||
/// A fake database discovery class which generates db names for 5 seconds or until it gets canceled
|
||||
/// </summary>
|
||||
public class FakeDatabaseDiscoveryProvider : IDatabaseDiscoveryProvider
|
||||
{
|
||||
private TimeSpan _timeout = TimeSpan.FromSeconds(5);
|
||||
|
||||
public IExportableMetadata Metadata { get; set; }
|
||||
public ExportableStatus Status { get; }
|
||||
IExportableMetadata IExportable.Metadata { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
ExportableStatus IExportable.Status => throw new NotImplementedException();
|
||||
|
||||
public Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabaseInstancesAsync(string serverName, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//public Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabaseInstancesAsync(UIConnectionInfo uiConnectionInfo, CancellationToken cancellationToken)
|
||||
//{
|
||||
// return Task.Factory.StartNew(() => GetDatabaseInstances(uiConnectionInfo, cancellationToken), cancellationToken);
|
||||
//}
|
||||
|
||||
//private ServiceResponse<DatabaseInstanceInfo> GetDatabaseInstances(UIConnectionInfo uiConnectionInfo, CancellationToken cancellationToken)
|
||||
//{
|
||||
// List<DatabaseInstanceInfo> databases = new List<DatabaseInstanceInfo>();
|
||||
// DateTime startTime = DateTime.UtcNow;
|
||||
// while (!cancellationToken.IsCancellationRequested)
|
||||
// {
|
||||
// DateTime now = DateTime.UtcNow;
|
||||
// if (now.Subtract(startTime).TotalMilliseconds >= _timeout.TotalMilliseconds)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// databases.Add(new DatabaseInstanceInfo(ServerDefinition.Default, uiConnectionInfo.ServerName, uiConnectionInfo.ServerName + "" + Guid.NewGuid().ToString()));
|
||||
// }
|
||||
|
||||
// return new ServiceResponse<DatabaseInstanceInfo>(databases);
|
||||
//}
|
||||
|
||||
private static void TimerCallback(object state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnDatabaseFound(DatabaseInstanceInfo databaseInfo)
|
||||
{
|
||||
if (DatabaseFound != null)
|
||||
{
|
||||
DatabaseFound(this, new DatabaseInfoEventArgs() { Database = databaseInfo });
|
||||
}
|
||||
}
|
||||
|
||||
public void SetServiceProvider(IMultiServiceProvider provider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public event EventHandler<DatabaseInfoEventArgs> DatabaseFound;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
public interface IDatabaseResourceManager
|
||||
{
|
||||
}
|
||||
|
||||
[Exportable(FakeServerDiscoveryProvider.ServerTypeValue, FakeServerDiscoveryProvider.CategoryValue
|
||||
, typeof(IDatabaseResourceManager), "Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes.FakeDatabaseResourceManager")]
|
||||
public class FakeDatabaseResourceManager : IDatabaseResourceManager
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
[Exportable("SqlServer", "azure", typeof(IServerDiscoveryProvider),
|
||||
"Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes.FakeSecureServerDiscoveryProvider")]
|
||||
public class FakeSecureServerDiscoveryProvider : ExportableBase, IServerDiscoveryProvider, ISecureService
|
||||
{
|
||||
public FakeSecureServerDiscoveryProvider(IExportableMetadata metadata)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
public async Task<ServiceResponse<ServerInstanceInfo>> GetServerInstancesAsync()
|
||||
{
|
||||
return await Task.Run(() => new ServiceResponse<ServerInstanceInfo>());
|
||||
}
|
||||
|
||||
public IDatabaseResourceManager DatabaseResourceManager
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public IAccountManager AccountManager
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetService<IAccountManager>();
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
[Exportable(ServerTypeValue, CategoryValue
|
||||
, typeof(IServerDiscoveryProvider),
|
||||
"Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes.FakeServerDiscoveryProvider")]
|
||||
public class FakeServerDiscoveryProvider : ExportableBase, IServerDiscoveryProvider
|
||||
{
|
||||
public FakeServerDiscoveryProvider(IExportableMetadata metadata)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
public async Task<ServiceResponse<ServerInstanceInfo>> GetServerInstancesAsync()
|
||||
{
|
||||
return await Task.Run(() => new ServiceResponse<ServerInstanceInfo>());
|
||||
}
|
||||
|
||||
|
||||
public IDatabaseResourceManager DatabaseResourceManager
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public const string ServerTypeValue = "FakeServerType";
|
||||
public const string CategoryValue = "FakeCategory";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
public class FakeServerDiscoveryProvider2 : ExportableBase, IServerDiscoveryProvider
|
||||
{
|
||||
public FakeServerDiscoveryProvider2(IExportableMetadata metadata)
|
||||
{
|
||||
Metadata = metadata;
|
||||
}
|
||||
|
||||
public async Task<ServiceResponse<ServerInstanceInfo>> GetServerInstancesAsync()
|
||||
{
|
||||
return await Task.Run(() => new ServiceResponse<ServerInstanceInfo>());
|
||||
}
|
||||
|
||||
|
||||
public IDatabaseResourceManager DatabaseResourceManager
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public const string ServerTypeValue = "FakeServerType";
|
||||
public const string CategoryValue = "FakeCategory";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// 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.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.SqlTools.Extensibility;
|
||||
using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes
|
||||
{
|
||||
[Exportable(typeof(ITrace), "Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes.FakeTrace")
|
||||
]
|
||||
public class FakeTrace : ITrace
|
||||
{
|
||||
private readonly List<string> _traces = new List<string>();
|
||||
public bool TraceEvent(TraceEventType eventType, int traceId, string message, params object[] args)
|
||||
{
|
||||
_traces.Add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TraceException(TraceEventType eventType, int traceId, Exception exception, string message, int lineNumber = 0,
|
||||
string fileName = "", string memberName = "")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetServiceProvider(IMultiServiceProvider provider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<string> Traces
|
||||
{
|
||||
get
|
||||
{
|
||||
return _traces;
|
||||
}
|
||||
}
|
||||
|
||||
public IExportableMetadata Metadata { get; set; }
|
||||
public ExportableStatus Status { get; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user