/// <summary> /// Creates negative keywords for the keyword plan. /// </summary> /// <param name="client">he Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="planCampaignResource">The resource name of the campaign under which the /// keyword is created.</param> private static void CreateKeywordPlanNegativeKeywords(GoogleAdsClient client, long customerId, string planCampaignResource) { // Get the KeywordPlanNegativeKeywordService. KeywordPlanNegativeKeywordServiceClient serviceClient = client.GetService( Services.V1.KeywordPlanNegativeKeywordService); // Create the negative keyword for the keyword plan. KeywordPlanNegativeKeyword keywordPlanNegativeKeyword = new KeywordPlanNegativeKeyword() { KeywordPlanCampaign = planCampaignResource, MatchType = KeywordMatchType.Broad, Text = "moon walk" }; KeywordPlanNegativeKeywordOperation operation = new KeywordPlanNegativeKeywordOperation { Create = keywordPlanNegativeKeyword }; // Add the negative keyword. MutateKeywordPlanNegativeKeywordsResponse response = serviceClient.MutateKeywordPlanNegativeKeywords(customerId.ToString(), new KeywordPlanNegativeKeywordOperation[] { operation }); // Display the result. MutateKeywordPlanNegativeKeywordResult planNegativeKeywordResult = response.Results[0]; Console.WriteLine("Created negative keyword for keyword plan: " + $"{planNegativeKeywordResult.ResourceName}."); return; }
public void GetKeywordPlanNegativeKeyword2() { Mock <KeywordPlanNegativeKeywordService.KeywordPlanNegativeKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanNegativeKeywordService.KeywordPlanNegativeKeywordServiceClient>(MockBehavior.Strict); GetKeywordPlanNegativeKeywordRequest request = new GetKeywordPlanNegativeKeywordRequest { ResourceName = new KeywordPlanNegativeKeywordName("[CUSTOMER]", "[KEYWORD_PLAN_NEGATIVE_KEYWORD]").ToString(), }; KeywordPlanNegativeKeyword expectedResponse = new KeywordPlanNegativeKeyword { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetKeywordPlanNegativeKeyword(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); KeywordPlanNegativeKeywordServiceClient client = new KeywordPlanNegativeKeywordServiceClientImpl(mockGrpcClient.Object, null); KeywordPlanNegativeKeyword response = client.GetKeywordPlanNegativeKeyword(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task GetKeywordPlanNegativeKeywordAsync() { Mock <KeywordPlanNegativeKeywordService.KeywordPlanNegativeKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanNegativeKeywordService.KeywordPlanNegativeKeywordServiceClient>(MockBehavior.Strict); GetKeywordPlanNegativeKeywordRequest expectedRequest = new GetKeywordPlanNegativeKeywordRequest { ResourceName = new KeywordPlanNegativeKeywordName("[CUSTOMER]", "[KEYWORD_PLAN_NEGATIVE_KEYWORD]").ToString(), }; KeywordPlanNegativeKeyword expectedResponse = new KeywordPlanNegativeKeyword { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetKeywordPlanNegativeKeywordAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <KeywordPlanNegativeKeyword>(Task.FromResult(expectedResponse), null, null, null, null)); KeywordPlanNegativeKeywordServiceClient client = new KeywordPlanNegativeKeywordServiceClientImpl(mockGrpcClient.Object, null); string formattedResourceName = new KeywordPlanNegativeKeywordName("[CUSTOMER]", "[KEYWORD_PLAN_NEGATIVE_KEYWORD]").ToString(); KeywordPlanNegativeKeyword response = await client.GetKeywordPlanNegativeKeywordAsync(formattedResourceName); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }