public void GetAdRequestObject()
        {
            moq::Mock <AdService.AdServiceClient> mockGrpcClient = new moq::Mock <AdService.AdServiceClient>(moq::MockBehavior.Strict);
            GetAdRequest request = new GetAdRequest
            {
                ResourceNameAsAdName = gagvr::AdName.FromCustomerAd("[CUSTOMER_ID]", "[AD_ID]"),
            };
            gagvr::Ad expectedResponse = new gagvr::Ad
            {
                Type                = gagve::AdTypeEnum.Types.AdType.ShoppingProductAd,
                TextAd              = new gagvc::TextAdInfo(),
                ExpandedTextAd      = new gagvc::ExpandedTextAdInfo(),
                UrlCustomParameters =
                {
                    new gagvc::CustomParameter(),
                },
                ExpandedDynamicSearchAd = new gagvc::ExpandedDynamicSearchAdInfo(),
                HotelAd            = new gagvc::HotelAdInfo(),
                ShoppingSmartAd    = new gagvc::ShoppingSmartAdInfo(),
                ShoppingProductAd  = new gagvc::ShoppingProductAdInfo(),
                DevicePreference   = gagve::DeviceEnum.Types.Device.Desktop,
                GmailAd            = new gagvc::GmailAdInfo(),
                ImageAd            = new gagvc::ImageAdInfo(),
                VideoAd            = new gagvc::VideoAdInfo(),
                ResponsiveSearchAd = new gagvc::ResponsiveSearchAdInfo(),
                UrlCollections     =
                {
                    new gagvc::UrlCollection(),
                },
                SystemManagedResourceSource = gagve::SystemManagedResourceSourceEnum.Types.SystemManagedResourceSource.AdVariations,
                LegacyResponsiveDisplayAd   = new gagvc::LegacyResponsiveDisplayAdInfo(),
                AppAd = new gagvc::AppAdInfo(),
                LegacyAppInstallAd  = new gagvc::LegacyAppInstallAdInfo(),
                ResponsiveDisplayAd = new gagvc::ResponsiveDisplayAdInfo(),
                LocalAd             = new gagvc::LocalAdInfo(),
                DisplayUploadAd     = new gagvc::DisplayUploadAdInfo(),
                AppEngagementAd     = new gagvc::AppEngagementAdInfo(),
                FinalAppUrls        =
                {
                    new gagvc::FinalAppUrl(),
                },
                ShoppingComparisonListingAd = new gagvc::ShoppingComparisonListingAdInfo(),
                ResourceNameAsAdName        = gagvr::AdName.FromCustomerAd("[CUSTOMER_ID]", "[AD_ID]"),
                VideoResponsiveAd           = new gagvc::VideoResponsiveAdInfo(),
                Id        = -6774108720365892680L,
                FinalUrls =
                {
                    "final_urls3ed0b71b",
                },
                FinalMobileUrls =
                {
                    "final_mobile_urlsf4131aa0",
                },
                TrackingUrlTemplate = "tracking_url_template157f152a",
                FinalUrlSuffix      = "final_url_suffix046ed37a",
                DisplayUrl          = "display_url12de0d0c",
                AddedByGoogleAds    = true,
                AdName                = gagvr::AdName.FromCustomerAd("[CUSTOMER_ID]", "[AD_ID]"),
                SmartCampaignAd       = new gagvc::SmartCampaignAdInfo(),
                CallAd                = new gagvc::CallAdInfo(),
                AppPreRegistrationAd  = new gagvc::AppPreRegistrationAdInfo(),
                DiscoveryMultiAssetAd = new gagvc::DiscoveryMultiAssetAdInfo(),
                DiscoveryCarouselAd   = new gagvc::DiscoveryCarouselAdInfo(),
            };

            mockGrpcClient.Setup(x => x.GetAd(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AdServiceClient client   = new AdServiceClientImpl(mockGrpcClient.Object, null);
            gagvr::Ad       response = client.GetAd(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Beispiel #2
0
        public async stt::Task GetAdResourceNamesAsync()
        {
            moq::Mock <AdService.AdServiceClient> mockGrpcClient = new moq::Mock <AdService.AdServiceClient>(moq::MockBehavior.Strict);
            GetAdRequest request = new GetAdRequest
            {
                ResourceNameAsAdName = gagvr::AdName.FromCustomerAd("[CUSTOMER]", "[AD]"),
            };
            gagvr::Ad expectedResponse = new gagvr::Ad
            {
                Id        = -6774108720365892680L,
                FinalUrls =
                {
                    "final_urls3ed0b71b",
                },
                DisplayUrl          = "display_url12de0d0c",
                Type                = gagve::AdTypeEnum.Types.AdType.ImageAd,
                TextAd              = new gagvc::TextAdInfo(),
                ExpandedTextAd      = new gagvc::ExpandedTextAdInfo(),
                UrlCustomParameters =
                {
                    new gagvc::CustomParameter(),
                },
                TrackingUrlTemplate     = "tracking_url_template157f152a",
                CallOnlyAd              = new gagvc::CallOnlyAdInfo(),
                ExpandedDynamicSearchAd = new gagvc::ExpandedDynamicSearchAdInfo(),
                HotelAd         = new gagvc::HotelAdInfo(),
                FinalMobileUrls =
                {
                    "final_mobile_urlsf4131aa0",
                },
                ShoppingSmartAd    = new gagvc::ShoppingSmartAdInfo(),
                ShoppingProductAd  = new gagvc::ShoppingProductAdInfo(),
                AddedByGoogleAds   = true,
                DevicePreference   = gagve::DeviceEnum.Types.Device.Desktop,
                GmailAd            = new gagvc::GmailAdInfo(),
                ImageAd            = new gagvc::ImageAdInfo(),
                AdName             = gagvr::AdName.FromCustomerAd("[CUSTOMER]", "[AD]"),
                VideoAd            = new gagvc::VideoAdInfo(),
                ResponsiveSearchAd = new gagvc::ResponsiveSearchAdInfo(),
                UrlCollections     =
                {
                    new gagvc::UrlCollection(),
                },
                SystemManagedResourceSource = gagve::SystemManagedResourceSourceEnum.Types.SystemManagedResourceSource.AdVariations,
                LegacyResponsiveDisplayAd   = new gagvc::LegacyResponsiveDisplayAdInfo(),
                AppAd = new gagvc::AppAdInfo(),
                LegacyAppInstallAd  = new gagvc::LegacyAppInstallAdInfo(),
                ResponsiveDisplayAd = new gagvc::ResponsiveDisplayAdInfo(),
                LocalAd             = new gagvc::LocalAdInfo(),
                DisplayUploadAd     = new gagvc::DisplayUploadAdInfo(),
                AppEngagementAd     = new gagvc::AppEngagementAdInfo(),
                FinalAppUrls        =
                {
                    new gagvc::FinalAppUrl(),
                },
                ShoppingComparisonListingAd = new gagvc::ShoppingComparisonListingAdInfo(),
                ResourceNameAsAdName        = gagvr::AdName.FromCustomerAd("[CUSTOMER]", "[AD]"),
                FinalUrlSuffix = "final_url_suffix046ed37a",
            };

            mockGrpcClient.Setup(x => x.GetAdAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gagvr::Ad>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AdServiceClient client = new AdServiceClientImpl(mockGrpcClient.Object, null);
            gagvr::Ad       responseCallSettings = await client.GetAdAsync(request.ResourceNameAsAdName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            Assert.AreEqual(expectedResponse, responseCallSettings);
            gagvr::Ad responseCancellationToken = await client.GetAdAsync(request.ResourceNameAsAdName, st::CancellationToken.None);

            Assert.AreEqual(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Beispiel #3
0
        /// <summary>
        /// Creates the text ads.
        /// </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="adGroupId">ID of the ad group in which ads are created.</param>
        /// <returns>The newly created ad group ad instances.</returns>
        private gagvr::AdGroupAd[] CreateTextAds(GoogleAdsClient client, long customerId,
                                                 long adGroupId)
        {
            // Get the AdGroupAdService.
            gagvs::AdGroupAdServiceClient adGroupAdService = client.GetService(
                Services.V6.AdGroupAdService);

            List <gagvs::AdGroupAdOperation> operations = new List <gagvs::AdGroupAdOperation>();

            for (int i = 0; i < NUMBER_OF_ADS; i++)
            {
                // Create the ad group ad object.
                gagvr::AdGroupAd adGroupAd = new gagvr::AdGroupAd
                {
                    AdGroup = gagver::ResourceNames.AdGroup(customerId, adGroupId),
                    // Optional: Set the status.
                    Status = gag__AdGroupAdStatus.Paused,
                    Ad     = new gagvr::Ad
                    {
                        FinalUrls      = { "http://www.example.com/" + i },
                        ExpandedTextAd = new gagvc::ExpandedTextAdInfo
                        {
                            Description   = "Buy your tickets now!",
                            HeadlinePart1 = "Cruise #" + i.ToString() + " to Mars",
                            HeadlinePart2 = "Best Space Cruise Line",
                            Path1         = "path1",
                            Path2         = "path2"
                        }
                    }
                };

                // Create the operation.
                operations.Add(new gagvs::AdGroupAdOperation
                {
                    Create = adGroupAd
                });
            }

            // Create the ads.
            gagvs::MutateAdGroupAdsResponse response = adGroupAdService.MutateAdGroupAds(
                customerId.ToString(), operations);

            // Retrieve the newly created ad group ads.
            List <string> newResourceNames =
                response.Results.Select(result => result.ResourceName).ToList();

            gagvr::AdGroupAd[] newAdGroupAds = GetAdGroupAds(client, customerId, newResourceNames);

            // Display the results.
            foreach (gagvr::AdGroupAd newAdGroupAd in newAdGroupAds)
            {
                gagvr::Ad ad = newAdGroupAd.Ad;
                gagvc::ExpandedTextAdInfo expandedTextAdInfo = ad.ExpandedTextAd;
                Console.WriteLine("Expanded text ad with ID {0}, status '{1}', and headline " +
                                  "'{2} - {3}' was found in ad group with ID {4}.",
                                  ad.Id, newAdGroupAd.Status, expandedTextAdInfo.HeadlinePart1,
                                  expandedTextAdInfo.HeadlinePart2, adGroupId);
            }

            // Return the newly created ad group ads.
            return(newAdGroupAds);
        }