public void Execute_First_Null_Arg_Test()
 {
     RuleEngine<Order> engine = new RuleEngine<Order>();
     Order order = new Order();
     string error;
     engine.Execute(null, ref order, out error);
 }
Beispiel #2
0
        public RoutingTable()
        {
            this.randomNumberGenerator = new Random();
            this.manager = new XPathMessageContext();

            this.ruleSet = GetRuleSetFromFile(ConfigurationManager.AppSettings["SelectDestinationRuleSetName"], ConfigurationManager.AppSettings["SelectDestinationRulesFile"]);
            this.ruleEngine = new RuleEngine(ruleSet, typeof(RoutingTable));
        }
 public void Execute_Null_OrderItem_Test()
 {
     RuleEngine<Order> engine = new RuleEngine<Order>();
     Order order = new Order();
     string error;
     engine.Execute(
         ConfigurationManager.AppSettings["RuleFilePath"],
         ref order,
         out error);
 }
        public void Execute_InValidRulePath_Test()
        {
            RuleEngine<Order> engine = new RuleEngine<Order>();
            Order order = new Order()
            {
                Items = new List<OrderItem>()
            };

            string error;
            Assert.IsTrue(engine.Execute(
                "test",
                ref order,
                out error));
        }
        public void Execute_Empty_Object_Test()
        {
            RuleEngine<Order> engine = new RuleEngine<Order>();
            Order order = new Order()
            {
                Items = new List<OrderItem>()
            };

            string error;
            Assert.IsTrue(engine.Execute(
                ConfigurationManager.AppSettings["RuleFilePath"],
                ref order,
                out error));
        }
        public void Execute_InValidRuleFile_Test()
        {
            RuleEngine<Order> engine = new RuleEngine<Order>();
            Order order = new Order()
            {
                Items = new List<OrderItem>()
            };

            string path = Environment.CurrentDirectory + "\\test.txt";
            using (var stream = File.Create(path))
            {
                stream.Close();
            }

            string error;
            Assert.IsTrue(engine.Execute(
                path,
                ref order,
                out error));
        }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            XmlReader reader = new XmlTextReader(RuleFilePath);
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            RuleDefinitions ruleDef = (RuleDefinitions)serializer.Deserialize(reader);
            reader.Close();

            // ルートアクティビティを取得
            Activity root = this;
            while (root.Parent != null)
                root = root.Parent;

            for (int i = 0; i < ruleDef.RuleSets.Count; i++)
            {
                RuleSet myRuleSet = ruleDef.RuleSets[i];
                RuleEngine ruleEng = new RuleEngine(myRuleSet, root.GetType());
                ruleEng.Execute(root, executionContext);
            }

            return base.Execute(executionContext);
        }
        public void Execute_InValidObjectForRule_Test()
        {
            RuleEngine<OrderItem> engine = new RuleEngine<OrderItem>();
            OrderItem orderItem = new OrderItem();

            string error;
            Assert.IsFalse(engine.Execute(
                ConfigurationManager.AppSettings["RuleFilePath"],
                ref orderItem,
                out error));
        }
        public void Execute_CustomerMoreThan2_LessThan_890_Test()
        {
            RuleEngine<Order> engine = new RuleEngine<Order>();
            var order = new Order
            {
                Id = 1,
                Customer = new Customer { RegisteredOnUtc = DateTime.UtcNow.AddYears(3) },
                Items = new List<OrderItem>()
            };

            order.Items.Add(new OrderItem
            {
                BasePricePerItem = 100,
                Quantity = 8,
                ItemType = ProductItemType.Apparel
            });

            order.Items.Add(new OrderItem
            {
                BasePricePerItem = 90,
                Quantity = 1,
                ItemType = ProductItemType.Grocery
            });

            string error;
            Assert.IsTrue(engine.Execute(
                ConfigurationManager.AppSettings["RuleFilePath"],
                ref order,
                out error));
            Assert.AreEqual(order.TotalOrderDiscounts, 40D + 40D);
        }
        public void Execute_Affiliate_LessThan_890_Test()
        {
            RuleEngine<Order> engine = new RuleEngine<Order>();
            var order = new Order
            {
                Id = 1,
                Customer = new Customer (),
                Items = new List<OrderItem>(),
                AffiliateId = "AFF-10"
            };

            order.Items.Add(new OrderItem
            {
                BasePricePerItem = 100,
                Quantity = 8,
                ItemType = ProductItemType.Apparel
            });

            order.Items.Add(new OrderItem
            {
                BasePricePerItem = 90,
                Quantity = 1,
                ItemType = ProductItemType.Grocery
            });

            string error;
            Assert.IsTrue(engine.Execute(
                ConfigurationManager.AppSettings["RuleFilePath"],
                ref order,
                out error));
            Assert.AreEqual(order.TotalOrderDiscounts, 80D + 40D);
        }
        public void Execute_EmployeeNoDiscountOnGrocery_LessThan_100_Test()
        {
            RuleEngine<Order> engine = new RuleEngine<Order>();
            var order = new Order
            {
                Id = 1,
                Customer = new Customer { IsEmployee = true },
                Items = new List<OrderItem>()
            };

            order.Items.Add(new OrderItem
            {
                BasePricePerItem = 50,
                Quantity = 1,
                ItemType = ProductItemType.Grocery
            });

            string error;
            Assert.IsTrue(engine.Execute(
                ConfigurationManager.AppSettings["RuleFilePath"],
                ref order,
                out error));
            Assert.AreEqual(order.TotalOrderDiscounts, 0D);
        }
Beispiel #12
0
        internal void Execute(Activity activity, ActivityExecutionContext executionContext)
        {
            // this can be called from multiple threads if multiple workflows are 
            // running at the same time (only a single workflow is single-threaded)
            // we want to only lock around the validation and preprocessing, so that
            // execution can run in parallel.

            if (activity == null)
                throw new ArgumentNullException("activity");

            Type activityType = activity.GetType();
            RuleEngine engine = null;
            lock (syncLock)
            {
                // do we have something useable cached?
                if ((cachedEngine == null) || (cachedValidation == null) || (cachedValidation.ThisType != activityType))
                {
                    // no cache (or its invalid)
                    RuleValidation validation = new RuleValidation(activityType, null);
                    engine = new RuleEngine(this, validation, executionContext);
                    cachedValidation = validation;
                    cachedEngine = engine;
                }
                else
                {
                    // this will happen if the ruleset has already been processed
                    // we can simply use the previously processed engine
                    engine = cachedEngine;
                }
            }

            // when we get here, we have a local RuleEngine all ready to go
            // we are outside the lock, so these can run in parallel
            engine.Execute(activity, executionContext);
        }
Beispiel #13
0
        public void Execute(RuleExecution ruleExecution)
        {
            // we have no way of knowing if the ruleset has been changed, so no caching done
            if (ruleExecution == null)
                throw new ArgumentNullException("ruleExecution");
            if (ruleExecution.Validation == null)
                throw new ArgumentException(SR.GetString(SR.Error_MissingValidationProperty), "ruleExecution");

            RuleEngine engine = new RuleEngine(this, ruleExecution.Validation, ruleExecution.ActivityExecutionContext);
            engine.Execute(ruleExecution);
        }