public void ApplyRecommendation() { moq::Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new moq::Mock <RecommendationService.RecommendationServiceClient>(moq::MockBehavior.Strict); ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "customer_id3b3724cb", Operations = { new ApplyRecommendationOperation(), }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse { Results = { new ApplyRecommendationResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.ApplyRecommendation(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); ApplyRecommendationResponse response = client.ApplyRecommendation(request.CustomerId, request.Operations); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task ApplyRecommendationAsync() { moq::Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new moq::Mock <RecommendationService.RecommendationServiceClient>(moq::MockBehavior.Strict); ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "customer_id3b3724cb", Operations = { new ApplyRecommendationOperation(), }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse { Results = { new ApplyRecommendationResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.ApplyRecommendationAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ApplyRecommendationResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); ApplyRecommendationResponse responseCallSettings = await client.ApplyRecommendationAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); ApplyRecommendationResponse responseCancellationToken = await client.ApplyRecommendationAsync(request.CustomerId, request.Operations, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for ApplyRecommendation</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void ApplyRecommendation() { // Create client RecommendationServiceClient recommendationServiceClient = RecommendationServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <ApplyRecommendationOperation> operations = new ApplyRecommendationOperation[] { new ApplyRecommendationOperation(), }; // Make the request ApplyRecommendationResponse response = recommendationServiceClient.ApplyRecommendation(customerId, operations); }
/// <summary>Snippet for ApplyRecommendation</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void ApplyRecommendationRequestObject() { // Create client RecommendationServiceClient recommendationServiceClient = RecommendationServiceClient.Create(); // Initialize request argument(s) ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "", Operations = { new ApplyRecommendationOperation(), }, PartialFailure = false, }; // Make the request ApplyRecommendationResponse response = recommendationServiceClient.ApplyRecommendation(request); }
/// <summary>Snippet for ApplyRecommendationAsync</summary> public async Task ApplyRecommendationAsync() { // Snippet: ApplyRecommendationAsync(string, IEnumerable<ApplyRecommendationOperation>, CallSettings) // Additional: ApplyRecommendationAsync(string, IEnumerable<ApplyRecommendationOperation>, CancellationToken) // Create client RecommendationServiceClient recommendationServiceClient = await RecommendationServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <ApplyRecommendationOperation> operations = new ApplyRecommendationOperation[] { new ApplyRecommendationOperation(), }; // Make the request ApplyRecommendationResponse response = await recommendationServiceClient.ApplyRecommendationAsync(customerId, operations); // End snippet }
public async Task ApplyRecommendationAsync3() { Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict); ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "customerId-1772061412", Operations = { }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse(); mockGrpcClient.Setup(x => x.ApplyRecommendationAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <ApplyRecommendationResponse>(Task.FromResult(expectedResponse), null, null, null, null)); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); ApplyRecommendationResponse response = await client.ApplyRecommendationAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void ApplyRecommendation3() { Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict); ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "customerId-1772061412", Operations = { }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse(); mockGrpcClient.Setup(x => x.ApplyRecommendation(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); ApplyRecommendationResponse response = client.ApplyRecommendation(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="recommendationId">ID of the recommendation to apply.</param> public void Run(GoogleAdsClient client, long customerId, long recommendationId) { // Get the RecommendationServiceClient. RecommendationServiceClient service = client.GetService( Services.V0.RecommendationService); ApplyRecommendationOperation operation = new ApplyRecommendationOperation() { ResourceName = ResourceNames.Recommendation(customerId, recommendationId), // Each recommendation types has optional parameters to override the recommended // values. For example, you can override a recommended ad when a // TextAdRecommendation is applied, as shown below. // Please read https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v0.services#google.ads.googleads.v0.services.ApplyRecommendationOperation // for details. // TextAd = new TextAdParameters() { // Ad = new Ad() { // Id = long.Parse("INSERT_AD_ID_HERE") // } // } }; bool partialFailure = false; try { ApplyRecommendationResponse response = service.ApplyRecommendation( customerId.ToString(), partialFailure, new ApplyRecommendationOperation[] { operation }); Console.WriteLine($"Applied {0} recommendation(s):", response.Results.Count); foreach (ApplyRecommendationResult 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}"); } }
public async Task ApplyRecommendationAsync() { Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict); ApplyRecommendationRequest expectedRequest = new ApplyRecommendationRequest { CustomerId = "customerId-1772061412", PartialFailure = true, Operations = { }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse(); mockGrpcClient.Setup(x => x.ApplyRecommendationAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <ApplyRecommendationResponse>(Task.FromResult(expectedResponse), null, null, null, null)); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); string customerId = "customerId-1772061412"; bool partialFailure = true; IEnumerable <ApplyRecommendationOperation> operations = new List <ApplyRecommendationOperation>(); ApplyRecommendationResponse response = await client.ApplyRecommendationAsync(customerId, partialFailure, operations); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary>Snippet for ApplyRecommendationAsync</summary> public async Task ApplyRecommendationRequestObjectAsync() { // Snippet: ApplyRecommendationAsync(ApplyRecommendationRequest, CallSettings) // Additional: ApplyRecommendationAsync(ApplyRecommendationRequest, CancellationToken) // Create client RecommendationServiceClient recommendationServiceClient = await RecommendationServiceClient.CreateAsync(); // Initialize request argument(s) ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "", Operations = { new ApplyRecommendationOperation(), }, PartialFailure = false, }; // Make the request ApplyRecommendationResponse response = await recommendationServiceClient.ApplyRecommendationAsync(request); // End snippet }
public void ApplyRecommendation() { Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict); ApplyRecommendationRequest expectedRequest = new ApplyRecommendationRequest { CustomerId = "customerId-1772061412", Operations = { }, PartialFailure = true, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse(); mockGrpcClient.Setup(x => x.ApplyRecommendation(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); string customerId = "customerId-1772061412"; IEnumerable <ApplyRecommendationOperation> operations = new List <ApplyRecommendationOperation>(); bool partialFailure = true; ApplyRecommendationResponse response = client.ApplyRecommendation(customerId, operations, partialFailure); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }