Beispiel #1
0
        public void MutateCampaignLabels()
        {
            moq::Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new moq::Mock <CampaignLabelService.CampaignLabelServiceClient>(moq::MockBehavior.Strict);
            MutateCampaignLabelsRequest request = new MutateCampaignLabelsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new CampaignLabelOperation(),
                },
            };
            MutateCampaignLabelsResponse expectedResponse = new MutateCampaignLabelsResponse
            {
                Results =
                {
                    new MutateCampaignLabelResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateCampaignLabels(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            CampaignLabelServiceClient   client   = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignLabelsResponse response = client.MutateCampaignLabels(request.CustomerId, request.Operations);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Beispiel #2
0
        public async stt::Task MutateCampaignLabelsRequestObjectAsync()
        {
            moq::Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new moq::Mock <CampaignLabelService.CampaignLabelServiceClient>(moq::MockBehavior.Strict);
            MutateCampaignLabelsRequest request = new MutateCampaignLabelsRequest
            {
                CustomerId = "customer_id3b3724cb",
                Operations =
                {
                    new CampaignLabelOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = true,
            };
            MutateCampaignLabelsResponse expectedResponse = new MutateCampaignLabelsResponse
            {
                Results =
                {
                    new MutateCampaignLabelResult(),
                },
                PartialFailureError = new gr::Status(),
            };

            mockGrpcClient.Setup(x => x.MutateCampaignLabelsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateCampaignLabelsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            CampaignLabelServiceClient   client = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignLabelsResponse responseCallSettings = await client.MutateCampaignLabelsAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            MutateCampaignLabelsResponse responseCancellationToken = await client.MutateCampaignLabelsAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
 /// <summary>Snippet for MutateCampaignLabels</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignLabels()
 {
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <CampaignLabelOperation> operations = new CampaignLabelOperation[]
     {
         new CampaignLabelOperation(),
     };
     // Make the request
     MutateCampaignLabelsResponse response = campaignLabelServiceClient.MutateCampaignLabels(customerId, operations);
 }
Beispiel #4
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="campaignIds">IDs of the campaigns where the campaign labels will be added.
        /// </param>
        /// <param name="labelId">The ID of the label to attach to campaigns.</param>
        public void Run(GoogleAdsClient client, long customerId, long[] campaignIds, long labelId)
        {
            // Get the CampaignLabelServiceClient.
            CampaignLabelServiceClient campaignLabelService =
                client.GetService(Services.V3.CampaignLabelService);

            // Gets the resource name of the label to be added across all given campaigns.
            string labelResourceName = ResourceNames.Label(customerId, labelId);

            List <CampaignLabelOperation> operations = new List <CampaignLabelOperation>();

            // Creates a campaign label operation for each campaign.
            foreach (long campaignId in campaignIds)
            {
                // Gets the resource name of the given campaign.
                string campaignResourceName = ResourceNames.Campaign(customerId, campaignId);
                // Creates the campaign label.
                CampaignLabel campaignLabel = new CampaignLabel()
                {
                    Campaign = campaignResourceName,
                    Label    = labelResourceName
                };

                operations.Add(new CampaignLabelOperation()
                {
                    Create = campaignLabel
                });
            }

            // Send the operation in a mutate request.
            try
            {
                MutateCampaignLabelsResponse response =
                    campaignLabelService.MutateCampaignLabels(customerId.ToString(), operations);
                Console.WriteLine($"Added {response.Results} campaign labels:");

                foreach (MutateCampaignLabelResult result in response.Results)
                {
                    Console.WriteLine(result.ResourceName);
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        /// <summary>Snippet for MutateCampaignLabelsAsync</summary>
        public async Task MutateCampaignLabelsAsync()
        {
            // Snippet: MutateCampaignLabelsAsync(string, IEnumerable<CampaignLabelOperation>, CallSettings)
            // Additional: MutateCampaignLabelsAsync(string, IEnumerable<CampaignLabelOperation>, CancellationToken)
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <CampaignLabelOperation> operations = new CampaignLabelOperation[]
            {
                new CampaignLabelOperation(),
            };
            // Make the request
            MutateCampaignLabelsResponse response = await campaignLabelServiceClient.MutateCampaignLabelsAsync(customerId, operations);

            // End snippet
        }
Beispiel #6
0
 /// <summary>Snippet for MutateCampaignLabels</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void MutateCampaignLabelsRequestObject()
 {
     // Create client
     CampaignLabelServiceClient campaignLabelServiceClient = CampaignLabelServiceClient.Create();
     // Initialize request argument(s)
     MutateCampaignLabelsRequest request = new MutateCampaignLabelsRequest
     {
         CustomerId = "",
         Operations =
         {
             new CampaignLabelOperation(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     MutateCampaignLabelsResponse response = campaignLabelServiceClient.MutateCampaignLabels(request);
 }
        public async Task MutateCampaignLabelsAsync3()
        {
            Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new Mock <CampaignLabelService.CampaignLabelServiceClient>(MockBehavior.Strict);
            MutateCampaignLabelsRequest request = new MutateCampaignLabelsRequest
            {
                CustomerId = "customerId-1772061412",
                Operations = { },
            };
            MutateCampaignLabelsResponse expectedResponse = new MutateCampaignLabelsResponse();

            mockGrpcClient.Setup(x => x.MutateCampaignLabelsAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateCampaignLabelsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            CampaignLabelServiceClient   client   = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignLabelsResponse response = await client.MutateCampaignLabelsAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void MutateCampaignLabels3()
        {
            Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new Mock <CampaignLabelService.CampaignLabelServiceClient>(MockBehavior.Strict);
            MutateCampaignLabelsRequest request = new MutateCampaignLabelsRequest
            {
                CustomerId = "customerId-1772061412",
                Operations = { },
            };
            MutateCampaignLabelsResponse expectedResponse = new MutateCampaignLabelsResponse();

            mockGrpcClient.Setup(x => x.MutateCampaignLabels(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            CampaignLabelServiceClient   client   = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            MutateCampaignLabelsResponse response = client.MutateCampaignLabels(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>Snippet for MutateCampaignLabelsAsync</summary>
        public async Task MutateCampaignLabelsRequestObjectAsync()
        {
            // Snippet: MutateCampaignLabelsAsync(MutateCampaignLabelsRequest, CallSettings)
            // Additional: MutateCampaignLabelsAsync(MutateCampaignLabelsRequest, CancellationToken)
            // Create client
            CampaignLabelServiceClient campaignLabelServiceClient = await CampaignLabelServiceClient.CreateAsync();

            // Initialize request argument(s)
            MutateCampaignLabelsRequest request = new MutateCampaignLabelsRequest
            {
                CustomerId = "",
                Operations =
                {
                    new CampaignLabelOperation(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            MutateCampaignLabelsResponse response = await campaignLabelServiceClient.MutateCampaignLabelsAsync(request);

            // End snippet
        }
        public async Task MutateCampaignLabelsAsync()
        {
            Mock <CampaignLabelService.CampaignLabelServiceClient> mockGrpcClient = new Mock <CampaignLabelService.CampaignLabelServiceClient>(MockBehavior.Strict);
            MutateCampaignLabelsRequest expectedRequest = new MutateCampaignLabelsRequest
            {
                CustomerId     = "customerId-1772061412",
                Operations     = { },
                PartialFailure = true,
                ValidateOnly   = false,
            };
            MutateCampaignLabelsResponse expectedResponse = new MutateCampaignLabelsResponse();

            mockGrpcClient.Setup(x => x.MutateCampaignLabelsAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <MutateCampaignLabelsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            CampaignLabelServiceClient client = new CampaignLabelServiceClientImpl(mockGrpcClient.Object, null);
            string customerId = "customerId-1772061412";
            IEnumerable <CampaignLabelOperation> operations = new List <CampaignLabelOperation>();
            bool partialFailure = true;
            bool validateOnly   = false;
            MutateCampaignLabelsResponse response = await client.MutateCampaignLabelsAsync(customerId, operations, partialFailure, validateOnly);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }