Esempio n. 1
0
        //Complex Policy: more than 5 units and weights more than 100
        public async Task CheckAndProductPolicyAsync()
        {
            Assert.AreEqual(true, store.CheckPolicy(shoppingBasket));
            await marketRules.AddPolicyRule(store, store.GetFounder().Username, store.GetId(), PolicyRuleRelation.Simple, RuleContext.Product, RuleType.Quantity, productId : product.Id, valueGreaterEQThan : 5);

            await marketRules.AddPolicyRule(store, store.GetFounder().Username, store.GetId(), PolicyRuleRelation.And, RuleContext.Product, RuleType.Weight, productId : product.Id, valueGreaterEQThan : 100);

            Assert.AreEqual(true, store.CheckPolicy(shoppingBasket));
        }
        //Add New / Complex Policy
        public async Task AddPolicyRule(string username, Guid storeId, PolicyRuleRelation policyRuleRelation, RuleContext ruleContext, RuleType ruleType, string category = "", Guid productId = new Guid(),
                                        double valueLessThan = int.MaxValue, double valueGreaterEQThan = 0, DateTime d1 = default(DateTime), DateTime d2 = default(DateTime))
        {
            await StorePredicatesManager.Instance.SaveRequest(++counter, "AddPolicyRule", username, storeId, policyRuleRelation, ruleContext, ruleType, category, productId, valueLessThan, valueGreaterEQThan, d1, d2);

            await marketRules.AddPolicyRule(await MarketStores.Instance.GetStoreById(storeId), username, storeId, policyRuleRelation, ruleContext, ruleType, category, productId, valueLessThan, valueGreaterEQThan, d1, d2);

            var policyData = new PolicyData(username, storeId, policyRuleRelation, ruleContext, ruleType, category, productId, valueLessThan, valueGreaterEQThan, d1, d2);

            await this.policyManager.AddPolicy(policyData);
        }
 public void CheckSimpleLegalProductPolicy()
 {
     Assert.AreEqual(true, store.CheckPolicy(shoppingBasket));
     marketRules.AddPolicyRule(store, store.GetFounder().Username, store.GetId(), PolicyRuleRelation.Simple, RuleContext.Product, RuleType.Quantity, productId: product.Id, valueGreaterEQThan: 5);
     Assert.AreEqual(true, store.CheckPolicy(shoppingBasket));
 }