Exemple #1
0
        public void GetRecommendation()
        {
            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.MaximizeClicksOptIn,
                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,
            };

            mockGrpcClient.Setup(x => x.GetRecommendation(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            RecommendationServiceClient client   = new RecommendationServiceClientImpl(mockGrpcClient.Object, null);
            gagvr::Recommendation       response = client.GetRecommendation(request.ResourceName);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task GetRecommendationAsync()
        {
            Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict);
            GetRecommendationRequest expectedRequest = new GetRecommendationRequest
            {
                ResourceName = new RecommendationName("[CUSTOMER]", "[RECOMMENDATION]").ToString(),
            };
            Recommendation expectedResponse = new Recommendation
            {
                ResourceName = "resourceName2625949903",
            };

            mockGrpcClient.Setup(x => x.GetRecommendationAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Recommendation>(Task.FromResult(expectedResponse), null, null, null, null));
            RecommendationServiceClient client   = new RecommendationServiceClientImpl(mockGrpcClient.Object, null);
            string         formattedResourceName = new RecommendationName("[CUSTOMER]", "[RECOMMENDATION]").ToString();
            Recommendation response = await client.GetRecommendationAsync(formattedResourceName);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async Task DismissRecommendationAsync()
        {
            Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict);
            DismissRecommendationRequest expectedRequest = new DismissRecommendationRequest
            {
                CustomerId     = "customerId-1772061412",
                PartialFailure = true,
                Operations     = { },
            };
            DismissRecommendationResponse expectedResponse = new DismissRecommendationResponse();

            mockGrpcClient.Setup(x => x.DismissRecommendationAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <DismissRecommendationResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null);
            string customerId     = "customerId-1772061412";
            bool   partialFailure = true;
            IEnumerable <DismissRecommendationRequest.Types.DismissRecommendationOperation> operations = new List <DismissRecommendationRequest.Types.DismissRecommendationOperation>();
            DismissRecommendationResponse response = await client.DismissRecommendationAsync(customerId, partialFailure, operations);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void ApplyRecommendation()
        {
            Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict);
            ApplyRecommendationRequest expectedRequest = new ApplyRecommendationRequest
            {
                CustomerId     = "customerId-1772061412",
                PartialFailure = true,
                Operations     = { },
            };
            ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse();

            mockGrpcClient.Setup(x => x.ApplyRecommendation(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null);
            string customerId     = "customerId-1772061412";
            bool   partialFailure = true;
            IEnumerable <ApplyRecommendationOperation> operations = new List <ApplyRecommendationOperation>();
            ApplyRecommendationResponse response = client.ApplyRecommendation(customerId, partialFailure, operations);

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