예제 #1
0
        /// <summary>
        /// Creates a test expanded text ad for running further tests.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">The adgroup id for which the ad is created.
        /// </param>
        /// <param name="hasAdParam">True, if an ad param placeholder should be
        /// added.</param>
        /// <returns>The expanded text ad id.</returns>
        public long CreateExpandedTextAd(AdWordsUser user, long adGroupId, bool hasAdParam)
        {
            AdGroupAdService adGroupAdService =
                (AdGroupAdService)user.GetService(AdWordsService.v201705.AdGroupAdService);
            AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();

            adGroupAdOperation.@operator         = Operator.ADD;
            adGroupAdOperation.operand           = new AdGroupAd();
            adGroupAdOperation.operand.adGroupId = adGroupId;

            ExpandedTextAd expandedTextAd = new ExpandedTextAd();

            expandedTextAd.headlinePart1 = "Luxury Cruise to Mars";
            expandedTextAd.headlinePart2 = "Best Space Cruise Line";
            expandedTextAd.description   = "Buy your tickets now!";
            if (hasAdParam)
            {
                expandedTextAd.description = "Low-gravity fun for {param1:cheap}!";
            }
            else
            {
                expandedTextAd.description = "Low-gravity fun for everyone!";
            }
            expandedTextAd.finalUrls = new string[] { "http://www.example.com/" };

            adGroupAdOperation.operand.ad = expandedTextAd;

            AdGroupAdReturnValue retVal =
                adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation });

            return(retVal.value[0].ad.id);
        }
