Esempio n. 1
0
 /// <summary>Snippet for MutateAdGroupAdLabels</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateAdGroupAdLabels()
 {
     // Create client
     AdGroupAdLabelServiceClient adGroupAdLabelServiceClient = AdGroupAdLabelServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <AdGroupAdLabelOperation> operations = new AdGroupAdLabelOperation[]
     {
         new AdGroupAdLabelOperation(),
     };
     // Make the request
     MutateAdGroupAdLabelsResponse response = adGroupAdLabelServiceClient.MutateAdGroupAdLabels(customerId, operations);
 }
Esempio n. 2
0
 /// <summary>Snippet for MutateAdGroupAdLabelsAsync</summary>
 public async Task MutateAdGroupAdLabelsAsync()
 {
     // Snippet: MutateAdGroupAdLabelsAsync(string, IEnumerable<AdGroupAdLabelOperation>, CallSettings)
     // Additional: MutateAdGroupAdLabelsAsync(string, IEnumerable<AdGroupAdLabelOperation>, CancellationToken)
     // Create client
     AdGroupAdLabelServiceClient adGroupAdLabelServiceClient = await AdGroupAdLabelServiceClient.CreateAsync();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable<AdGroupAdLabelOperation> operations = new AdGroupAdLabelOperation[]
     {
         new AdGroupAdLabelOperation(),
     };
     // Make the request
     MutateAdGroupAdLabelsResponse response = await adGroupAdLabelServiceClient.MutateAdGroupAdLabelsAsync(customerId, operations);
     // End snippet
 }
        public async Task TestLabel_CD_Passed()
        {
            var testConfig = TestConfig.GetFromConfigFile();

            long          labelId       = 0;
            ILabelService labelService  = CreateService <ILabelService>((x, y, z) => new LabelService(x, y, z));
            var           labelSelector = new Selector <LabelServiceField>()
                                          .AddFields(LabelServiceField.LabelId)
                                          .AddPredicate(LabelServiceField.LabelName, PredicateOperator.Equals, testConfig.AdWords.LabelText);
            var lsReturnValue = await labelService.GetAsync(labelSelector);

            labelId = lsReturnValue.Entries[0].Id.Value;

            IAdGroupAdService adService = CreateService();
            // Create
            var createOp = new AdGroupAdLabelOperation();

            createOp.Operand = new AdGroupAdLabel
            {
                AdGroupId = testConfig.AdWords.AdGroupId,
                AdId      = testConfig.AdWords.AdId,
                LabelId   = labelId
            };
            createOp.Operator = Operator.Add;

            var adLabelReturnValue = await adService.MutateLabelAsync(new AdGroupAdLabelOperation[] { createOp });

            Assert.Equal(1, adLabelReturnValue.Value.Count);
            var adLabel = adLabelReturnValue.Value[0];

            Assert.Equal(testConfig.AdWords.AdGroupId, adLabel.AdGroupId.Value);
            Assert.Equal(testConfig.AdWords.AdId, adLabel.AdId.Value);
            Assert.Equal(labelId, adLabel.LabelId.Value);

            var adSelector = new Selector <AdGroupAdServiceField>()
                             .AddFields(AdGroupAdServiceField.Labels)
                             .AddPredicate(AdGroupAdServiceField.Id, PredicateOperator.Equals, testConfig.AdWords.AdId);
            var adReturnValue = await adService.GetAsync(adSelector);

            Assert.Equal(1, adReturnValue.TotalNumEntries.Value);
            var returnAdGroupAd = adReturnValue.Entries[0];

            Assert.True(returnAdGroupAd.Labels.Count >= 1);
            var returnLabel = returnAdGroupAd.Labels.First(x => x.Name == testConfig.AdWords.LabelText) as TextLabel;

            Assert.Equal(labelId, returnLabel.Id);

            // Delete
            var removeOp = new AdGroupAdLabelOperation();

            removeOp.Operand = new AdGroupAdLabel
            {
                AdGroupId = testConfig.AdWords.AdGroupId,
                AdId      = testConfig.AdWords.AdId,
                LabelId   = labelId
            };
            removeOp.Operator = Operator.Remove;

            adLabelReturnValue = await adService.MutateLabelAsync(new AdGroupAdLabelOperation[] { removeOp });

            Assert.Equal(1, adLabelReturnValue.Value.Count);
            adLabel = adLabelReturnValue.Value[0];
            Assert.Equal(testConfig.AdWords.AdGroupId, adLabel.AdGroupId.Value);
            Assert.Equal(testConfig.AdWords.AdId, adLabel.AdId.Value);
            Assert.False(adLabel.LabelId.HasValue);
        }