コード例 #1
0
        public async stt::Task GetRecommendationRequestObjectAsync()
        {
            moq::Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new moq::Mock <RecommendationService.RecommendationServiceClient>(moq::MockBehavior.Strict);
            GetRecommendationRequest request = new GetRecommendationRequest
            {
                ResourceNameAsRecommendationName = gagvr::RecommendationName.FromCustomerRecommendation("[CUSTOMER_ID]", "[RECOMMENDATION_ID]"),
            };
            gagvr::Recommendation expectedResponse = new gagvr::Recommendation
            {
                ResourceNameAsRecommendationName = gagvr::RecommendationName.FromCustomerRecommendation("[CUSTOMER_ID]", "[RECOMMENDATION_ID]"),
                Type   = gagve::RecommendationTypeEnum.Types.RecommendationType.MoveUnusedBudget,
                Impact = new gagvr::Recommendation.Types.RecommendationImpact(),
                CampaignBudgetRecommendation            = new gagvr::Recommendation.Types.CampaignBudgetRecommendation(),
                KeywordRecommendation                   = new gagvr::Recommendation.Types.KeywordRecommendation(),
                TextAdRecommendation                    = new gagvr::Recommendation.Types.TextAdRecommendation(),
                TargetCpaOptInRecommendation            = new gagvr::Recommendation.Types.TargetCpaOptInRecommendation(),
                MaximizeConversionsOptInRecommendation  = new gagvr::Recommendation.Types.MaximizeConversionsOptInRecommendation(),
                EnhancedCpcOptInRecommendation          = new gagvr::Recommendation.Types.EnhancedCpcOptInRecommendation(),
                SearchPartnersOptInRecommendation       = new gagvr::Recommendation.Types.SearchPartnersOptInRecommendation(),
                MaximizeClicksOptInRecommendation       = new gagvr::Recommendation.Types.MaximizeClicksOptInRecommendation(),
                OptimizeAdRotationRecommendation        = new gagvr::Recommendation.Types.OptimizeAdRotationRecommendation(),
                CalloutExtensionRecommendation          = new gagvr::Recommendation.Types.CalloutExtensionRecommendation(),
                SitelinkExtensionRecommendation         = new gagvr::Recommendation.Types.SitelinkExtensionRecommendation(),
                CallExtensionRecommendation             = new gagvr::Recommendation.Types.CallExtensionRecommendation(),
                KeywordMatchTypeRecommendation          = new gagvr::Recommendation.Types.KeywordMatchTypeRecommendation(),
                MoveUnusedBudgetRecommendation          = new gagvr::Recommendation.Types.MoveUnusedBudgetRecommendation(),
                ForecastingCampaignBudgetRecommendation = new gagvr::Recommendation.Types.CampaignBudgetRecommendation(),
                TargetRoasOptInRecommendation           = new gagvr::Recommendation.Types.TargetRoasOptInRecommendation(),
                CampaignBudgetAsCampaignBudgetName      = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER_ID]", "[CAMPAIGN_BUDGET_ID]"),
                CampaignAsCampaignName                  = gagvr::CampaignName.FromCustomerCampaign("[CUSTOMER_ID]", "[CAMPAIGN_ID]"),
                AdGroupAsAdGroupName                    = gagvr::AdGroupName.FromCustomerAdGroup("[CUSTOMER_ID]", "[AD_GROUP_ID]"),
                Dismissed = true,
                ResponsiveSearchAdRecommendation        = new gagvr::Recommendation.Types.ResponsiveSearchAdRecommendation(),
                MarginalRoiCampaignBudgetRecommendation = new gagvr::Recommendation.Types.CampaignBudgetRecommendation(),
            };

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

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

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetRecommendationAsync2()
        {
            Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict);
            GetRecommendationRequest request = new GetRecommendationRequest
            {
                ResourceName = new RecommendationName("[CUSTOMER]", "[RECOMMENDATION]").ToString(),
            };
            Recommendation expectedResponse = new Recommendation
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetRecommendationAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Recommendation>(Task.FromResult(expectedResponse), null, null, null, null));
            RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null);
            Recommendation response            = await client.GetRecommendationAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }