mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 17:24:00 -05:00
OptionsMapTable preparing from DacFx description,value,displayname at… (#1550)
* OptionsMapTable preparing from DacFx description,value,displayname attributes * Review Comments addressed for options map table changes * OptionsMapTable final changes * Code review comments updated code changes * Test fix: Adding missing change while splitting the PR * DacFx vBump * Reverted to displayName and code updates * final:prop name changed, references updated, tests fixed, comments addressed * Code review comments updated for name,exception etc * updates method names * property name changes to BooleanOptionsDictionary and comment updates * Removed the unused properties, null cases handeled, hardcoded values are replaced
This commit is contained in:
committed by
GitHub
parent
6558f2036d
commit
5663ddba68
@@ -18,6 +18,7 @@ using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using NUnit.Framework;
|
||||
using Moq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.DacFx
|
||||
{
|
||||
@@ -586,11 +587,13 @@ FROM MissingEdgeHubInputStream'";
|
||||
UpgradeExisting = true,
|
||||
DeploymentOptions = new DeploymentOptions()
|
||||
{
|
||||
DropObjectsNotInSource = new DeploymentOptionProperty<bool>(false),
|
||||
ExcludeObjectTypes = new DeploymentOptionProperty<ObjectType[]>(new[] { ObjectType.Views })
|
||||
}
|
||||
};
|
||||
|
||||
// Updating the BooleanOptionsDictionary since it has all the boolean type options
|
||||
deployParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.DropObjectsNotInSource)].Value = false;
|
||||
|
||||
// expect table3 to not have been dropped and view1 to not have been created
|
||||
await VerifyDeployWithOptions(deployParams, targetDb, service, result.ConnectionInfo, expectedTableResult: "table3", expectedViewResult: null);
|
||||
|
||||
@@ -664,11 +667,13 @@ FROM MissingEdgeHubInputStream'";
|
||||
DatabaseName = targetDb.DatabaseName,
|
||||
DeploymentOptions = new DeploymentOptions()
|
||||
{
|
||||
DropObjectsNotInSource = new DeploymentOptionProperty<bool>(false),
|
||||
ExcludeObjectTypes = new DeploymentOptionProperty<ObjectType[]>(new[] { ObjectType.Views })
|
||||
}
|
||||
};
|
||||
|
||||
// Updating the BooleanOptionsDictionary since it has all the boolean type properties
|
||||
generateScriptFalseOptionParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.DropObjectsNotInSource)].Value = false;
|
||||
|
||||
var generateScriptFalseOptionOperation = new GenerateDeployScriptOperation(generateScriptFalseOptionParams, result.ConnectionInfo);
|
||||
service.PerformOperation(generateScriptFalseOptionOperation, TaskExecutionMode.Execute);
|
||||
|
||||
@@ -682,7 +687,6 @@ FROM MissingEdgeHubInputStream'";
|
||||
DatabaseName = targetDb.DatabaseName,
|
||||
DeploymentOptions = new DeploymentOptions()
|
||||
{
|
||||
DropObjectsNotInSource = new DeploymentOptionProperty<bool>(true),
|
||||
ExcludeObjectTypes = new DeploymentOptionProperty<ObjectType[]>( new[] { ObjectType.Views })
|
||||
}
|
||||
};
|
||||
@@ -727,10 +731,10 @@ FROM MissingEdgeHubInputStream'";
|
||||
DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions();
|
||||
|
||||
expectedResults.ExcludeObjectTypes = null;
|
||||
expectedResults.IncludeCompositeObjects = new DeploymentOptionProperty<bool>(true);
|
||||
expectedResults.BlockOnPossibleDataLoss = new DeploymentOptionProperty<bool>(true);
|
||||
expectedResults.AllowIncompatiblePlatform = new DeploymentOptionProperty<bool>(true);
|
||||
expectedResults.DisableIndexesForDataPhase = new DeploymentOptionProperty<bool>(false);
|
||||
expectedResults.BooleanOptionsDictionary[nameof(DacDeployOptions.IncludeCompositeObjects)].Value = true;
|
||||
expectedResults.BooleanOptionsDictionary[nameof(DacDeployOptions.BlockOnPossibleDataLoss)].Value = true;
|
||||
expectedResults.BooleanOptionsDictionary[nameof(DacDeployOptions.AllowIncompatiblePlatform)].Value = true;
|
||||
expectedResults.BooleanOptionsDictionary[nameof(DacDeployOptions.DisableIndexesForDataPhase)].Value = false;
|
||||
|
||||
var dacfxRequestContext = new Mock<RequestContext<DacFxOptionsResult>>();
|
||||
dacfxRequestContext.Setup((RequestContext<DacFxOptionsResult> x) => x.SendResult(It.Is<DacFxOptionsResult>((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object()));
|
||||
@@ -755,7 +759,7 @@ FROM MissingEdgeHubInputStream'";
|
||||
{
|
||||
DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions();
|
||||
expectedResults.ExcludeObjectTypes = null;
|
||||
expectedResults.DisableIndexesForDataPhase = new DeploymentOptionProperty<bool>(false);
|
||||
expectedResults.BooleanOptionsDictionary["DisableIndexesForDataPhase"].Value = false;
|
||||
|
||||
var dacfxRequestContext = new Mock<RequestContext<DacFxOptionsResult>>();
|
||||
dacfxRequestContext.Setup((RequestContext<DacFxOptionsResult> x) => x.SendResult(It.Is<DacFxOptionsResult>((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object()));
|
||||
@@ -842,26 +846,37 @@ Streaming query statement contains a reference to missing output stream 'Missing
|
||||
private bool ValidateOptions(DeploymentOptions expected, DeploymentOptions actual)
|
||||
{
|
||||
System.Reflection.PropertyInfo[] deploymentOptionsProperties = expected.GetType().GetProperties();
|
||||
foreach (var v in deploymentOptionsProperties)
|
||||
var booleanOptionsDictionary = new Dictionary<string, DeploymentOptionProperty<bool>>();
|
||||
foreach (PropertyInfo v in deploymentOptionsProperties)
|
||||
{
|
||||
var defaultP = v.GetValue(expected);
|
||||
var defaultPValue = defaultP != null ? defaultP.GetType().GetProperty("Value").GetValue(defaultP): defaultP;
|
||||
var actualP = v.GetValue(actual);
|
||||
var actualPValue = actualP.GetType().GetProperty("Value").GetValue(actualP);
|
||||
|
||||
if (v.Name == "ExcludeObjectTypes")
|
||||
if (v.Name != nameof(DeploymentOptions.BooleanOptionsDictionary))
|
||||
{
|
||||
Assert.True((defaultP as ObjectType[])?.Length == (actualP as ObjectType[])?.Length, "Number of excluded objects is different not equal");
|
||||
var defaultP = v.GetValue(expected);
|
||||
var defaultPValue = defaultP != null ? defaultP.GetType().GetProperty("Value").GetValue(defaultP) : defaultP;
|
||||
var actualP = v.GetValue(actual);
|
||||
var actualPValue = actualP.GetType().GetProperty("Value").GetValue(actualP);
|
||||
|
||||
if (v.Name == nameof(DeploymentOptions.ExcludeObjectTypes))
|
||||
{
|
||||
Assert.True((defaultP as ObjectType[])?.Length == (actualP as ObjectType[])?.Length, "Number of excluded objects is different not equal");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Verifying expected and actual deployment options properties are equal
|
||||
Assert.True((defaultPValue == null && String.IsNullOrEmpty(actualPValue as string))
|
||||
|| (defaultPValue).Equals(actualPValue)
|
||||
, $"Actual Property from Service is not equal to default property for {v.Name}, Actual value: {actualPValue} and Default value: {defaultPValue}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Verifying expected and actual deployment options properties are equal
|
||||
Assert.True((defaultPValue == null && String.IsNullOrEmpty(actualPValue as string))
|
||||
|| (defaultPValue).Equals(actualPValue)
|
||||
, $"Actual Property from Service is not equal to default property for {v.Name}, Actual value: {actualPValue} and Default value: {defaultPValue}");
|
||||
booleanOptionsDictionary = v.GetValue(expected) as Dictionary<string, DeploymentOptionProperty<bool>>;
|
||||
}
|
||||
}
|
||||
|
||||
// Verify expected and actual DeploymentOptions BooleanOptionsDictionary
|
||||
VerifyExpectedAndActualBooleanOptionsDictionary(booleanOptionsDictionary, actual.BooleanOptionsDictionary);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -895,5 +910,21 @@ Streaming query statement contains a reference to missing output stream 'Missing
|
||||
File.Delete(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify expected and actual DeploymentOptions BooleanOptionsDictionary values
|
||||
/// </summary>
|
||||
/// <param name="expectedBooleanOptionsDictionary"></param>
|
||||
/// <param name="actualBooleanOptionsDictionary"></param>
|
||||
public void VerifyExpectedAndActualBooleanOptionsDictionary(Dictionary<string, DeploymentOptionProperty<bool>> expectedBooleanOptionsDictionary, Dictionary<string, DeploymentOptionProperty<bool>> actualBooleanOptionsDictionary)
|
||||
{
|
||||
foreach (KeyValuePair<string, DeploymentOptionProperty<bool>> optionRow in expectedBooleanOptionsDictionary)
|
||||
{
|
||||
var expectedValue = optionRow.Value.Value;
|
||||
var actualValue = actualBooleanOptionsDictionary[optionRow.Key].Value;
|
||||
|
||||
Assert.That(actualValue, Is.EqualTo(expectedValue), $"Actual Property from Service is not equal to default property for {optionRow.Key}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ END
|
||||
private DeploymentOptions GetIgnoreColumnOptions()
|
||||
{
|
||||
var options = new DeploymentOptions();
|
||||
options.IgnoreColumnOrder = new DeploymentOptionProperty<bool>(true);
|
||||
options.BooleanOptionsDictionary[nameof(DacDeployOptions.IgnoreColumnOrder)].Value = true;
|
||||
return options;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlServer.Dac;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SchemaCompare
|
||||
{
|
||||
@@ -1823,22 +1824,21 @@ WITH VALUES
|
||||
{
|
||||
SourceEndpointInfo = sourceInfo,
|
||||
TargetEndpointInfo = targetInfo,
|
||||
DeploymentOptions = new DeploymentOptions()
|
||||
{
|
||||
// change some random ones explicitly
|
||||
AllowDropBlockingAssemblies = new DeploymentOptionProperty<bool>(true),
|
||||
DropConstraintsNotInSource = new DeploymentOptionProperty<bool>(true),
|
||||
IgnoreAnsiNulls = new DeploymentOptionProperty<bool>(true),
|
||||
NoAlterStatementsToChangeClrTypes = new DeploymentOptionProperty<bool>(false),
|
||||
PopulateFilesOnFileGroups = new DeploymentOptionProperty<bool>(false),
|
||||
VerifyDeployment = new DeploymentOptionProperty<bool>(false),
|
||||
DisableIndexesForDataPhase = new DeploymentOptionProperty<bool>(false)
|
||||
},
|
||||
DeploymentOptions = new DeploymentOptions(),
|
||||
ScmpFilePath = filePath,
|
||||
ExcludedSourceObjects = schemaCompareObjectIds,
|
||||
ExcludedTargetObjects = null,
|
||||
};
|
||||
|
||||
// change some random ones explicitly
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.AllowDropBlockingAssemblies)].Value = true;
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.DropConstraintsNotInSource)].Value = true;
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.IgnoreAnsiNulls)].Value = true;
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.NoAlterStatementsToChangeClrTypes)].Value = false;
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.PopulateFilesOnFileGroups)].Value = false;
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.VerifyDeployment)].Value = false;
|
||||
schemaCompareParams.DeploymentOptions.BooleanOptionsDictionary[nameof(DacDeployOptions.DisableIndexesForDataPhase)].Value = false;
|
||||
|
||||
SchemaCompareSaveScmpOperation schemaCompareOperation = new SchemaCompareSaveScmpOperation(schemaCompareParams, result.ConnectionInfo, result.ConnectionInfo);
|
||||
schemaCompareOperation.Execute(TaskExecutionMode.Execute);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using Microsoft.SqlServer.Dac;
|
||||
using Microsoft.SqlTools.ServiceLayer.DacFx;
|
||||
using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.DacFx;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
|
||||
@@ -14,6 +15,8 @@ using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SchemaCompare
|
||||
{
|
||||
@@ -129,25 +132,29 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SchemaCompare
|
||||
// TODO: update with new options. Tracking issue: https://github.com/microsoft/azuredatastudio/issues/15336
|
||||
//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)
|
||||
foreach (PropertyInfo 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 changedDacValue = deployOptionsValue != null ? deployOptionsValue.GetType().GetProperty("Value").GetValue(deployOptionsValue) : deployOptionsValue;
|
||||
var dafaultDacValue = dacProp.GetValue(dacDeployOptions);
|
||||
|
||||
if (deployOptionsProp.Name != "ExcludeObjectTypes") // do not compare for ExcludeObjectTypes because it will be different
|
||||
if (deployOptionsProp.Name != nameof(DeploymentOptions.BooleanOptionsDictionary))
|
||||
{
|
||||
Assert.True((deployOptionsValue == null && dafaultDacValue == null)
|
||||
|| deployOptionsValue.Equals(dafaultDacValue)
|
||||
|| changedDacValue == null && (dafaultDacValue as string) == string.Empty
|
||||
|| changedDacValue == null && dafaultDacValue == null
|
||||
|| (changedDacValue).Equals(dafaultDacValue)
|
||||
, $"DacFx DacDeploy property not equal to Tools Service DeploymentOptions for { deployOptionsProp.Name}, SchemaCompareOptions value: {changedDacValue} and DacDeployOptions value: {dafaultDacValue} ");
|
||||
var dacProp = dacDeployOptions.GetType().GetProperty(deployOptionsProp.Name);
|
||||
Assert.That(dacProp, Is.Not.Null, $"DacDeploy property not present for {deployOptionsProp.Name}");
|
||||
|
||||
var defaultP = deployOptionsProp.GetValue(deploymentOptions);
|
||||
var defaultPValue = defaultP != null ? defaultP.GetType().GetProperty("Value").GetValue(defaultP) : defaultP;
|
||||
var actualPValue = dacProp.GetValue(dacDeployOptions);
|
||||
|
||||
if (deployOptionsProp.Name != nameof(DeploymentOptions.ExcludeObjectTypes)) // do not compare for ExcludeObjectTypes because it will be different
|
||||
{
|
||||
// Verifying expected and actual deployment options properties are equal
|
||||
Assert.True((defaultPValue == null && String.IsNullOrEmpty(actualPValue as string))
|
||||
|| (defaultPValue).Equals(actualPValue)
|
||||
, $"DacFx DacDeploy property not equal to Tools Service DeploymentOptions for {deployOptionsProp.Name}, Actual value: {actualPValue} and Default value: {defaultPValue}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the booleanOptionsDictionary with the DacDeployOptions property values
|
||||
VerifyBooleanOptionsDictionary(deploymentOptions.BooleanOptionsDictionary, dacDeployOptions);
|
||||
}
|
||||
|
||||
internal static bool ValidateOptionsEqualsDefault(SchemaCompareOptionsResult options)
|
||||
@@ -156,26 +163,52 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.SchemaCompare
|
||||
DeploymentOptions actualOpt = options.DefaultDeploymentOptions;
|
||||
|
||||
System.Reflection.PropertyInfo[] deploymentOptionsProperties = defaultOpt.GetType().GetProperties();
|
||||
foreach (var v in deploymentOptionsProperties)
|
||||
foreach (PropertyInfo v in deploymentOptionsProperties)
|
||||
{
|
||||
var defaultP = v.GetValue(defaultOpt);
|
||||
var defaultPValue = defaultP != null ? defaultP.GetType().GetProperty("Value").GetValue(defaultP) : defaultP;
|
||||
var actualP = v.GetValue(actualOpt);
|
||||
var actualPValue = actualP.GetType().GetProperty("Value").GetValue(actualP);
|
||||
if (v.Name != nameof(DeploymentOptions.BooleanOptionsDictionary))
|
||||
{
|
||||
var defaultP = v.GetValue(defaultOpt);
|
||||
var defaultPValue = defaultP != null ? defaultP.GetType().GetProperty("Value").GetValue(defaultP) : defaultP;
|
||||
var actualP = v.GetValue(actualOpt);
|
||||
var actualPValue = actualP.GetType().GetProperty("Value").GetValue(actualP);
|
||||
|
||||
if (v.Name == "ExcludeObjectTypes")
|
||||
{
|
||||
Assert.True((defaultPValue as ObjectType[]).Length == (actualPValue as ObjectType[]).Length, $"Number of excluded objects is different; expected: {(defaultPValue as ObjectType[]).Length} actual: {(actualPValue as ObjectType[]).Length}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verifying expected and actual deployment options properties are equal
|
||||
Assert.True((defaultPValue == null && String.IsNullOrEmpty(actualPValue as string))
|
||||
|| (defaultPValue).Equals(actualPValue)
|
||||
, $"Actual Property from Service is not equal to default property for {v.Name}, Actual value: {actualPValue} and Default value: {defaultPValue}");
|
||||
if (v.Name == nameof(DeploymentOptions.ExcludeObjectTypes))
|
||||
{
|
||||
Assert.That((defaultPValue as ObjectType[]).Length, Is.EqualTo((actualPValue as ObjectType[]).Length), $"Number of excluded objects is different; expected: {(defaultPValue as ObjectType[]).Length} actual: {(actualPValue as ObjectType[]).Length}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verifying expected and actual deployment options properties are equal
|
||||
Assert.True((defaultPValue == null && String.IsNullOrEmpty(actualPValue as string))
|
||||
|| (defaultPValue).Equals(actualPValue)
|
||||
, $"Actual Property from Service is not equal to default property for {v.Name}, Actual value: {actualPValue} and Default value: {defaultPValue}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify the default booleanOptionsDictionary with the SchemaCompareOptionsResult options property values
|
||||
DacFxServiceTests dacFxServiceTests = new DacFxServiceTests();
|
||||
dacFxServiceTests.VerifyExpectedAndActualBooleanOptionsDictionary(defaultOpt.BooleanOptionsDictionary, options.DefaultDeploymentOptions.BooleanOptionsDictionary);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the DeploymentOptions booleanOptionsDictionary with the DacDeployOptions
|
||||
/// </summary>
|
||||
/// <param name="expectedBooleanOptionsDictionary"></param>
|
||||
/// <param name="dacDeployOptions"></param>
|
||||
private static void VerifyBooleanOptionsDictionary(Dictionary<string, DeploymentOptionProperty<bool>> expectedBooleanOptionsDictionary, DacDeployOptions dacDeployOptions)
|
||||
{
|
||||
foreach (KeyValuePair<string, DeploymentOptionProperty<bool>> optionRow in expectedBooleanOptionsDictionary)
|
||||
{
|
||||
var dacProp = dacDeployOptions.GetType().GetProperty(optionRow.Key);
|
||||
Assert.That(dacProp, Is.Not.Null, $"DacDeploy property not present for {optionRow.Key}");
|
||||
var actualValue = dacProp.GetValue(dacDeployOptions);
|
||||
var expectedValue = optionRow.Value.Value;
|
||||
|
||||
Assert.That(actualValue, Is.EqualTo(expectedValue), $"Actual Property from Service is not equal to default property for {optionRow.Key}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user