mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-25 01:25:40 -05:00
Added service class for machine learning services operations (#906)
* Added service class for server configurations and language extension
This commit is contained in:
@@ -78,23 +78,25 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName))
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
|
||||
// Backup the database
|
||||
service.PerformBackup(backupOperation);
|
||||
// Backup the database
|
||||
service.PerformBackup(backupOperation);
|
||||
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,29 +106,31 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName))
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
|
||||
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
|
||||
// Generate script for backup
|
||||
service.ScriptBackup(backupOperation);
|
||||
string script = backupOperation.ScriptContent;
|
||||
Assert.True(!string.IsNullOrEmpty(script));
|
||||
// Generate script for backup
|
||||
service.ScriptBackup(backupOperation);
|
||||
string script = backupOperation.ScriptContent;
|
||||
Assert.True(!string.IsNullOrEmpty(script));
|
||||
|
||||
// Execute the script
|
||||
testDb.RunQuery(script);
|
||||
// Execute the script
|
||||
testDb.RunQuery(script);
|
||||
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,45 +143,47 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName))
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
|
||||
string certificateName = CreateCertificate(testDb);
|
||||
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
||||
string certificateName = CreateCertificate(testDb);
|
||||
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
||||
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
backupInfo.ContinueAfterError = true;
|
||||
backupInfo.FormatMedia = true;
|
||||
backupInfo.SkipTapeHeader = true;
|
||||
backupInfo.Initialize = true;
|
||||
backupInfo.MediaName = "backup test media";
|
||||
backupInfo.MediaDescription = "backup test";
|
||||
backupInfo.RetainDays = 90;
|
||||
backupInfo.CompressionOption = (int)BackupCompressionOptions.On;
|
||||
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
||||
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
||||
backupInfo.EncryptorName = certificateName;
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
backupInfo.ContinueAfterError = true;
|
||||
backupInfo.FormatMedia = true;
|
||||
backupInfo.SkipTapeHeader = true;
|
||||
backupInfo.Initialize = true;
|
||||
backupInfo.MediaName = "backup test media";
|
||||
backupInfo.MediaDescription = "backup test";
|
||||
backupInfo.RetainDays = 90;
|
||||
backupInfo.CompressionOption = (int)BackupCompressionOptions.On;
|
||||
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
||||
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
||||
backupInfo.EncryptorName = certificateName;
|
||||
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
|
||||
// Backup the database
|
||||
Console.WriteLine("Perform backup operation..");
|
||||
service.PerformBackup(backupOperation);
|
||||
// Backup the database
|
||||
Console.WriteLine("Perform backup operation..");
|
||||
service.PerformBackup(backupOperation);
|
||||
|
||||
// Remove the backup file
|
||||
Console.WriteLine("Verify the backup file exists and remove..");
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
// Remove the backup file
|
||||
Console.WriteLine("Verify the backup file exists and remove..");
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
|
||||
// Delete certificate and master key
|
||||
Console.WriteLine("Remove certificate and master key..");
|
||||
testDb.RunQuery(cleanupCertificateQuery);
|
||||
// Delete certificate and master key
|
||||
Console.WriteLine("Remove certificate and master key..");
|
||||
testDb.RunQuery(cleanupCertificateQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,47 +196,49 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName))
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||
using (DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true))
|
||||
using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo))
|
||||
{
|
||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||
|
||||
string certificateName = CreateCertificate(testDb);
|
||||
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
||||
string certificateName = CreateCertificate(testDb);
|
||||
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
||||
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
backupInfo.FormatMedia = true;
|
||||
backupInfo.SkipTapeHeader = true;
|
||||
backupInfo.Initialize = true;
|
||||
backupInfo.MediaName = "backup test media";
|
||||
backupInfo.MediaDescription = "backup test";
|
||||
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
||||
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
||||
backupInfo.EncryptorName = certificateName;
|
||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||
BackupType.Full,
|
||||
new List<string>() { backupPath },
|
||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||
backupInfo.FormatMedia = true;
|
||||
backupInfo.SkipTapeHeader = true;
|
||||
backupInfo.Initialize = true;
|
||||
backupInfo.MediaName = "backup test media";
|
||||
backupInfo.MediaDescription = "backup test";
|
||||
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
||||
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
||||
backupInfo.EncryptorName = certificateName;
|
||||
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||
|
||||
// Backup the database
|
||||
Console.WriteLine("Generate script for backup operation..");
|
||||
service.ScriptBackup(backupOperation);
|
||||
string script = backupOperation.ScriptContent;
|
||||
// Backup the database
|
||||
Console.WriteLine("Generate script for backup operation..");
|
||||
service.ScriptBackup(backupOperation);
|
||||
string script = backupOperation.ScriptContent;
|
||||
|
||||
// Run the script
|
||||
Console.WriteLine("Execute the script..");
|
||||
testDb.RunQuery(script);
|
||||
// Run the script
|
||||
Console.WriteLine("Execute the script..");
|
||||
testDb.RunQuery(script);
|
||||
|
||||
// Remove the backup file
|
||||
Console.WriteLine("Verify the backup file exists and remove..");
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
// Remove the backup file
|
||||
Console.WriteLine("Verify the backup file exists and remove..");
|
||||
VerifyAndCleanBackup(sqlConn, backupPath);
|
||||
|
||||
// Delete certificate and master key
|
||||
Console.WriteLine("Remove certificate and master key..");
|
||||
testDb.RunQuery(cleanupCertificateQuery);
|
||||
// Delete certificate and master key
|
||||
Console.WriteLine("Remove certificate and master key..");
|
||||
testDb.RunQuery(cleanupCertificateQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// 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.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageExtensions;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageExtensions.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Moq;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageExtensions
|
||||
{
|
||||
public class LanguageExtensionsTests
|
||||
{
|
||||
[Fact]
|
||||
public async void VerifyExternalLanguageStatusRequest()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
ExternalLanguageStatusResponseParams result = null;
|
||||
var requestContext = RequestContextMocks.Create<ExternalLanguageStatusResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
|
||||
ExternalLanguageStatusRequestParams requestParams = new ExternalLanguageStatusRequestParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
LanguageName = "Python"
|
||||
};
|
||||
|
||||
await LanguageExtensionsService.Instance.HandleExternalLanguageStatusRequest(requestParams, requestContext.Object);
|
||||
Assert.NotNull(result);
|
||||
|
||||
LanguageExtensionsService.Instance.ConnectionServiceInstance.Disconnect(new DisconnectParams
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
Type = ServiceLayer.Connection.ConnectionType.Default
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void VerifyExternalLanguageStatusRequestSendErrorGivenInvalidConnection()
|
||||
{
|
||||
ExternalLanguageStatusResponseParams result = null;
|
||||
var requestContext = RequestContextMocks.Create<ExternalLanguageStatusResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
requestContext.Setup(x => x.SendError(It.IsAny<Exception>())).Returns(System.Threading.Tasks.Task.FromResult(true));
|
||||
|
||||
ExternalLanguageStatusRequestParams requestParams = new ExternalLanguageStatusRequestParams
|
||||
{
|
||||
OwnerUri = "invalid uri",
|
||||
LanguageName = "Python"
|
||||
};
|
||||
|
||||
await LanguageExtensionsService.Instance.HandleExternalLanguageStatusRequest(requestParams, requestContext.Object);
|
||||
requestContext.Verify(x => x.SendError(It.IsAny<Exception>()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// 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.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.MachineLearningServices
|
||||
{
|
||||
public class ServerConfigurationsServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async void VerifyListingConfigs()
|
||||
{
|
||||
List<ServerConfigProperty> configs = await GetAllConfigs();
|
||||
Assert.NotNull(configs);
|
||||
Assert.True(configs.Count > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void VerifyUpdatingConfigs()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
List<ServerConfigProperty> configs = await GetAllConfigs();
|
||||
Assert.NotNull(configs);
|
||||
Assert.True(configs.Count > 0);
|
||||
ServerConfigProperty sampleConfig = configs[0];
|
||||
|
||||
ServerConfigViewResponseParams result = null;
|
||||
ServerConfigUpdateResponseParams updateResult = null;
|
||||
int newValue = sampleConfig.ConfigValue == sampleConfig.Minimum ? sampleConfig.Maximum : sampleConfig.Minimum;
|
||||
|
||||
var requestContext = RequestContextMocks.Create<ServerConfigViewResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
var updateRequestContext = RequestContextMocks.Create<ServerConfigUpdateResponseParams>(r => updateResult = r).AddErrorHandling(null);
|
||||
|
||||
ServerConfigViewRequestParams requestParams = new ServerConfigViewRequestParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
ConfigNumber = sampleConfig.Number
|
||||
};
|
||||
ServerConfigUpdateRequestParams updateRequestParams = new ServerConfigUpdateRequestParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
ConfigNumber = sampleConfig.Number,
|
||||
ConfigValue = newValue
|
||||
};
|
||||
|
||||
await ServerConfigService.Instance.HandleServerConfigViewRequest(requestParams, requestContext.Object);
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(result.ConfigProperty.ConfigValue, sampleConfig.ConfigValue);
|
||||
await ServerConfigService.Instance.HandleServerConfigUpdateRequest(updateRequestParams, updateRequestContext.Object);
|
||||
Assert.NotNull(updateResult);
|
||||
Assert.Equal(updateResult.ConfigProperty.ConfigValue, newValue);
|
||||
updateRequestParams.ConfigValue = sampleConfig.ConfigValue;
|
||||
await ServerConfigService.Instance.HandleServerConfigUpdateRequest(updateRequestParams, updateRequestContext.Object);
|
||||
Assert.NotNull(updateResult);
|
||||
Assert.Equal(updateResult.ConfigProperty.ConfigValue, sampleConfig.ConfigValue);
|
||||
ServerConfigService.Instance.ConnectionServiceInstance.Disconnect(new DisconnectParams
|
||||
{
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
Type = ServiceLayer.Connection.ConnectionType.Default
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ServerConfigProperty>> GetAllConfigs()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
|
||||
ServerConfigListResponseParams result = null;
|
||||
|
||||
var requestContext = RequestContextMocks.Create<ServerConfigListResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
|
||||
ServerConfigListRequestParams requestParams = new ServerConfigListRequestParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri
|
||||
};
|
||||
|
||||
await ServerConfigService.Instance.HandleServerConfigListRequest(requestParams, requestContext.Object);
|
||||
Assert.NotNull(result);
|
||||
return result.ConfigProperties;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async void VerifyConfigViewRequestSendErrorGivenInvalidConnection()
|
||||
{
|
||||
ServerConfigViewResponseParams result = null;
|
||||
var requestContext = RequestContextMocks.Create<ServerConfigViewResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
requestContext.Setup(x => x.SendError(It.IsAny<Exception>())).Returns(System.Threading.Tasks.Task.FromResult(true));
|
||||
|
||||
ServerConfigViewRequestParams requestParams = new ServerConfigViewRequestParams
|
||||
{
|
||||
OwnerUri = "invalid uri"
|
||||
};
|
||||
|
||||
await ServerConfigService.Instance.HandleServerConfigViewRequest(requestParams, requestContext.Object);
|
||||
requestContext.Verify(x => x.SendError(It.IsAny<Exception>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void VerifyConfigUpdateRequestSendErrorGivenInvalidConnection()
|
||||
{
|
||||
ServerConfigUpdateResponseParams result = null;
|
||||
var requestContext = RequestContextMocks.Create<ServerConfigUpdateResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
requestContext.Setup(x => x.SendError(It.IsAny<Exception>())).Returns(System.Threading.Tasks.Task.FromResult(true));
|
||||
|
||||
ServerConfigUpdateRequestParams requestParams = new ServerConfigUpdateRequestParams
|
||||
{
|
||||
OwnerUri = "invalid uri",
|
||||
ConfigValue = 1
|
||||
};
|
||||
|
||||
await ServerConfigService.Instance.HandleServerConfigUpdateRequest(requestParams, requestContext.Object);
|
||||
requestContext.Verify(x => x.SendError(It.IsAny<Exception>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void VerifyConfigListRequestSendErrorGivenInvalidConnection()
|
||||
{
|
||||
ServerConfigListResponseParams result = null;
|
||||
var requestContext = RequestContextMocks.Create<ServerConfigListResponseParams>(r => result = r).AddErrorHandling(null);
|
||||
requestContext.Setup(x => x.SendError(It.IsAny<Exception>())).Returns(System.Threading.Tasks.Task.FromResult(true));
|
||||
|
||||
ServerConfigListRequestParams requestParams = new ServerConfigListRequestParams
|
||||
{
|
||||
OwnerUri = "invalid uri",
|
||||
};
|
||||
|
||||
await ServerConfigService.Instance.HandleServerConfigListRequest(requestParams, requestContext.Object);
|
||||
requestContext.Verify(x => x.SendError(It.IsAny<Exception>()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
}
|
||||
|
||||
public static async Task<TestConnectionResult> InitLiveConnectionInfoAsync(string databaseName = null, string ownerUri = null,
|
||||
string connectionType = ServiceLayer.Connection.ConnectionType.Default)
|
||||
string connectionType = ServiceLayer.Connection.ConnectionType.Default, TestServerType serverType = TestServerType.OnPrem)
|
||||
{
|
||||
ScriptFile scriptFile = null;
|
||||
if (string.IsNullOrEmpty(ownerUri))
|
||||
@@ -72,7 +72,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility
|
||||
scriptFile = TestServiceProvider.Instance.WorkspaceService.Workspace.GetFile(ownerUri);
|
||||
ownerUri = scriptFile.ClientUri;
|
||||
}
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(TestServerType.OnPrem, databaseName);
|
||||
ConnectParams connectParams = TestServiceProvider.Instance.ConnectionProfileService.GetConnectionParameters(serverType, databaseName);
|
||||
|
||||
var connectionService = GetLiveTestConnectionService();
|
||||
var connectionResult =
|
||||
|
||||
Reference in New Issue
Block a user