public async Task GetAdAsync2()
        {
            Mock <AdService.AdServiceClient> mockGrpcClient = new Mock <AdService.AdServiceClient>(MockBehavior.Strict);
            GetAdRequest request = new GetAdRequest
            {
                ResourceName = new AdName("[CUSTOMER]", "[AD]").ToString(),
            };
            Ad expectedResponse = new Ad
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetAdAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Ad>(Task.FromResult(expectedResponse), null, null, null, null));
            AdServiceClient client = new AdServiceClientImpl(mockGrpcClient.Object, null);
            Ad response            = await client.GetAdAsync(request);

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