예제 #2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group to which ads are added.
        /// </param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            using (AdGroupAdService adGroupAdService =
                       (AdGroupAdService)user.GetService(AdWordsService.v201802.AdGroupAdService)) {
                List <AdGroupAdOperation> operations = new List <AdGroupAdOperation>();

                for (int i = 0; i < NUMBER_OF_ADS; i++)
                {
                    // Create the expanded text ad.
                    ExpandedTextAd expandedTextAd = new ExpandedTextAd {
                        headlinePart1 = "Cruise #" + i.ToString() + " to Mars",
                        headlinePart2 = "Best Space Cruise Line",
                        description   = "Buy your tickets now!",
                        finalUrls     = new string[] { "http://www.example.com/" + i }
                    };

                    AdGroupAd expandedTextAdGroupAd = new AdGroupAd {
                        adGroupId = adGroupId,
                        ad        = expandedTextAd,

                        // Optional: Set the status.
                        status = AdGroupAdStatus.PAUSED
                    };

                    // Create the operation.
                    AdGroupAdOperation operation = new AdGroupAdOperation {
                        @operator = Operator.ADD,
                        operand   = expandedTextAdGroupAd
                    };

                    operations.Add(operation);
                }

                AdGroupAdReturnValue retVal = null;

                try {
                    // Create the ads.
                    retVal = adGroupAdService.mutate(operations.ToArray());

                    // Display the results.
                    if (retVal != null && retVal.value != null)
                    {
                        foreach (AdGroupAd adGroupAd in retVal.value)
                        {
                            ExpandedTextAd newAd = adGroupAd.ad as ExpandedTextAd;
                            Console.WriteLine("Expanded text ad with ID '{0}' and headline '{1} - {2}' " +
                                              "was added.", newAd.id, newAd.headlinePart1, newAd.headlinePart2);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No expanded text ads were created.");
                    }
                    adGroupAdService.Close();
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to create expanded text ad.", e);
                }
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adId">Id of the ad to be updated.</param>
        public void Run(AdWordsUser user, long adId)
        {
            using (AdService adService =
                       (AdService)user.GetService(AdWordsService.v201806.AdService))
            {
                // Create an expanded text ad using the provided ad ID.
                ExpandedTextAd expandedTextAd = new ExpandedTextAd
                {
                    id = adId,

                    // Update some properties of the expanded text ad.
                    headlinePart1 = "Cruise to Pluto #" + ExampleUtilities.GetShortRandomString(),
                    headlinePart2 = "Tickets on sale now",
                    description   = "Best space cruise ever.",
                    finalUrls     = new string[]
                    {
                        "http://www.example.com/"
                    },
                    finalMobileUrls = new string[]
                    {
                        "http://www.example.com/mobile"
                    }
                };

                // Create ad group ad operation and add it to the list.
                AdOperation operation = new AdOperation
                {
                    operand   = expandedTextAd,
                    @operator = Operator.SET
                };

                try
                {
                    // Update the ad on the server.
                    AdReturnValue result = adService.mutate(new AdOperation[]
                    {
                        operation
                    });
                    ExpandedTextAd updatedAd = (ExpandedTextAd)result.value[0];

                    // Print out some information.
                    Console.WriteLine("Expanded text ad with ID {0} was updated.", updatedAd.id);
                    Console.WriteLine(
                        "Headline part 1: {0}\nHeadline part 2: {1}\nDescription: {2}" +
                        "\nFinal URL: {3}\nFinal mobile URL: {4}", updatedAd.headlinePart1,
                        updatedAd.headlinePart2, updatedAd.description, updatedAd.finalUrls[0],
                        updatedAd.finalMobileUrls[0]);
                }
                catch (Exception e)
                {
                    throw new System.ApplicationException("Failed to update expanded text ad.", e);
                }
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group to which text ads are
        /// added.</param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupAdService.
            AdGroupAdService adGroupAdService =
                (AdGroupAdService)user.GetService(AdWordsService.v201609.AdGroupAdService);

            // Set the validateOnly headers.
            adGroupAdService.RequestHeader.validateOnly = true;

            // Create your expanded text ad.
            ExpandedTextAd expandedTextAd = new ExpandedTextAd()
            {
                headlinePart1 = "Luxury Cruise to Mars",
                headlinePart2 = "Visit the Red Planet in style.",
                description   = "Low-gravity fun for everyone!!",
                finalUrls     = new string[] { "http://www.example.com" }
            };

            AdGroupAd adGroupAd = new AdGroupAd()
            {
                adGroupId = adGroupId,
                ad        = expandedTextAd
            };

            AdGroupAdOperation operation = new AdGroupAdOperation()
            {
                @operator = Operator.ADD,
                operand   = adGroupAd
            };

            try {
                AdGroupAdReturnValue retVal = adGroupAdService.mutate(
                    (new AdGroupAdOperation[] { operation }));
                // Since validation is ON, result will be null.
                Console.WriteLine("Expanded text ad validated successfully.");
            } catch (AdWordsApiException e) {
                // This block will be hit if there is a validation error from the server.
                Console.WriteLine("There were validation error(s) while adding expanded text ad.");

                if (e.ApiException != null)
                {
                    foreach (ApiError error in ((ApiException)e.ApiException).errors)
                    {
                        Console.WriteLine("  Error type is '{0}' and fieldPath is '{1}'.",
                                          error.ApiErrorType, error.fieldPath);
                    }
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to validate expanded text ad.", e);
            }
        }
예제 #5
0
        /// <summary>
        /// Creates text ads that use ad customizations for the specified ad group
        /// IDs.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupIds">IDs of the ad groups to which customized ads
        /// are added.</param>
        /// <param name="feedName">Name of the feed to be used.</param>
        private static void CreateAdsWithCustomizations(AdWordsUser user, long[] adGroupIds,
                                                        string feedName)
        {
            using (AdGroupAdService adGroupAdService =
                       (AdGroupAdService)user.GetService(AdWordsService.v201809.AdGroupAdService))
            {
                ExpandedTextAd expandedTextAd = new ExpandedTextAd()
                {
                    headlinePart1 = string.Format("Luxury Cruise to {{={0}.Name}}", feedName),
                    headlinePart2 = string.Format("Only {{={0}.Price}}", feedName),
                    description   =
                        string.Format("Offer ends in {{=countdown({0}.Date)}}!", feedName),
                    finalUrls = new string[]
                    {
                        "http://www.example.com"
                    }
                };

                // We add the same ad to both ad groups. When they serve, they will show
                // different values, since they match different feed items.
                List <AdGroupAdOperation> adGroupAdOperations = new List <AdGroupAdOperation>();
                foreach (long adGroupId in adGroupIds)
                {
                    AdGroupAd adGroupAd = new AdGroupAd()
                    {
                        adGroupId = adGroupId,
                        ad        = expandedTextAd
                    };

                    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation()
                    {
                        operand   = adGroupAd,
                        @operator = Operator.ADD
                    };

                    adGroupAdOperations.Add(adGroupAdOperation);
                }

                AdGroupAdReturnValue adGroupAdReturnValue =
                    adGroupAdService.mutate(adGroupAdOperations.ToArray());

                foreach (AdGroupAd addedAd in adGroupAdReturnValue.value)
                {
                    Console.WriteLine("Created an ad with ID {0}, type '{1}' and status '{2}'.",
                                      addedAd.ad.id, addedAd.ad.AdType, addedAd.status);
                }
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">ID of the ad group to which ad is added.
        /// </param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupAdService.
            AdGroupAdService service =
                (AdGroupAdService)user.GetService(AdWordsService.v201702.AdGroupAdService);

            // Create the expanded text ad.
            ExpandedTextAd expandedTextAd = new ExpandedTextAd()
            {
                headlinePart1 = "Luxury Cruise to Mars",
                headlinePart2 = "Visit the Red Planet in style.",
                description   = "Low-gravity fun for everyone!",
            };

            // Specify a tracking URL for 3rd party tracking provider. You may
            // specify one at customer, campaign, ad group, ad, criterion or
            // feed item levels.
            expandedTextAd.trackingUrlTemplate =
                "http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}";

            // Since your tracking URL has two custom parameters, provide their
            // values too. This can be provided at campaign, ad group, ad, criterion
            // or feed item levels.
            CustomParameter seasonParameter = new CustomParameter();

            seasonParameter.key   = "season";
            seasonParameter.value = "christmas";

            CustomParameter promoCodeParameter = new CustomParameter();

            promoCodeParameter.key   = "promocode";
            promoCodeParameter.value = "NYC123";

            expandedTextAd.urlCustomParameters            = new CustomParameters();
            expandedTextAd.urlCustomParameters.parameters =
                new CustomParameter[] { seasonParameter, promoCodeParameter };

            // Specify a list of final URLs. This field cannot be set if URL field is
            // set. This may be specified at ad, criterion and feed item levels.
            expandedTextAd.finalUrls = new string[] {
                "http://www.example.com/cruise/space/",
                "http://www.example.com/locations/mars/"
            };

            // Specify a list of final mobile URLs. This field cannot be set if URL
            // field is set, or finalUrls is unset. This may be specified at ad,
            // criterion and feed item levels.
            expandedTextAd.finalMobileUrls = new string[] {
                "http://mobile.example.com/cruise/space/",
                "http://mobile.example.com/locations/mars/"
            };

            AdGroupAd adGroupAd = new AdGroupAd();

            adGroupAd.adGroupId = adGroupId;
            adGroupAd.ad        = expandedTextAd;

            // Optional: Set the status.
            adGroupAd.status = AdGroupAdStatus.PAUSED;

            // Create the operation.
            AdGroupAdOperation operation = new AdGroupAdOperation();

            operation.@operator = Operator.ADD;
            operation.operand   = adGroupAd;

            AdGroupAdReturnValue retVal = null;

            try {
                // Create the ads.
                retVal = service.mutate(new AdGroupAdOperation[] { operation });

                // Display the results.
                if (retVal != null && retVal.value != null)
                {
                    ExpandedTextAd newExpandedTextAd = retVal.value[0].ad as ExpandedTextAd;

                    Console.WriteLine("Expanded text ad with ID '{0}' and headline '{1} - {2}' was added.",
                                      newExpandedTextAd.id, newExpandedTextAd.headlinePart1,
                                      newExpandedTextAd.headlinePart2);

                    Console.WriteLine("Upgraded URL properties:");

                    Console.WriteLine("  Final URLs: {0}", string.Join(", ", newExpandedTextAd.finalUrls));
                    Console.WriteLine("  Final Mobile URLs: {0}",
                                      string.Join(", ", newExpandedTextAd.finalMobileUrls));
                    Console.WriteLine("  Tracking URL template: {0}", newExpandedTextAd.trackingUrlTemplate);

                    List <string> parameters = new List <string>();
                    foreach (CustomParameter customParam in
                             newExpandedTextAd.urlCustomParameters.parameters)
                    {
                        parameters.Add(string.Format("{0}={1}", customParam.key, customParam.value));
                    }
                    Console.WriteLine("  Custom parameters: {0}", string.Join(", ", parameters.ToArray()));
                }
                else
                {
                    Console.WriteLine("No expanded text ads were created.");
                }
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to create expanded text ad.", e);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group that contains the criterion.
        /// </param>
        /// <param name="criterionId">Id of the keyword for which the ad
        /// parameters are set.</param>
        public void Run(AdWordsUser user, long adGroupId, long criterionId)
        {
            using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(
                       AdWordsService.v201802.AdGroupAdService))
                using (AdParamService adParamService = (AdParamService)user.GetService(
                           AdWordsService.v201802.AdParamService)) {
                    // Create the expanded text ad.
                    ExpandedTextAd expandedTextAd = new ExpandedTextAd();
                    expandedTextAd.headlinePart1 = "Mars Cruises";
                    expandedTextAd.headlinePart2 = "Low-gravity fun for {param1:cheap}.";
                    expandedTextAd.description   = "Only {param2:a few} seats left!";
                    expandedTextAd.finalUrls     = new string[] { "http://www.example.com" };

                    AdGroupAd adOperand = new AdGroupAd();
                    adOperand.adGroupId = adGroupId;
                    adOperand.status    = AdGroupAdStatus.ENABLED;
                    adOperand.ad        = expandedTextAd;

                    // Create the operation.
                    AdGroupAdOperation adOperation = new AdGroupAdOperation();
                    adOperation.operand   = adOperand;
                    adOperation.@operator = Operator.ADD;


                    // Create the text ad.
                    AdGroupAdReturnValue retVal = adGroupAdService.mutate(
                        new AdGroupAdOperation[] { adOperation });

                    // Display the results.
                    if (retVal != null && retVal.value != null && retVal.value.Length > 0)
                    {
                        Console.WriteLine("Expanded text ad with id ='{0}' was successfully added.",
                                          retVal.value[0].ad.id);
                    }
                    else
                    {
                        throw new System.ApplicationException("Failed to create expanded text ads.");
                    }

                    // Create the ad param for price.
                    AdParam priceParam = new AdParam();
                    priceParam.adGroupId     = adGroupId;
                    priceParam.criterionId   = criterionId;
                    priceParam.paramIndex    = 1;
                    priceParam.insertionText = "$100";

                    // Create the ad param for seats.
                    AdParam seatParam = new AdParam();
                    seatParam.adGroupId     = adGroupId;
                    seatParam.criterionId   = criterionId;
                    seatParam.paramIndex    = 2;
                    seatParam.insertionText = "50";

                    // Create the operations.
                    AdParamOperation priceOperation = new AdParamOperation();
                    priceOperation.@operator = Operator.SET;
                    priceOperation.operand   = priceParam;

                    AdParamOperation seatOperation = new AdParamOperation();
                    seatOperation.@operator = Operator.SET;
                    seatOperation.operand   = seatParam;

                    try {
                        // Set the ad parameters.
                        AdParam[] newAdParams = adParamService.mutate(new AdParamOperation[]
                                                                      { priceOperation, seatOperation });

                        // Display the results.
                        if (newAdParams != null)
                        {
                            Console.WriteLine("Ad parameters were successfully updated.");
                        }
                        else
                        {
                            Console.WriteLine("No ad parameters were set.");
                        }
                    } catch (Exception e) {
                        throw new System.ApplicationException("Failed to set ad parameters.", e);
                    }
                }
        }
예제 #8
0
        public static AdGroupAdReturnValue CreateTextAds(AdWordsUser user, AdWordsContentLo adWordsContent)
        {
            using (AdGroupAdService adGroupAdService =
                       (AdGroupAdService)user.GetService(AdWordsService.v201710.AdGroupAdService))
            {
                List <AdGroupAdOperation> operations = new List <AdGroupAdOperation>();

                for (int i = 0; i < adWordsContent.ContentProducts.Count; i++)
                {
                    // Create the expanded text ad.
                    ExpandedTextAd expandedTextAd = new ExpandedTextAd();
                    expandedTextAd.headlinePart1 = adWordsContent.ContentProducts[i].AdContent.HeadLinePart1;
                    expandedTextAd.headlinePart2 = adWordsContent.ContentProducts[i].AdContent.HeadLinePart2;
                    expandedTextAd.path1         = adWordsContent.ContentProducts[i].AdContent.Path1 != "" ? adWordsContent.ContentProducts[i].AdContent.Path1 : "";
                    expandedTextAd.path2         = adWordsContent.ContentProducts[i].AdContent.Path2 != "" ? adWordsContent.ContentProducts[i].AdContent.Path2 : "";
                    expandedTextAd.description   = adWordsContent.ContentProducts[i].AdContent.Description;
                    expandedTextAd.finalUrls     = adWordsContent.ContentProducts[i].FinalUrl;

                    AdGroupAd expandedTextAdGroupAd = new AdGroupAd();
                    expandedTextAdGroupAd.adGroupId = adWordsContent.AdGroupLo.AdGroupId;
                    expandedTextAdGroupAd.ad        = expandedTextAd;

                    // Optional: Set the status.
                    expandedTextAdGroupAd.status = AdGroupAdStatus.ENABLED;

                    // Create the operation.
                    AdGroupAdOperation operation = new AdGroupAdOperation();
                    operation.@operator = Operator.ADD;
                    operation.operand   = expandedTextAdGroupAd;

                    operations.Add(operation);
                }

                AdGroupAdReturnValue retVal = null;

                try
                {
                    // Create the ads.
                    retVal = adGroupAdService.mutate(operations.ToArray());


                    adGroupAdService.Close();
                }
                catch (AdWordsApiException e)
                {
                    ApiException innerException = e.ApiException as ApiException;
                    if (innerException == null)
                    {
                        throw new Exception("Failed to retrieve ApiError. See inner exception for more " +
                                            "details.", e);
                    }

                    // Examine each ApiError received from the server.
                    foreach (ApiError apiError in innerException.errors)
                    {
                        int index = apiError.GetOperationIndex();
                        if (index == -1)
                        {
                            // This API error is not associated with an operand, so we cannot
                            // recover from this error by removing one or more operations.
                            // Rethrow the exception for manual inspection.
                            throw;
                        }

                        // Handle policy violation errors.
                        if (apiError is PolicyViolationError)
                        {
                            PolicyViolationError policyError = (PolicyViolationError)apiError;

                            if (policyError.isExemptable)
                            {
                                // If the policy violation error is exemptable, add an exemption
                                // request.
                                List <ExemptionRequest> exemptionRequests = new List <ExemptionRequest>();
                            }
                            else
                            {
                                // Policy violation error is not exemptable, remove this
                                // operation from the list of operations.
                            }
                        }
                        else
                        {
                            // This is not a policy violation error, remove this operation
                            // from the list of operations.
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new System.ApplicationException("Failed to create expanded text ad.", ex);
                }
                return(retVal);
            }
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="adGroupId">Id of the ad group from which expanded text ads
        /// are retrieved.</param>
        public void Run(AdWordsUser user, long adGroupId)
        {
            using (AdGroupAdService adGroupAdService =
                       (AdGroupAdService)user.GetService(AdWordsService.v201802.AdGroupAdService)) {
                // Create a selector.
                Selector selector = new Selector()
                {
                    fields = new string[] {
                        ExpandedTextAd.Fields.Id, AdGroupAd.Fields.Status, ExpandedTextAd.Fields.HeadlinePart1,
                        ExpandedTextAd.Fields.HeadlinePart2, ExpandedTextAd.Fields.Description, ExpandedTextAd.Fields.SystemManagedEntitySource
                    },
                    ordering   = new OrderBy[] { OrderBy.Asc(ExpandedTextAd.Fields.Id) },
                    predicates = new Predicate[] {
                        // Restrict the fetch to only the selected ad group id.
                        Predicate.Equals(AdGroupAd.Fields.AdGroupId, adGroupId),

                        // Retrieve only expanded text ads.
                        Predicate.Equals("AdType", "EXPANDED_TEXT_AD"),

                        // By default disabled ads aren't returned by the selector. To return
                        // them include the DISABLED status in the statuses field.
                        Predicate.In(AdGroupAd.Fields.Status, new string[] {
                            AdGroupAdStatus.ENABLED.ToString(),
                            AdGroupAdStatus.PAUSED.ToString(),
                            AdGroupAdStatus.DISABLED.ToString()
                        })
                    },
                    paging = Paging.Default
                };

                AdGroupAdPage page = new AdGroupAdPage();

                try {
                    do
                    {
                        // Get the expanded text ads.
                        page = adGroupAdService.get(selector);

                        // Display the results.
                        if (page != null && page.entries != null)
                        {
                            int i = selector.paging.startIndex;

                            foreach (AdGroupAd adGroupAd in page.entries)
                            {
                                ExpandedTextAd expandedTextAd = (ExpandedTextAd)adGroupAd.ad;
                                Console.WriteLine("{0} : Expanded text ad with ID '{1}', headline '{2} - {3}' " +
                                                  "and description '{4} was found.", i + 1, expandedTextAd.id,
                                                  expandedTextAd.headlinePart1, expandedTextAd.headlinePart2,
                                                  expandedTextAd.description);
                                i++;
                            }
                        }
                        selector.paging.IncreaseOffset();
                    } while (selector.paging.startIndex < page.totalNumEntries);
                    Console.WriteLine("Number of expanded text ads found: {0}", page.totalNumEntries);
                } catch (Exception e) {
                    throw new System.ApplicationException("Failed to get expanded text ads", e);
                }
            }
        }
        public async Task TestAdGroupAd_CRUD_Passed()
        {
            var  service    = CreateService();
            var  testConfig = TestConfig.GetFromConfigFile();
            long adGroupId  = testConfig.AdWords.AdGroupId;

            // Create
            var createOp = new AdGroupAdOperation();
            var textAd   = new ExpandedTextAd
            {
                HeadlinePart1 = "Test Headline Part One",
                HeadlinePart2 = "Test Headline Part Two",
                Description   = "Test Expanded Text Ad Description",
                FinalUrls     = StringUtility.List("https://github.com/manychois/googleapis-dotnetcore")
            };

            createOp.Operand = new AdGroupAd
            {
                AdGroupId = adGroupId,
                Ad        = textAd,
                Status    = AdGroupAdStatus.Enabled
            };
            createOp.Operator = Operator.Add;

            var returnValue = await service.MutateAsync(new AdGroupAdOperation[] { createOp });

            Assert.Equal(1, returnValue.Value.Count);
            var returnAdGroupAd = returnValue.Value[0];

            Assert.Equal(adGroupId, returnAdGroupAd.AdGroupId.Value);
            Assert.Equal(AdGroupAdStatus.Enabled, returnAdGroupAd.Status.Value);
            Assert.IsType <ExpandedTextAd>(returnAdGroupAd.Ad);
            var returnTextAd = returnAdGroupAd.Ad as ExpandedTextAd;

            Assert.Equal(textAd.HeadlinePart1, returnTextAd.HeadlinePart1);
            Assert.Equal(textAd.HeadlinePart2, returnTextAd.HeadlinePart2);
            Assert.Equal(textAd.Description, returnTextAd.Description);
            Assert.Equal(textAd.FinalUrls, returnTextAd.FinalUrls);

            long adId = returnTextAd.Id.Value;

            // Read
            var selector = new Selector <AdGroupAdServiceField>()
                           .AddFields(
                AdGroupAdServiceField.AdGroupId,
                AdGroupAdServiceField.BaseCampaignId,
                AdGroupAdServiceField.Status,
                AdGroupAdServiceField.AdGroupCreativeApprovalStatus,
                AdGroupAdServiceField.HeadlinePart1,
                AdGroupAdServiceField.HeadlinePart2,
                AdGroupAdServiceField.Description,
                AdGroupAdServiceField.CreativeFinalUrls)
                           .AddPredicate(AdGroupAdServiceField.Id, PredicateOperator.Equals, adId);

            var page = await service.GetAsync(selector);

            Assert.Equal(1, page.TotalNumEntries.Value);
            returnAdGroupAd = page.Entries[0];
            Assert.Equal(adGroupId, returnAdGroupAd.AdGroupId.Value);
            Assert.Equal(AdGroupAdStatus.Enabled, returnAdGroupAd.Status.Value);
            Assert.Equal(testConfig.AdWords.CampaignId, returnAdGroupAd.BaseCampaignId.Value);
            Assert.Equal(AdGroupAdApprovalStatus.Unchecked, returnAdGroupAd.ApprovalStatus.Value);
            Assert.IsType <ExpandedTextAd>(returnAdGroupAd.Ad);
            returnTextAd = returnAdGroupAd.Ad as ExpandedTextAd;
            Assert.Equal(textAd.HeadlinePart1, returnTextAd.HeadlinePart1);
            Assert.Equal(textAd.HeadlinePart2, returnTextAd.HeadlinePart2);
            Assert.Equal(textAd.Description, returnTextAd.Description);
            Assert.Equal(textAd.FinalUrls, returnTextAd.FinalUrls);

            // Update (Status only)
            var setOp = new AdGroupAdOperation();

            setOp.Operand = new AdGroupAd
            {
                AdGroupId = adGroupId,
                Ad        = new Ad
                {
                    Id = adId
                },
                Status = AdGroupAdStatus.Paused
            };
            setOp.Operator = Operator.Set;

            returnValue = await service.MutateAsync(new AdGroupAdOperation[] { setOp });

            Assert.Equal(1, returnValue.Value.Count);
            returnAdGroupAd = returnValue.Value[0];
            Assert.Equal(adGroupId, returnAdGroupAd.AdGroupId.Value);
            Assert.Equal(AdGroupAdStatus.Paused, returnAdGroupAd.Status.Value);
            Assert.IsType <ExpandedTextAd>(returnAdGroupAd.Ad);
            returnTextAd = returnAdGroupAd.Ad as ExpandedTextAd;
            Assert.Equal(textAd.HeadlinePart1, returnTextAd.HeadlinePart1);
            Assert.Equal(textAd.HeadlinePart2, returnTextAd.HeadlinePart2);
            Assert.Equal(textAd.Description, returnTextAd.Description);
            Assert.Equal(textAd.FinalUrls, returnTextAd.FinalUrls);

            // Delete
            var removeOp = new AdGroupAdOperation();

            removeOp.Operand = new AdGroupAd
            {
                AdGroupId = adGroupId,
                Ad        = new Ad
                {
                    Id = adId
                }
            };
            removeOp.Operator = Operator.Remove;

            returnValue = await service.MutateAsync(new AdGroupAdOperation[] { removeOp });

            Assert.Equal(1, returnValue.Value.Count);
            returnAdGroupAd = returnValue.Value[0];
            Assert.Equal(adId, returnAdGroupAd.Ad.Id);
        }