Add support to save publish profile (#1844)

* Add support to save publish profile

* Address comments

* Update dacfx nuget package version

* Fix test

* Address comments

* Resolve package.props conflict

* Add content verification in test and use handler methods instead of try-catch

* Address comments
This commit is contained in:
Sakshi Sharma
2023-02-09 11:56:43 -08:00
committed by GitHub
parent b717ca9d6c
commit 497118ed82
4 changed files with 149 additions and 0 deletions

View File

@@ -23,6 +23,8 @@ using Microsoft.SqlServer.Dac.Model;
using NUnit.Framework;
using Moq;
using System.Reflection;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DacFx
{
@@ -868,6 +870,37 @@ Streaming query statement contains a reference to missing output stream 'Missing
}
}
// <summary>
/// Verify that publish profile gets created and saved
/// </summary>
[Test]
public async Task ValidateSavePublishProfile()
{
DacFxService service = new DacFxService();
string fileName = "validateSavePublishProfile.publish.xml";
string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest");
string profileFilePath = Path.Combine(folderPath, fileName);
string expectedFile = Path.Combine(publishProfileFolder, fileName);
var savePublishProfileParams = new SavePublishProfileParams
{
ProfilePath = profileFilePath,
DatabaseName = "testDb",
ConnectionString = "testConnString",
SqlCommandVariableValues = new Dictionary<string, string>()
{
{ "testvar", "testval" }
}
};
MockRequest<ResultStatus> requestMock = new();
await service.HandleSavePublishProfileRequest(savePublishProfileParams, requestMock.Object);
requestMock.AssertSuccess(nameof(service.HandleSavePublishProfileRequest));
await VerifyContentAndCleanupAsync(expectedFile, profileFilePath);
}
private bool ValidateStreamingJobErrors(ValidateStreamingJobResult expected, ValidateStreamingJobResult actual)
{
return expected.Success == actual.Success
@@ -942,6 +975,24 @@ Streaming query statement contains a reference to missing output stream 'Missing
}
}
private async Task VerifyContentAndCleanupAsync(string baselineFilePath, string outputFilePath)
{
// Verify it was created
Assert.True(File.Exists(outputFilePath), "The output file did not get generated.");
//Verify the contents are same
string baseline = await File.ReadAllTextAsync(baselineFilePath);
string output = await File.ReadAllTextAsync(outputFilePath);
Assert.That(output, Is.EqualTo(baseline), $"The output doesn't match the baseline. Expected {Environment.NewLine} {baseline} {Environment.NewLine} Actual {Environment.NewLine} {output}");
// Remove the file
if (File.Exists(outputFilePath))
{
File.Delete(outputFilePath);
}
}
/// <summary>
/// Verify expected and actual DeploymentOptions BooleanOptionsDictionary values
/// </summary>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetDatabaseName>testDb</TargetDatabaseName>
<TargetConnectionString>testConnString</TargetConnectionString>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
<ItemGroup>
<SqlCmdVariable Include="testvar">
<Value>testval</Value>
</SqlCmdVariable>
</ItemGroup>
</Project>