Feature/schemacompare scmp save (#824)

* First cut of scmp Save related changes and some test refactoring

* Adding Exclude/Include objects in saving

* Add diff entry validation as part of test

* Adding PR comments - major change is change to nameparts in place of name hence preserving any "."/"[" in name and avoiding any string operations

* One more UT scenario addition for create excluded object
This commit is contained in:
udeeshagautam
2019-06-13 17:28:59 -07:00
committed by GitHub
parent b451670222
commit 432e054d55
11 changed files with 883 additions and 235 deletions

View File

@@ -3,10 +3,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlServer.Dac;
using Microsoft.SqlTools.ServiceLayer.DacFx;
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
using Microsoft.SqlTools.ServiceLayer.Test.Common;
using NUnit.Framework;
using System;
@@ -50,6 +52,18 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SchemaCompare
return extractParams.PackageFilePath;
}
internal static string CreateScmpPath()
{
var result = GetLiveAutoCompleteTestObjects();
string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SchemaCompareTest");
Directory.CreateDirectory(folderPath);
string fileName = TestContext.CurrentContext?.Test?.Name + "_" + DateTime.Now.Ticks.ToString();
string path = Path.Combine(folderPath, string.Format("{0}.scmp", fileName));
return path;
}
internal static LiveConnectionHelper.TestConnectionResult GetLiveAutoCompleteTestObjects()
{
// Adding retry for reliability - otherwise it caused test to fail in lab
@@ -69,5 +83,52 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SchemaCompare
return result;
}
internal static void CompareOptions(DeploymentOptions deploymentOptions, DacDeployOptions dacDeployOptions)
{
System.Reflection.PropertyInfo[] deploymentOptionsProperties = deploymentOptions.GetType().GetProperties();
System.Reflection.PropertyInfo[] dacDeployProperties = dacDeployOptions.GetType().GetProperties();
// Note that DatabaseSpecification and sql cmd variables list is not present in Sqltools service - its not settable and is not used by ADS options.
// They are not present in SSDT as well
// TODO : update this test if the above options are added later
Assert.True(deploymentOptionsProperties.Length == dacDeployProperties.Length - 2, $"Number of properties is not same Deployment options : {deploymentOptionsProperties.Length} DacFx options : {dacDeployProperties.Length}");
foreach (var deployOptionsProp in deploymentOptionsProperties)
{
var dacProp = dacDeployOptions.GetType().GetProperty(deployOptionsProp.Name);
Assert.True(dacProp != null, $"DacDeploy property not present for {deployOptionsProp.Name}");
var deployOptionsValue = deployOptionsProp.GetValue(deploymentOptions);
var dacValue = dacProp.GetValue(dacDeployOptions);
if (deployOptionsProp.Name != "ExcludeObjectTypes") // do not compare for ExcludeObjectTypes because it will be different
{
Assert.True((deployOptionsValue == null && dacValue == null) || deployOptionsValue.Equals(dacValue), $"DacFx DacDeploy property not equal to Tools Service DeploymentOptions for { deployOptionsProp.Name}, SchemaCompareOptions value: {deployOptionsValue} and DacDeployOptions value: {dacValue} ");
}
}
}
internal static bool ValidateOptionsEqualsDefault(SchemaCompareOptionsResult options)
{
DeploymentOptions defaultOpt = new DeploymentOptions();
DeploymentOptions actualOpt = options.DefaultDeploymentOptions;
System.Reflection.PropertyInfo[] deploymentOptionsProperties = defaultOpt.GetType().GetProperties();
foreach (var v in deploymentOptionsProperties)
{
var defaultP = v.GetValue(defaultOpt);
var actualP = v.GetValue(actualOpt);
if (v.Name == "ExcludeObjectTypes")
{
Assert.True((defaultP as ObjectType[]).Length == (actualP as ObjectType[]).Length, $"Number of excluded objects is different; expected: {(defaultP as ObjectType[]).Length} actual: {(actualP as ObjectType[]).Length}");
}
else
{
Assert.True((defaultP == null && actualP == null) || defaultP.Equals(actualP), $"Actual Property from Service is not equal to default property for { v.Name}, Actual value: {actualP} and Default value: {defaultP}");
}
}
return true;
}
}
}