public void TestRemoveChildThatDoesNotExistFails() { rootNode = rootNode.AsSubdivision(); Assert.Throws <ArgumentException>(delegate() { rootNode.RemoveChild(ProductDimensions.CreateBrand("google")); }); }
public void TestNavigation() { rootNode = rootNode.AsSubdivision(); ProductBrand brandGoogle = ProductDimensions.CreateBrand("google"); ProductBrand brandOther = ProductDimensions.CreateBrand(null); ProductCanonicalCondition conditionNew = ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.NEW); ProductCanonicalCondition conditionUsed = ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.USED); ProductCanonicalCondition conditionOther = ProductDimensions.CreateCanonicalCondition(); // Build up the brand = Google node under the root. ProductPartitionNode brandGoogleNode = rootNode.AddChild(brandGoogle).AsSubdivision(); brandGoogleNode.AddChild(conditionNew); brandGoogleNode.AddChild(conditionUsed); brandGoogleNode.AddChild(conditionOther); Assert.True(brandGoogleNode.HasChild(conditionNew), "HasChild should return true for existing child dimension."); Assert.AreSame(brandGoogleNode, brandGoogleNode.GetChild(conditionNew).Parent, "parent->GetChild->getParent should return parent."); Assert.True(brandGoogleNode.HasChild(conditionUsed), "HasChild should return true for existing child dimension."); Assert.AreSame(brandGoogleNode, brandGoogleNode.GetChild(conditionUsed).Parent, "parent->GetChild->getParent should return parent."); Assert.True(brandGoogleNode.HasChild(conditionOther), "HasChild should return true for existing child dimension."); Assert.AreSame(brandGoogleNode, brandGoogleNode.GetChild(conditionOther).Parent, "parent->GetChild->getParent should return parent."); // Build up the brand = null (other) node under the root. ProductPartitionNode brandOtherNode = rootNode.AddChild(brandOther).AsSubdivision(); brandOtherNode.AddChild(conditionNew); Assert.True(brandOtherNode.HasChild(conditionNew), "HasChild should return true for existing child dimension."); Assert.AreSame(brandOtherNode, brandOtherNode.GetChild(conditionNew).Parent, "parent->GetChild->getParent should return parent."); Assert.False(brandOtherNode.HasChild(conditionUsed), "HasChild should return false for nonexistent child dimension."); Assert.False(brandOtherNode.HasChild(conditionOther), "HasChild should return false for nonexistent child dimension."); brandOtherNode.AddChild(conditionOther); Assert.True(brandOtherNode.HasChild(conditionOther), "HasChild should return true for existing child dimension."); Assert.AreSame(brandOtherNode, brandOtherNode.GetChild(conditionOther).Parent, "parent->GetChild->getParent should return parent."); // Remove one of the children of brand = null. brandOtherNode.RemoveChild(conditionOther); Assert.False(brandOtherNode.HasChild(conditionOther), "HasChild should return false for a removed child dimension."); // Remove the rest of the children of brand = null. brandOtherNode.RemoveAllChildren(); Assert.False(brandOtherNode.HasChild(conditionNew), "HasChild should return false for any removed child dimension."); Assert.False(brandOtherNode.HasChild(conditionUsed), "HasChild should return false for any removed child dimension."); }
public void TestCreateUltimatelyEmptyTree() { ProductPartitionTree tree = ProductPartitionTree.CreateAdGroupTree(new List <AdGroupCriterion>()); ProductPartitionNode rootNode = tree.Root.AsSubdivision(); ProductPartitionNode brand1 = rootNode.AddChild(ProductDimensions.CreateBrand("google")) .AsSubdivision(); ProductPartitionNode offerNode = brand1.AddChild(ProductDimensions.CreateOfferId("A")); offerNode.AsBiddableUnit().CpcBid = 1000000L; brand1.AddChild(ProductDimensions.CreateOfferId()).AsExcludedUnit(); ProductPartitionNode brand2 = rootNode.AddChild(ProductDimensions.CreateBrand()).AsExcludedUnit(); // Now remove the two child nodes under the root and set the root back // to a UNIT. This should result in operations that simply create the // root node. rootNode.RemoveChild(brand1.Dimension); rootNode.RemoveChild(brand2.Dimension); rootNode = rootNode.AsBiddableUnit(); AdGroupCriterionOperation[] mutateOperations = tree.GetMutateOperations(); Assert.AreEqual(mutateOperations.Count(), 1, "Number of operations is incorrect."); AdGroupCriterionOperation operation = mutateOperations[0]; Assert.AreEqual(Operator.ADD, operation.@operator, "Should have a single operation to ADD the root node."); BiddableAdGroupCriterion adGroupCriterion = (BiddableAdGroupCriterion)operation.operand; Assert.Null(((ProductPartition)adGroupCriterion.criterion).caseValue, "Product dimension of operation's operand should be null."); Assert.True(adGroupCriterion.criterion.id < 0L, "Partition ID of the operand should be negative."); }
public void TestRemoveChildThatDoesNotExistFails() { rootNode = rootNode.AsSubdivision(); Assert.Throws<ArgumentException>(delegate() { rootNode.RemoveChild(ProductDimensions.CreateBrand("google")); }); }