Ejemplo n.º 1
0
 public Notification(RulesResult rulesResult)
 {
     Success = rulesResult.Success;
     if (!Success && rulesResult.RuleResults.Count > 1)
     {
         Errors = new List <ErrorInfo>();
     }
     rulesResult.RuleResults.Each(x => Errors.Add(new ErrorInfo(CoreLocalizationKeys.DELETE_EMPLOYEE.ToString(), x.Message)));
 }
Ejemplo n.º 2
0
        public async Task <RulesResult> EvaluateRules(ProjectDefinition projectDefinition, IList <RecommendationRuleItem> rules)
        {
            // If there are no rules the recipe must be invalid so don't include it.
            if (false == rules?.Any())
            {
                return(new RulesResult {
                    Include = false
                });
            }

            var availableTests = RecommendationTestFactory.LoadAvailableTests();
            var results        = new RulesResult {
                Include = true
            };

            foreach (var rule in rules)
            {
                var allTestPass = true;
                foreach (var test in rule.Tests)
                {
                    if (!availableTests.TryGetValue(test.Type, out var testInstance))
                    {
                        throw new InvalidRecipeDefinitionException($"Invalid test type [{test.Type}] found in rule.");
                    }

                    var input = new RecommendationTestInput
                    {
                        Test = test,
                        ProjectDefinition = projectDefinition,
                        Session           = _orchestratorSession
                    };
                    allTestPass &= await testInstance.Execute(input);

                    if (!allTestPass)
                    {
                        break;
                    }
                }

                results.Include &= ShouldInclude(rule.Effect, allTestPass);

                var effectOptions = GetEffectOptions(rule.Effect, allTestPass);

                if (effectOptions != null)
                {
                    if (effectOptions.PriorityAdjustment.HasValue)
                    {
                        results.PriorityAdjustment += effectOptions.PriorityAdjustment.Value;
                    }
                }
            }

            return(results);
        }
Ejemplo n.º 3
0
        public void Rules_RemoveOtherSetValues()
        {
            Mock <ICell> neighborCell = new Mock <ICell>();

            neighborCell.Setup(e => e.Value).Returns(1);
            neighbors.Add(neighborCell.Object);

            RulesResult rulesResult = rules.Process(cell.Object, neighbors);

            cell.Verify(e => e.RemovePossibleValue(1), Times.Once);
        }
Ejemplo n.º 4
0
        public void Rules_SetWhenOnly1ValueLeft()
        {
            cell.Setup(e => e.PossibleValues).Returns(new List <int>()
            {
                1
            });

            RulesResult rulesResult = rules.Process(cell.Object, neighbors);

            Assert.AreEqual(1, rulesResult.Value);
            Assert.AreEqual(0, rulesResult.RemovedPossible.Count);
        }
Ejemplo n.º 5
0
        public virtual RulesResult ExecuteRules()
        {
            RulesResult rulesResult = new RulesResult {Success = true};
            foreach (var rule in Rules.OrderBy(x=>x.Order))
            {
                if (rule.GetType().GetInterfaces().Any(x=>x.Name == "IRulesSet"))
                {
                    ((IRulesSet)rule).ProcessRulesSet(rulesResult);
                }
                if (rule.GetType() == typeof(RuleItemOperator))
                {

                }
            }
            return rulesResult;
        }
Ejemplo n.º 6
0
        public void Rules_FindOnlyValue()
        {
            cell.Setup(e => e.PossibleValues).Returns(new List <int>()
            {
                1, 3
            });
            Mock <ICell> neighborCell = new Mock <ICell>();

            neighborCell.Setup(e => e.PossibleValues).Returns(new List <int>()
            {
                2
            });
            neighbors.Add(neighborCell.Object);

            RulesResult rulesResult = rules.Process(cell.Object, neighbors);

            Assert.AreEqual(1, rulesResult.Value);
            Assert.AreEqual(0, rulesResult.RemovedPossible.Count);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns true if ordered quantity is within limit.
        /// </summary>
        /// <param name="eventProductList"></param>
        /// <param name="cart"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        bool ValidateMaxQtyDependsOnSpouseName(CartItemWithDetailList eventProductList, ShoppingCart_V02 cart, ShoppingCartRuleResult result)
        {
            bool ret = true;

            LoadSkuPurchasedCount(eventProductList, cart.DistributorID);

            foreach (var item in eventProductList)
            {
                if (item.TotalQty <= MaxQtyIfNoSpouseName)
                {
                    continue;
                }

                RulesResult rslt  = RulesResult.Unknown;
                string      msg   = null;
                int         limit = 0;

                var user = DistributorOrderingProfileProvider.GetProfile(cart.DistributorID, this.Country);
                if (string.IsNullOrWhiteSpace(user.SpouseLocalName))
                {
                    #region no spouse name
                    limit = MaxQtyIfNoSpouseName;

                    if (item.TotalQty > limit)
                    {
                        DeductEventProductQty(item, limit, cart);

                        rslt = (item.CurrentItem.Quantity <= 0) ? RulesResult.Failure : RulesResult.Feedback;

                        msg = GetRulesResourceString("EventProductLimitedToNAsNoSpouseName");
                        msg = string.Format(msg, item.SKU.Product.DisplayName, limit);
                    }
                    #endregion
                }
                else
                {
                    #region has spouse name
                    limit = MaxQtyIfHasSpouseName;
                    if (item.TotalQty > limit)
                    {
                        DeductEventProductQty(item, limit, cart);

                        rslt = (item.CurrentItem.Quantity <= 0) ? RulesResult.Failure : RulesResult.Feedback;

                        msg = GetRulesResourceString("EventProductLimitedToNAsHasSpouseName");
                        msg = string.Format(msg, item.SKU.Product.DisplayName, limit);
                    }
                    #endregion
                }

                if (rslt != RulesResult.Unknown)
                {
                    ret           = false;
                    result.Result = rslt;

                    if (item.QuantityAlreadyPurchased >= limit)
                    {
                        msg = GetRulesResourceString("EventProductAlreadyBeenPurchased");
                        msg = string.Format(msg, item.SKU.Product.DisplayName);
                    }

                    result.Messages.Add(msg);
                }

                LoggingTrace(string.Format("ValidateMaxQtyDependsOnSpouseName: {0}, {1}", rslt, msg));
            }

            return(ret);
        }
Ejemplo n.º 8
0
 public RulesResult ProcessRulesSet(RulesResult rulesResult)
 {
     Rules.Each(x =>
     {
         var ruleResult = x.Execute();
         if (!ruleResult.Success)
         {
             rulesResult.Success = false;
             rulesResult.Messages.Add(ruleResult.Message);
         }
     });
     return rulesResult;
 }
Ejemplo n.º 9
0
 public RulesResult ProcessRulesSet(RulesResult rulesResult)
 {
     var localRulesResult = new RulesResult {Success = true};
     Rules.Each(x =>
     {
         var ruleResult = x.Execute();
         if (!ruleResult.Success)
         {
             localRulesResult.Success = false;
             localRulesResult.Messages.Add(ruleResult.Message);
         }
     });
     if (localRulesResult.Success)
     {
         ChildRules.ProcessRulesSet(rulesResult);
     }
     return rulesResult;
 }
Ejemplo n.º 10
0
 public Notification(RulesResult rulesResult)
 {
     Success = rulesResult.Success;
     if(!Success && rulesResult.RuleResults.Count>1) Errors = new List<ErrorInfo>();
     rulesResult.RuleResults.Each(x => Errors.Add(new ErrorInfo(CoreLocalizationKeys.DELETE_EMPLOYEE.ToString(), x.Message)));
 }