예제 #1
0
        public void ExecuteActions_should_mark_the_rule_as_triggered_once_complete()
        {
            // arrange
            var assertion = Guid.NewGuid().ToString();
            var newFact   = new Fact()
            {
                Assertion = assertion
            };
            var action = new AddRuleAction();

            action.SetFact(newFact);
            _rule.AddRuleAction(action);
            var facts = GenerateFacts();

            // act
            _rule.ExecuteActions(facts);

            // assert
            Assert.True(_rule.Triggered);
        }
예제 #2
0
        public void ExecuteActions_should_execute_actions_in_the_actions_collection_against_a_list_of_facts()
        {
            // arrange
            var assertion = Guid.NewGuid().ToString();
            var newFact   = new Fact()
            {
                Assertion = assertion
            };
            var action = new AddRuleAction();

            action.SetFact(newFact);
            _rule.AddRuleAction(action);
            var facts = GenerateFacts();

            // act
            _rule.ExecuteActions(facts);
            var result = facts.FirstOrDefault(x => x.Assertion == assertion);

            // assert
            Assert.NotNull(result);
        }
        private RuleBase SeedRuleBase(bool withMatch = true)
        {
            var assertion = withMatch ? "Has .NET" : "Has no .NET";

            var ruleBase = new RuleBase.Builder().Build();

            var rule = new Rule(Guid.Empty);
            var fact = new Fact()
            {
                Assertion = assertion
            };
            var precondition = new ContainsPrecondition.Builder()
                               .WithFact(fact)
                               .Build();

            rule.AddPrecondition(precondition);

            var action1 = new AddRuleAction();

            action1.SetFact(new Fact()
            {
                Assertion = "Potential C# experience"
            });

            var action2 = new AddRuleAction();

            action2.SetFact(new Fact()
            {
                Assertion = "Potential Angular experience"
            });

            rule.AddRuleAction(action1);
            rule.AddRuleAction(action2);

            ruleBase.AddRule(rule);

            return(ruleBase);
        }