Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DisasterRecovery/DisasterRecoveryFileValidatorTests.cs
Karl Burtram 84ea045572 XEvent Profiler initial event handlers (#456)
* Bump SMO to 140.2.5 to pick-up private XEvent binaries

* Pick up SMO binaries from the build lab

* Add ProfilerService class placeholder

* Update SMO nuget package to include DB Scoped XEvents

* Stage changes

* Stage changes

* Update SMO to use RTM dependencies and remove separate SqlScript package

* Stage changes

* Iterate on profiler service

* Fix post-merge break in localization

* More refactoring

* Continue iterating on profiler

* Add test profiler listener

* Address a couple of the code review feedback

* Fix AppVeyor build break

* Use self-cleaning test file
2017-09-12 14:08:50 -07:00

89 lines
3.6 KiB
C#

//
// 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.Data.SqlClient;
using System.IO;
using Microsoft.SqlTools.ServiceLayer.Admin;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DisasterRecovery
{
/// <summary>
/// Integration tests for disaster recovery file validator
/// </summary>
public class DisasterRecoveryFileValidatorTests
{
[Fact]
public void ValidateDefaultBackupFullFilePath()
{
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo("master");
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
string backupPath = Path.Combine(GetDefaultBackupFolderPath(helper.DataContainer, sqlConn), "master.bak");
string message;
bool result = DisasterRecoveryFileValidator.ValidatePaths(new FileBrowserValidateEventArgs
{
ServiceType = FileValidationServiceConstants.Backup,
OwnerUri = liveConnection.ConnectionInfo.OwnerUri,
FilePaths = new string[] { backupPath }
}, out message);
Assert.True(result);
Assert.Empty(message);
}
[Fact]
public void ValidateDefaultBackupFolderPath()
{
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo("master");
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
string backupPath = GetDefaultBackupFolderPath(helper.DataContainer, sqlConn);
bool isFolder;
bool result = DisasterRecoveryFileValidator.IsPathExisting(sqlConn, backupPath, out isFolder);
Assert.True(isFolder);
Assert.True(result);
}
[Fact]
public void ValidatorShouldReturnFalseForInvalidPath()
{
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo("master");
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
string message;
bool result = DisasterRecoveryFileValidator.ValidatePaths(new FileBrowserValidateEventArgs
{
ServiceType = FileValidationServiceConstants.Backup,
OwnerUri = liveConnection.ConnectionInfo.OwnerUri,
FilePaths = new string[] { Guid.NewGuid().ToString() }
}, out message);
Assert.False(result);
Assert.True(!string.IsNullOrEmpty(message));
}
#region private methods
private string GetDefaultBackupFolderPath(CDataContainer dataContainer, SqlConnection sqlConn)
{
DisasterRecoveryService service = new DisasterRecoveryService();
BackupConfigInfo backupConfigInfo = service.GetBackupConfigInfo(dataContainer, sqlConn, sqlConn.Database);
return backupConfigInfo.DefaultBackupFolder;
}
#endregion
}
}