示例#1
0
        public void GetCampaignBudgetRequestObject()
        {
            moq::Mock <CampaignBudgetService.CampaignBudgetServiceClient> mockGrpcClient = new moq::Mock <CampaignBudgetService.CampaignBudgetServiceClient>(moq::MockBehavior.Strict);
            GetCampaignBudgetRequest request = new GetCampaignBudgetRequest
            {
                ResourceNameAsCampaignBudgetName = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER]", "[CAMPAIGN_BUDGET]"),
            };
            gagvr::CampaignBudget expectedResponse = new gagvr::CampaignBudget
            {
                ResourceNameAsCampaignBudgetName = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER]", "[CAMPAIGN_BUDGET]"),
                Id = -6774108720365892680L,
                CampaignBudgetName            = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER]", "[CAMPAIGN_BUDGET]"),
                AmountMicros                  = -5708430407335026218L,
                Status                        = gagve::BudgetStatusEnum.Types.BudgetStatus.Enabled,
                DeliveryMethod                = gagve::BudgetDeliveryMethodEnum.Types.BudgetDeliveryMethod.Standard,
                ExplicitlyShared              = true,
                ReferenceCount                = -8440758895662409664L,
                TotalAmountMicros             = -8735537612243809071L,
                HasRecommendedBudget          = false,
                RecommendedBudgetAmountMicros = -5174015606152417050L,
                Period                        = gagve::BudgetPeriodEnum.Types.BudgetPeriod.Unknown,
                RecommendedBudgetEstimatedChangeWeeklyClicks       = 5003538975719544582L,
                RecommendedBudgetEstimatedChangeWeeklyCostMicros   = 6886876539534848907L,
                RecommendedBudgetEstimatedChangeWeeklyInteractions = -4068174795511900246L,
                RecommendedBudgetEstimatedChangeWeeklyViews        = -4598204636615893095L,
                Type = gagve::BudgetTypeEnum.Types.BudgetType.Unspecified,
            };

            mockGrpcClient.Setup(x => x.GetCampaignBudget(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            CampaignBudgetServiceClient client   = new CampaignBudgetServiceClientImpl(mockGrpcClient.Object, null);
            gagvr::CampaignBudget       response = client.GetCampaignBudget(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
示例#2
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        public void Run(GoogleAdsClient client, long customerId)
        {
            gagvr::CampaignBudget budget   = CreateBudget(client, customerId);
            gagvr::Campaign       campaign = CreateCampaign(client, customerId, budget.Id);
            gagvr::AdGroup        adGroup  = CreateAdGroup(client, customerId, campaign.Id);

            gagvr::AdGroupAd[]        adGroupAds      = CreateTextAds(client, customerId, adGroup.Id);
            gagvr::AdGroupCriterion[] adGroupCriteria = CreateKeywords(client, customerId,
                                                                       adGroup.Id, KEYWORDS_TO_ADD);
        }
示例#3
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The Google Ads user.</param>
        /// <param name="client">The Google Ads client.</param>
        public void Run(AdWordsUser user, GoogleAdsClient client)
        {
            // Note: The IDs returned for various entities by both APIs are the same, and can
            // be used interchangeably.
            long customerId = long.Parse((user.Config as AdWordsAppConfig).ClientCustomerId);

            gagvr::CampaignBudget budget   = CreateBudget(client, customerId);
            gagvr::Campaign       campaign = CreateCampaign(client, customerId, budget.Id);
            gagvr::AdGroup        adGroup  = CreateAdGroup(client, customerId, campaign.Id);

            gagvr::AdGroupAd[]     adGroupAds      = CreateTextAds(client, customerId, adGroup.Id);
            aw::AdGroupCriterion[] adGroupCriteria = CreateKeywords(user, adGroup.Id,
                                                                    KEYWORDS_TO_ADD);
        }
        public async stt::Task GetCampaignBudgetResourceNamesAsync()
        {
            moq::Mock <CampaignBudgetService.CampaignBudgetServiceClient> mockGrpcClient = new moq::Mock <CampaignBudgetService.CampaignBudgetServiceClient>(moq::MockBehavior.Strict);
            GetCampaignBudgetRequest request = new GetCampaignBudgetRequest
            {
                ResourceNameAsCampaignBudgetName = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER_ID]", "[CAMPAIGN_BUDGET_ID]"),
            };
            gagvr::CampaignBudget expectedResponse = new gagvr::CampaignBudget
            {
                ResourceNameAsCampaignBudgetName = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER_ID]", "[CAMPAIGN_BUDGET_ID]"),
                Status                        = gagve::BudgetStatusEnum.Types.BudgetStatus.Enabled,
                DeliveryMethod                = gagve::BudgetDeliveryMethodEnum.Types.BudgetDeliveryMethod.Standard,
                Period                        = gagve::BudgetPeriodEnum.Types.BudgetPeriod.Unspecified,
                Type                          = gagve::BudgetTypeEnum.Types.BudgetType.Unspecified,
                Id                            = -6774108720365892680L,
                CampaignBudgetName            = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER_ID]", "[CAMPAIGN_BUDGET_ID]"),
                AmountMicros                  = -5708430407335026218L,
                TotalAmountMicros             = -8735537612243809071L,
                ExplicitlyShared              = true,
                ReferenceCount                = -8440758895662409664L,
                HasRecommendedBudget          = false,
                RecommendedBudgetAmountMicros = -5174015606152417050L,
                RecommendedBudgetEstimatedChangeWeeklyClicks       = 5003538975719544582L,
                RecommendedBudgetEstimatedChangeWeeklyCostMicros   = 6886876539534848907L,
                RecommendedBudgetEstimatedChangeWeeklyInteractions = -4068174795511900246L,
                RecommendedBudgetEstimatedChangeWeeklyViews        = -4598204636615893095L,
            };

            mockGrpcClient.Setup(x => x.GetCampaignBudgetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gagvr::CampaignBudget>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            CampaignBudgetServiceClient client = new CampaignBudgetServiceClientImpl(mockGrpcClient.Object, null);
            gagvr::CampaignBudget       responseCallSettings = await client.GetCampaignBudgetAsync(request.ResourceNameAsCampaignBudgetName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            gagvr::CampaignBudget responseCancellationToken = await client.GetCampaignBudgetAsync(request.ResourceNameAsCampaignBudgetName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
示例#5
0
        /// <summary>
        /// Creates the budget.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <returns>The newly created budget instance.</returns>
        private static gagvr::CampaignBudget CreateBudget(GoogleAdsClient client, long customerId)
        {
            // Get the CampaignBudgetService.
            gagvs::CampaignBudgetServiceClient budgetService = client.GetService(
                Services.V6.CampaignBudgetService);

            // Create the campaign budget.
            gagvr::CampaignBudget budget = new gagvr::CampaignBudget()
            {
                Name           = "Interplanetary Cruise Budget #" + ExampleUtilities.GetRandomString(),
                DeliveryMethod = gag__BudgetDeliveryMethod.Standard,
                AmountMicros   = 500000
            };

            // Create the operation.
            gagvs::CampaignBudgetOperation budgetOperation = new gagvs::CampaignBudgetOperation()
            {
                Create = budget
            };

            // Create the campaign budget.
            gagvs::MutateCampaignBudgetsResponse response = budgetService.MutateCampaignBudgets(
                customerId.ToString(), new gagvs::CampaignBudgetOperation[] { budgetOperation });

            // Retrieve the newly created budget.
            string newResourceName = response.Results[0].ResourceName;
            gagvr::CampaignBudget newCampaignBudget =
                GetBudget(client, customerId, newResourceName);

            // Display the results.
            Console.WriteLine($"Budget with ID={newCampaignBudget.Id} and name=" +
                              $"'{newCampaignBudget.Name}' was created.");

            // Return the newly created budget.
            return(newCampaignBudget);
        }