public void MutateCustomizerAttributes() { moq::Mock <CustomizerAttributeService.CustomizerAttributeServiceClient> mockGrpcClient = new moq::Mock <CustomizerAttributeService.CustomizerAttributeServiceClient>(moq::MockBehavior.Strict); MutateCustomizerAttributesRequest request = new MutateCustomizerAttributesRequest { CustomerId = "customer_id3b3724cb", Operations = { new CustomizerAttributeOperation(), }, }; MutateCustomizerAttributesResponse expectedResponse = new MutateCustomizerAttributesResponse { Results = { new MutateCustomizerAttributeResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.MutateCustomizerAttributes(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); CustomizerAttributeServiceClient client = new CustomizerAttributeServiceClientImpl(mockGrpcClient.Object, null); MutateCustomizerAttributesResponse response = client.MutateCustomizerAttributes(request.CustomerId, request.Operations); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
// [START add_responsive_search_ad_with_ad_customizer_1] /// <summary> /// Creates a customizer attribute with the specified customizer attribute name. /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The customer ID.</param> /// <param name="customizerAttributeName">The name of the customizer attribute.</param> /// <returns>The created customizer attribute resource name.</returns> private string CreateCustomizerAttribute( GoogleAdsClient client, long customerId, string customizerAttributeName) { // Creates a customizer attribute operation for creating a customizer attribute. CustomizerAttributeOperation operation = new CustomizerAttributeOperation() { // Creates a customizer attribute with the specified name. Create = new CustomizerAttribute() { Name = customizerAttributeName, // Specifies the type to be 'PRICE' so that we can dynamically customize the part of // the ad's description that is a price of a product/service we advertise. Type = CustomizerAttributeType.Price } }; CustomizerAttributeServiceClient serviceClient = client.GetService(Services.V10.CustomizerAttributeService); // Issues a mutate request to add the customizer attribute and prints its information. MutateCustomizerAttributesResponse response = serviceClient.MutateCustomizerAttributes( customerId.ToString(), new [] { operation }.ToList() ); string resourceName = response.Results[0].ResourceName; Console.WriteLine($"Added a customizer attribute with resource name '{resourceName}'."); return(resourceName); }
public async stt::Task MutateCustomizerAttributesRequestObjectAsync() { moq::Mock <CustomizerAttributeService.CustomizerAttributeServiceClient> mockGrpcClient = new moq::Mock <CustomizerAttributeService.CustomizerAttributeServiceClient>(moq::MockBehavior.Strict); MutateCustomizerAttributesRequest request = new MutateCustomizerAttributesRequest { CustomerId = "customer_id3b3724cb", Operations = { new CustomizerAttributeOperation(), }, PartialFailure = false, ValidateOnly = true, ResponseContentType = gagve::ResponseContentTypeEnum.Types.ResponseContentType.ResourceNameOnly, }; MutateCustomizerAttributesResponse expectedResponse = new MutateCustomizerAttributesResponse { Results = { new MutateCustomizerAttributeResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.MutateCustomizerAttributesAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateCustomizerAttributesResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); CustomizerAttributeServiceClient client = new CustomizerAttributeServiceClientImpl(mockGrpcClient.Object, null); MutateCustomizerAttributesResponse responseCallSettings = await client.MutateCustomizerAttributesAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); MutateCustomizerAttributesResponse responseCancellationToken = await client.MutateCustomizerAttributesAsync(request, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }