public void GetKeywordPlanKeyword2()
        {
            Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(MockBehavior.Strict);
            GetKeywordPlanKeywordRequest request = new GetKeywordPlanKeywordRequest
            {
                ResourceName = new KeywordPlanKeywordName("[CUSTOMER]", "[KEYWORD_PLAN_KEYWORD]").ToString(),
            };
            KeywordPlanKeyword expectedResponse = new KeywordPlanKeyword
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetKeywordPlanKeyword(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null);
            KeywordPlanKeyword response            = client.GetKeywordPlanKeyword(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetKeywordPlanKeywordAsync2()
        {
            Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient> mockGrpcClient = new Mock <KeywordPlanKeywordService.KeywordPlanKeywordServiceClient>(MockBehavior.Strict);
            GetKeywordPlanKeywordRequest request = new GetKeywordPlanKeywordRequest
            {
                ResourceName = new KeywordPlanKeywordName("[CUSTOMER]", "[KEYWORD_PLAN_KEYWORD]").ToString(),
            };
            KeywordPlanKeyword expectedResponse = new KeywordPlanKeyword
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetKeywordPlanKeywordAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <KeywordPlanKeyword>(Task.FromResult(expectedResponse), null, null, null, null));
            KeywordPlanKeywordServiceClient client = new KeywordPlanKeywordServiceClientImpl(mockGrpcClient.Object, null);
            KeywordPlanKeyword response            = await client.GetKeywordPlanKeywordAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 3
0
        /// <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;
        }