private static DeploymentStepDecision RemoveDropStep(DeploymentStep step, KeeperDecider decider) { var dropStep = step as DropElementStep; return(dropStep == null ? null : new DeploymentStepDecision() { Remove = decider.ShouldRemoveFromPlan(dropStep.TargetElement?.Name ?? new ObjectIdentifier(), dropStep.TargetElement?.ObjectType, StepType.Drop), StepType = StepType.Drop, ObjectName = dropStep.TargetElement?.Name?.ToString() ?? "" }); }
public void Create_Step_Does_Not_Call_Keep_Rule() { var keepRule = new Mock <FilterRule>(); keepRule.Setup(p => p.Operation()).Returns(FilterOperation.Keep); keepRule.Setup(p => p.Matches(It.IsAny <ObjectIdentifier>(), It.IsAny <ModelTypeClass>(), It.IsAny <DeploymentStep>())).Callback(() => Assert.Fail("Rule should not have been called")); var decider = new KeeperDecider(new List <FilterRule>() { keepRule.Object }); decider.ShouldRemoveFromPlan(new ObjectIdentifier("aa"), ModelSchema.Aggregate, StepType.Create); }
public void Alter_Step_Does_Call_Ignore_Rule() { var ignoreRule = new Mock <FilterRule>(); ignoreRule.Setup(p => p.Operation()).Returns(FilterOperation.Ignore); ignoreRule.Setup(p => p.Matches(It.IsAny <ObjectIdentifier>(), It.IsAny <ModelTypeClass>(), null)).Returns(true); var decider = new KeeperDecider(new List <FilterRule>() { ignoreRule.Object }); var result = decider.ShouldRemoveFromPlan(new ObjectIdentifier("aa"), ModelSchema.Aggregate, StepType.Alter); Assert.IsTrue(result); }
public void Drop_Step_Does_Call_Keep_Rule() { var keepRule = new Mock <FilterRule>(); keepRule.Setup(p => p.Operation()).Returns(FilterOperation.Keep); keepRule.Setup(p => p.Matches(It.IsAny <ObjectIdentifier>(), It.IsAny <ModelTypeClass>(), It.IsAny <DeploymentStep>())).Returns(true); var decider = new KeeperDecider(new List <FilterRule>() { keepRule.Object }); var result = decider.ShouldRemoveFromPlan(new ObjectIdentifier("aa"), ModelSchema.Aggregate, StepType.Drop); Assert.IsTrue(result); }
private static DeploymentStepDecision RemoveDropStep(DeploymentStep step, KeeperDecider decider) { var dropStep = step as DropElementStep; if (dropStep == null) { return(null); } var objectNames = GetAllIdentifiersFromStep(step); return(new DeploymentStepDecision() { Remove = decider.ShouldRemoveFromPlan(new ObjectIdentifier(objectNames), dropStep.TargetElement?.ObjectType, StepType.Drop), StepType = StepType.Drop, ObjectNames = objectNames }); }
protected override void OnExecute(DeploymentPlanContributorContext context) { try { PublishMessage(new ExtensibilityError("Starting AgileSqlClub.DeploymentFilterContributor", Severity.Message)); var rules = new RuleDefinitionFactory(this).BuildRules(context.Arguments, this); var decider = new KeeperDecider(rules); var next = context.PlanHandle.Head; while (next != null) { var current = next; next = current.Next; var stepDecider = DeploymentStepDecider.Decide(current, decider); if (stepDecider != null) { if (stepDecider.Remove) { Remove(context.PlanHandle, current); PublishMessage(new ExtensibilityError($"Step removed from deployment by SqlPackageFilter, object: {String.Join(", ", stepDecider.ObjectNames)}, step type: {stepDecider.StepType}", Severity.Message)); } else if (_displayLevel == DisplayMessageLevel.Info) { PublishMessage(new ExtensibilityError($"Step has not been removed from deployment, object: {String.Join(", ", stepDecider.ObjectNames)}, step type: {stepDecider.StepType}", Severity.Message)); } } } PublishMessage(new ExtensibilityError("Completed AgileSqlClub.DeploymentFilterContributor", Severity.Message)); } catch (Exception e) { //global exception as we don't want to break sqlpackage.exe PublishMessage(new ExtensibilityError($"Error in DeploymentFilter: {e.Message}\r\nStack: {e.StackTrace}", Severity.Error)); } }
public void All_Rules_Ignored_For_Other_Steps() { var ignoreRule = new Mock <FilterRule>(); ignoreRule.Setup(p => p.Operation()).Returns(FilterOperation.Ignore); ignoreRule.Setup(p => p.Matches(It.IsAny <ObjectIdentifier>(), It.IsAny <ModelTypeClass>(), null)).Callback(() => Assert.Fail("Ignore Rule should not have been called"));; var keepRule = new Mock <FilterRule>(); keepRule.Setup(p => p.Operation()).Returns(FilterOperation.Keep); keepRule.Setup(p => p.Matches(It.IsAny <ObjectIdentifier>(), It.IsAny <ModelTypeClass>(), null)).Callback(() => Assert.Fail("Keep Rule should not have been called")); var decider = new KeeperDecider(new List <FilterRule>() { ignoreRule.Object, keepRule.Object }); var result = decider.ShouldRemoveFromPlan(new ObjectIdentifier("aa"), ModelSchema.Aggregate, StepType.Other); Assert.IsFalse(result); }
public static DeploymentStepDecision Decide(DeploymentStep step, KeeperDecider decider) { return(RemoveCreateElement(step, decider) ?? RemoveDropStep(step, decider) ?? RemoveAlterStep(step, decider) ?? RemoveDataLossCheckStep(step, decider)); }
private static DeploymentStepDecision RemoveCreateElement(DeploymentStep step, KeeperDecider decider) { var createStep = step as CreateElementStep; return(createStep == null ? null : new DeploymentStepDecision() { Remove = decider.ShouldRemoveFromPlan(createStep.SourceElement?.Name ?? new ObjectIdentifier(), createStep.SourceElement?.ObjectType, StepType.Create), StepType = StepType.Create, ObjectName = createStep.SourceElement?.Name?.ToString() ?? "" }); }
private static DeploymentStepDecision RemoveDataLossCheckStep(DeploymentStep step, KeeperDecider decider) { var dlcStep = new DataLossCheckStep(step); return(!dlcStep.IsDataLossCheck ? null : new DeploymentStepDecision() { Remove = decider.ShouldRemoveFromPlan(dlcStep.ObjectName, ModelSchema.Table, StepType.Drop), StepType = StepType.DataLossCheck, ObjectName = dlcStep.ObjectName.ToString() }); }
private static DeploymentStepDecision RemoveCreateElement(DeploymentStep step, KeeperDecider decider) { var createStep = step as CreateElementStep; if (createStep == null) { return(null); } var objectNames = GetAllIdentifiersFromStep(step); return(new DeploymentStepDecision() { Remove = decider.ShouldRemoveFromPlan(new ObjectIdentifier(objectNames), createStep.SourceElement?.ObjectType, StepType.Create), StepType = StepType.Create, ObjectNames = objectNames }); }
private static DeploymentStepDecision RemoveDataLossCheckStep(DeploymentStep step, KeeperDecider decider) { var dlcStep = new DataLossCheckStep(step); if (dlcStep == null || !dlcStep.IsDataLossCheck) { return(null); } var objectNames = GetAllIdentifiersFromStep(step); return(new DeploymentStepDecision() { Remove = decider.ShouldRemoveFromPlan(new ObjectIdentifier(objectNames), ModelSchema.Table, StepType.Drop), StepType = StepType.DataLossCheck, ObjectNames = objectNames }); }