public async Task GetCampaignAsync2() { Mock <CampaignService.CampaignServiceClient> mockGrpcClient = new Mock <CampaignService.CampaignServiceClient>(MockBehavior.Strict); GetCampaignRequest request = new GetCampaignRequest { ResourceName = new CampaignName("[CUSTOMER]", "[CAMPAIGN]").ToString(), }; Campaign expectedResponse = new Campaign { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetCampaignAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Campaign>(Task.FromResult(expectedResponse), null, null, null, null)); CampaignServiceClient client = new CampaignServiceClientImpl(mockGrpcClient.Object, null); Campaign response = await client.GetCampaignAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task GetCampaignResourceNamesAsync() { moq::Mock <CampaignService.CampaignServiceClient> mockGrpcClient = new moq::Mock <CampaignService.CampaignServiceClient>(moq::MockBehavior.Strict); GetCampaignRequest request = new GetCampaignRequest { ResourceNameAsCampaignName = gagvr::CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]"), }; gagvr::Campaign expectedResponse = new gagvr::Campaign { ResourceNameAsCampaignName = gagvr::CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]"), Id = -6774108720365892680L, CampaignName = gagvr::CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]"), Status = gagve::CampaignStatusEnum.Types.CampaignStatus.Removed, CampaignBudgetAsCampaignBudgetName = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER]", "[CAMPAIGN_BUDGET]"), AdServingOptimizationStatus = gagve::AdServingOptimizationStatusEnum.Types.AdServingOptimizationStatus.ConversionOptimize, AdvertisingChannelType = gagve::AdvertisingChannelTypeEnum.Types.AdvertisingChannelType.MultiChannel, AdvertisingChannelSubType = gagve::AdvertisingChannelSubTypeEnum.Types.AdvertisingChannelSubType.VideoOutstream, TrackingUrlTemplate = "tracking_url_template157f152a", UrlCustomParameters = { new gagvc::CustomParameter(), }, NetworkSettings = new gagvr::Campaign.Types.NetworkSettings(), ExperimentType = gagve::CampaignExperimentTypeEnum.Types.CampaignExperimentType.Unknown, StartDate = "start_date11b9dbea", EndDate = "end_date89dae890", ServingStatus = gagve::CampaignServingStatusEnum.Types.CampaignServingStatus.Ended, BiddingStrategyType = gagve::BiddingStrategyTypeEnum.Types.BiddingStrategyType.TargetCpa, BiddingStrategyAsBiddingStrategyName = gagvr::BiddingStrategyName.FromCustomerBiddingStrategy("[CUSTOMER]", "[BIDDING_STRATEGY]"), ManualCpc = new gagvc::ManualCpc(), ManualCpm = new gagvc::ManualCpm(), TargetCpa = new gagvc::TargetCpa(), TargetSpend = new gagvc::TargetSpend(), BaseCampaignAsCampaignName = gagvr::CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]"), TargetRoas = new gagvc::TargetRoas(), MaximizeConversions = new gagvc::MaximizeConversions(), MaximizeConversionValue = new gagvc::MaximizeConversionValue(), HotelSetting = new gagvr::Campaign.Types.HotelSettingInfo(), DynamicSearchAdsSetting = new gagvr::Campaign.Types.DynamicSearchAdsSetting(), PercentCpc = new gagvc::PercentCpc(), ShoppingSetting = new gagvr::Campaign.Types.ShoppingSetting(), ManualCpv = new gagvc::ManualCpv(), FinalUrlSuffix = "final_url_suffix046ed37a", RealTimeBiddingSetting = new gagvc::RealTimeBiddingSetting(), FrequencyCaps = { new gagvc::FrequencyCapEntry(), }, TargetCpm = new gagvc::TargetCpm(), VideoBrandSafetySuitability = gagve::BrandSafetySuitabilityEnum.Types.BrandSafetySuitability.Unknown, TargetingSetting = new gagvc::TargetingSetting(), VanityPharma = new gagvr::Campaign.Types.VanityPharma(), SelectiveOptimization = new gagvr::Campaign.Types.SelectiveOptimization(), TrackingSetting = new gagvr::Campaign.Types.TrackingSetting(), GeoTargetTypeSetting = new gagvr::Campaign.Types.GeoTargetTypeSetting(), TargetImpressionShare = new gagvc::TargetImpressionShare(), Commission = new gagvc::Commission(), AppCampaignSetting = new gagvr::Campaign.Types.AppCampaignSetting(), PaymentMode = gagve::PaymentModeEnum.Types.PaymentMode.Clicks, LabelsAsCampaignLabelNames = { gagvr::CampaignLabelName.FromCustomerCampaignLabel("[CUSTOMER]", "[CAMPAIGN_LABEL]"), }, OptimizationScore = -4.7741588361660064E+17, }; mockGrpcClient.Setup(x => x.GetCampaignAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gagvr::Campaign>(stt::Task.FromResult(expectedResponse), null, null, null, null)); CampaignServiceClient client = new CampaignServiceClientImpl(mockGrpcClient.Object, null); gagvr::Campaign responseCallSettings = await client.GetCampaignAsync(request.ResourceNameAsCampaignName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); gagvr::Campaign responseCancellationToken = await client.GetCampaignAsync(request.ResourceNameAsCampaignName, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }