public async stt::Task MutateKeywordPlanKeywordsAsync() { moq::Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new moq::Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(moq::MockBehavior.Strict); MutateKeywordPlanKeywordsRequest request = new MutateKeywordPlanKeywordsRequest { CustomerId = "customer_id3b3724cb", Operations = { new KeywordPlanKeywordOperation(), }, }; MutateKeywordPlanKeywordsResponse expectedResponse = new MutateKeywordPlanKeywordsResponse { Results = { new MutateKeywordPlanKeywordResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.MutateKeywordPlanKeywordsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateKeywordPlanKeywordsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null); MutateKeywordPlanKeywordsResponse responseCallSettings = await client.MutateKeywordPlanKeywordsAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); MutateKeywordPlanKeywordsResponse responseCancellationToken = await client.MutateKeywordPlanKeywordsAsync(request.CustomerId, request.Operations, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void MutateKeywordPlanKeywords() { moq::Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new moq::Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(moq::MockBehavior.Strict); MutateKeywordPlanKeywordsRequest request = new MutateKeywordPlanKeywordsRequest { CustomerId = "customer_id3b3724cb", Operations = { new KeywordPlanKeywordOperation(), }, }; MutateKeywordPlanKeywordsResponse expectedResponse = new MutateKeywordPlanKeywordsResponse { Results = { new MutateKeywordPlanKeywordResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.MutateKeywordPlanKeywords(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null); MutateKeywordPlanKeywordsResponse response = client.MutateKeywordPlanKeywords(request.CustomerId, request.Operations); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task MutateKeywordPlanKeywordsAsync3() { Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(MockBehavior.Strict); MutateKeywordPlanKeywordsRequest request = new MutateKeywordPlanKeywordsRequest { CustomerId = "customerId-1772061412", Operations = { }, }; MutateKeywordPlanKeywordsResponse expectedResponse = new MutateKeywordPlanKeywordsResponse(); mockGrpcClient.Setup(x => x.MutateKeywordPlanKeywordsAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <MutateKeywordPlanKeywordsResponse>(Task.FromResult(expectedResponse), null, null, null, null)); KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null); MutateKeywordPlanKeywordsResponse response = await client.MutateKeywordPlanKeywordsAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void MutateKeywordPlanKeywords3() { Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(MockBehavior.Strict); MutateKeywordPlanKeywordsRequest request = new MutateKeywordPlanKeywordsRequest { CustomerId = "customerId-1772061412", Operations = { }, }; MutateKeywordPlanKeywordsResponse expectedResponse = new MutateKeywordPlanKeywordsResponse(); mockGrpcClient.Setup(x => x.MutateKeywordPlanKeywords(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null); MutateKeywordPlanKeywordsResponse response = client.MutateKeywordPlanKeywords(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task MutateKeywordPlanKeywordsAsync() { Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(MockBehavior.Strict); MutateKeywordPlanKeywordsRequest expectedRequest = new MutateKeywordPlanKeywordsRequest { CustomerId = "customerId-1772061412", Operations = { }, PartialFailure = true, ValidateOnly = false, }; MutateKeywordPlanKeywordsResponse expectedResponse = new MutateKeywordPlanKeywordsResponse(); mockGrpcClient.Setup(x => x.MutateKeywordPlanKeywordsAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <MutateKeywordPlanKeywordsResponse>(Task.FromResult(expectedResponse), null, null, null, null)); KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null); string customerId = "customerId-1772061412"; IEnumerable <KeywordPlanKeywordOperation> operations = new List <KeywordPlanKeywordOperation>(); bool partialFailure = true; bool validateOnly = false; MutateKeywordPlanKeywordsResponse response = await client.MutateKeywordPlanKeywordsAsync(customerId, operations, partialFailure, validateOnly); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary> /// Creates keywords for the keyword plan. /// </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="planAdGroupResource">The resource name of the ad group under which the /// keyword is created.</param> private static void CreateKeywordPlanKeywords(GoogleAdsClient client, long customerId, string planAdGroupResource) { // Get the KeywordPlanKeywordService. KeywordPlanKeywordServiceClient serviceClient = client.GetService( Services.V1.KeywordPlanKeywordService); // Create the keywords for keyword plan. KeywordPlanKeyword keywordPlanKeyword1 = new KeywordPlanKeyword() { KeywordPlanAdGroup = planAdGroupResource, CpcBidMicros = 2_000_000L, MatchType = KeywordMatchType.Broad, Text = "mars cruise" }; KeywordPlanKeyword keywordPlanKeyword2 = new KeywordPlanKeyword() { KeywordPlanAdGroup = planAdGroupResource, CpcBidMicros = 1_500_000L, MatchType = KeywordMatchType.Phrase, Text = "cheap cruise" }; KeywordPlanKeyword keywordPlanKeyword3 = new KeywordPlanKeyword() { KeywordPlanAdGroup = planAdGroupResource, CpcBidMicros = 1_990_000L, MatchType = KeywordMatchType.Exact, Text = "jupiter cruise" }; KeywordPlanKeyword[] keywordPlanKeywords = new KeywordPlanKeyword[] { keywordPlanKeyword1, keywordPlanKeyword2, keywordPlanKeyword3 }; // Create an operation for each plan keyword. List <KeywordPlanKeywordOperation> operations = new List <KeywordPlanKeywordOperation>(); foreach (KeywordPlanKeyword keywordPlanKeyword in keywordPlanKeywords) { operations.Add(new KeywordPlanKeywordOperation { Create = keywordPlanKeyword }); } // Add the keywords. MutateKeywordPlanKeywordsResponse response = serviceClient.MutateKeywordPlanKeywords(customerId.ToString(), operations); // Display the results. foreach (MutateKeywordPlanKeywordResult plankeywordResult in response.Results) { Console.WriteLine( $"Created keyword for keyword plan: {plankeywordResult.ResourceName}."); } return; }