public void TestProductOfferIdGetHashcode() { ProductOfferId productOfferIdA = new ProductOfferId() { value = "google" }; ProductOfferId productOfferIdATitleCase = new ProductOfferId() { value = "Google" }; ProductOfferId productOfferIdB = new ProductOfferId() { value = "google" }; ProductOfferId productOfferIdC = new ProductOfferId() { value = "motorola" }; Assert.AreEqual(comparer.GetHashCode(productOfferIdA), comparer.GetHashCode(productOfferIdA)); Assert.AreNotEqual(comparer.GetHashCode(productOfferIdA), comparer.GetHashCode(productOfferIdC)); // Case of value is ignored. Assert.AreEqual(comparer.GetHashCode(productOfferIdA), comparer.GetHashCode(productOfferIdATitleCase)); }
public void TestProductOfferIdEquals() { ProductOfferId productOfferIdA = new ProductOfferId() { value = "google" }; ProductOfferId productOfferIdATitleCase = new ProductOfferId() { value = "Google" }; ProductOfferId productOfferIdB = new ProductOfferId() { value = "google" }; ProductOfferId productOfferIdC = new ProductOfferId() { value = "motorola" }; ProductOfferId productOfferIdD = new ProductOfferId(); ProductOfferId productOfferIdE = new ProductOfferId(); Assert.True(comparer.Equals(productOfferIdA, productOfferIdB)); Assert.False(comparer.Equals(productOfferIdA, productOfferIdC)); // Case of value is ignored. Assert.True(comparer.Equals(productOfferIdA, productOfferIdATitleCase)); //Null value is handled gracefully. Assert.False(comparer.Equals(productOfferIdA, productOfferIdD)); Assert.True(comparer.Equals(productOfferIdD, productOfferIdE)); }
/// <summary> /// Gets the hash code for a <see cref="ProductOfferId"/>. /// </summary> /// <param name="obj">The object to calculate hash code for.</param> /// <returns>The hash code.</returns> private int GetHashCodeInternal(ProductOfferId obj) { if (obj.value == null) { return(obj.GetType().Name.GetHashCode()); } else { return(obj.value.ToLower().GetHashCode()); } }
public void TestCreateOfferId() { ProductOfferId productOfferIdA = new ProductOfferId() { value = "google" }; ProductOfferId productOfferIdB = ProductDimensions.CreateOfferId("google"); Assert.True(comparer.Equals(productOfferIdA, productOfferIdB)); ProductOfferId productOfferIdC = new ProductOfferId() { }; ProductOfferId productOfferIdD = ProductDimensions.CreateOfferId(); Assert.True(comparer.Equals(productOfferIdC, productOfferIdD)); }
/// <summary> /// Subdivides the new shoes. /// </summary> /// Takes a tree with: /// <pre> /// ROOT /// ... /// shoes /// new some bid /// </pre> /// /// and changes it to: /// /// <pre> /// ROOT /// ... /// shoes /// new /// other offerId $1.00 /// offerId=2 $2.00 /// ... /// offerId=20 $20.00 /// </pre> private void SubdivideNewShoes() { ProductPartitionNode shoesLevel1 = tree.Root.GetChild(ProductDimensions.CreateType( ProductDimensionType.PRODUCT_TYPE_L1, "shoes")).AsSubdivision(); ProductPartitionNode newShoesLevel2 = shoesLevel1.GetChild( ProductDimensions.CreateCanonicalCondition(ProductCanonicalConditionCondition.NEW)) .AsSubdivision(); for (int i = 1; i <= 20; i++) { ProductOfferId offerId = ProductDimensions.CreateOfferId(); if (i > 1) { offerId.value = i.ToString(); } newShoesLevel2.AddChild(offerId).AsBiddableUnit().CpcBid = i * 1000000L; } Assert.DoesNotThrow(delegate() { tree = ExecuteTreeOperations(); }); }
/// <summary> /// Determines whether the specified <see cref="ProductOfferId"/> objects /// are equal. /// </summary> /// <param name="x">The first object to compare.</param> /// <param name="y">The second object to compare.</param> /// <returns> /// True if the specified objects are equal; otherwise, false. /// </returns> private bool Equals(ProductOfferId x, ProductOfferId y) { return(AreValuesEqual(x.value, y.value)); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign id to add product scope.</param> public void Run(AdWordsUser user, long campaignId) { // Get the CampaignCriterionService. CampaignCriterionService campaignCriterionService = (CampaignCriterionService)user.GetService( AdWordsService.v201609.CampaignCriterionService); ProductScope productScope = new ProductScope(); // This set of dimensions is for demonstration purposes only. It would be // extremely unlikely that you want to include so many dimensions in your // product scope. ProductBrand nexusBrand = new ProductBrand(); nexusBrand.value = "Nexus"; ProductCanonicalCondition newProducts = new ProductCanonicalCondition(); newProducts.condition = ProductCanonicalConditionCondition.NEW; ProductCustomAttribute customAttribute = new ProductCustomAttribute(); customAttribute.type = ProductDimensionType.CUSTOM_ATTRIBUTE_0; customAttribute.value = "my attribute value"; ProductOfferId bookOffer = new ProductOfferId(); bookOffer.value = "book1"; ProductType mediaProducts = new ProductType(); mediaProducts.type = ProductDimensionType.PRODUCT_TYPE_L1; mediaProducts.value = "Media"; ProductType bookProducts = new ProductType(); bookProducts.type = ProductDimensionType.PRODUCT_TYPE_L2; bookProducts.value = "Books"; // The value for the bidding category is a fixed ID for the // 'Luggage & Bags' category. You can retrieve IDs for categories from // the ConstantDataService. See the 'GetProductCategoryTaxonomy' example // for more details. ProductBiddingCategory luggageBiddingCategory = new ProductBiddingCategory(); luggageBiddingCategory.type = ProductDimensionType.BIDDING_CATEGORY_L1; luggageBiddingCategory.value = -5914235892932915235; productScope.dimensions = new ProductDimension[] { nexusBrand, newProducts, bookOffer, mediaProducts, luggageBiddingCategory }; CampaignCriterion campaignCriterion = new CampaignCriterion(); campaignCriterion.campaignId = campaignId; campaignCriterion.criterion = productScope; // Create operation. CampaignCriterionOperation operation = new CampaignCriterionOperation(); operation.operand = campaignCriterion; operation.@operator = Operator.ADD; try { // Make the mutate request. CampaignCriterionReturnValue result = campaignCriterionService.mutate( new CampaignCriterionOperation[] { operation }); Console.WriteLine("Created a ProductScope criterion with ID '{0}'", result.value[0].criterion.id); } catch (Exception e) { throw new System.ApplicationException("Failed to set shopping product scope.", e); } }