public void GetRecommendationRequestObject() { moq::Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new moq::Mock <RecommendationService.RecommendationServiceClient>(moq::MockBehavior.Strict); GetRecommendationRequest request = new GetRecommendationRequest { ResourceNameAsRecommendationName = gagvr::RecommendationName.FromCustomerRecommendation("[CUSTOMER]", "[RECOMMENDATION]"), }; gagvr::Recommendation expectedResponse = new gagvr::Recommendation { ResourceNameAsRecommendationName = gagvr::RecommendationName.FromCustomerRecommendation("[CUSTOMER]", "[RECOMMENDATION]"), Type = gagve::RecommendationTypeEnum.Types.RecommendationType.EnhancedCpcOptIn, Impact = new gagvr::Recommendation.Types.RecommendationImpact(), CampaignBudgetRecommendation = new gagvr::Recommendation.Types.CampaignBudgetRecommendation(), CampaignBudgetAsCampaignBudgetName = gagvr::CampaignBudgetName.FromCustomerCampaignBudget("[CUSTOMER]", "[CAMPAIGN_BUDGET]"), CampaignAsCampaignName = gagvr::CampaignName.FromCustomerCampaign("[CUSTOMER]", "[CAMPAIGN]"), AdGroupAsAdGroupName = gagvr::AdGroupName.FromCustomerAdGroup("[CUSTOMER]", "[AD_GROUP]"), 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(), Dismissed = true, 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(), }; 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); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
// Partial methods called on each request. // Allows per-RPC-call modification to the request and CallSettings objects, // before the underlying RPC is performed. partial void Modify_GetRecommendationRequest(ref GetRecommendationRequest request, ref gaxgrpc::CallSettings settings);
/// <summary> /// Returns the requested recommendation in full detail. /// </summary> /// <param name="request"> /// The request object containing all of the parameters for the API call. /// </param> /// <param name="callSettings"> /// If not null, applies overrides to this RPC call. /// </param> /// <returns> /// The RPC response. /// </returns> public virtual gagvr::Recommendation GetRecommendation( GetRecommendationRequest request, gaxgrpc::CallSettings callSettings = null) { throw new sys::NotImplementedException(); }
/// <summary> /// Returns the requested recommendation in full detail. /// </summary> /// <param name="request"> /// The request object containing all of the parameters for the API call. /// </param> /// <param name="cancellationToken"> /// A <see cref="st::CancellationToken"/> to use for this RPC. /// </param> /// <returns> /// A Task containing the RPC response. /// </returns> public virtual stt::Task <gagvr::Recommendation> GetRecommendationAsync( GetRecommendationRequest request, st::CancellationToken cancellationToken) => GetRecommendationAsync( request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
/// <summary> /// Creates a waiter using the provided configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="config">Wait Configuration</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <GetRecommendationRequest, GetRecommendationResponse> ForRecommendation(GetRecommendationRequest request, WaiterConfiguration config, params LifecycleState[] targetStates) { var agent = new WaiterAgent <GetRecommendationRequest, GetRecommendationResponse>( request, request => client.GetRecommendation(request), response => targetStates.Contains(response.Recommendation.LifecycleState.Value), targetStates.Contains(LifecycleState.Deleted) ); return(new Waiter <GetRecommendationRequest, GetRecommendationResponse>(config, agent)); }
/// <summary> /// Creates a waiter using default wait configuration. /// </summary> /// <param name="request">Request to send.</param> /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param> /// <returns>a new Oci.common.Waiter instance</returns> public Waiter <GetRecommendationRequest, GetRecommendationResponse> ForRecommendation(GetRecommendationRequest request, params LifecycleState[] targetStates) { return(this.ForRecommendation(request, WaiterConfiguration.DefaultWaiterConfiguration, targetStates)); }
public async Task <IDictionary <int, int> > GetRecommended(GetRecommendationRequest request, int?amount = null) { await _dbContext.Properties.ToListAsync(); await _dbContext.PropertyValues.ToListAsync(); await _dbContext.SelectionProperties.ToListAsync(); DateTime thresholdDate = DateTime.Today; switch (request.SelectionTimeSpan) { case SelectionTimeSpan.Year: { thresholdDate = DateTime.Now.Subtract(new TimeSpan(365, 0, 0, 0)); break; } case SelectionTimeSpan.Month: { thresholdDate = DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0)); break; } case SelectionTimeSpan.Week: { thresholdDate = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)); break; } case SelectionTimeSpan.Day: { thresholdDate = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)); break; } } if (amount.HasValue && amount.Value > 0) { var list = await _dbContext.Selections. Where(e => e.ComponentType == request.ComponentType && //Select only component types that apply e.Properties.All(v => request.Properties.ContainsKey(v.PropertyValue.Property.Name) && //Check if all of the properties are in the selection record request.Properties[v.PropertyValue.Property.Name] == v.PropertyValue.Value) && //And properties values are equal e.Date >= thresholdDate). //Select only records with date newer than threshold GroupBy(e => e.ElementID). //Group by element ID Select(e => new { e.Key, Sum = e.Sum(v => 1) }). //Select only element ID and amount of selections OrderByDescending(e => e.Sum). //Order by descending to get top elements Take(amount.Value). ToDictionaryAsync(e => e.Key, e => e.Sum); return(list); } else { var list = await _dbContext.Selections. Where(e => e.ComponentType == request.ComponentType && //Select only component types that apply e.Properties.All(v => request.Properties.ContainsKey(v.PropertyValue.Property.Name) && //Check if all of the properties are in the selection record request.Properties[v.PropertyValue.Property.Name] == v.PropertyValue.Value) && //And properties values are equal e.Date >= thresholdDate). //Select only records with date newer than threshold GroupBy(e => e.ElementID). //Group by element ID Select(e => new { e.Key, Sum = e.Sum(v => 1) }). //Select only element ID and amount of selections OrderByDescending(e => e.Sum). //Order by descending to get top elements ToDictionaryAsync(e => e.Key, e => e.Sum); return(list); } }