Beispiel #1
0
        public void Example1Test()
        {
            var subject = new Example1Subject {
                IsTrue = true
            };
            var ruleEngine = RuleEngine <Example1Subject> .CreateTypedRuleEngine();

            ruleEngine.ExecuteAllRules(subject);

            Assert.AreEqual("hello world", subject.Greeting);
        }
Beispiel #2
0
        public void Example1Test()
        {
            var subject = new Example1Subject
            {
                Text = "Text"
            };
            var ruleEngine = RuleEngine <Example1Subject> .CreateTypedRuleEngine();

            var result = ruleEngine.ExecuteRuleSet(subject, "RuleSet1");

            Assert.IsFalse(result.HasRuleViolation);
        }
Beispiel #3
0
        public void Example1Test()
        {
            var subject = new Example1Subject
            {
                DueDate = DateTime.Today.AddDays(-1)
            };
            var ruleEngine = RuleEngine <Example1Subject> .CreateTypedRuleEngine();

            var results = ruleEngine.ExecuteAllRules(subject);

            Assert.IsFalse(results.HasRuleViolation);
        }
        public void Example1Test()
        {
            var subject = new Example1Subject
            {
                StartDate = new DateTime(2000, 1, 1),
                EndDate   = new DateTime(1999, 1, 1)
            };
            var ruleEngine = RuleEngine <Example1Subject> .CreateTypedRuleEngine();

            var result = ruleEngine.ExecuteAllRules(subject);

            Assert.IsTrue(result.HasRuleViolation);

            var ruleViolation = result.RuleViolations.Single();

            Assert.AreEqual(Resource.SectionB_StartDateMustComeAfterEndDate, ruleViolation.Message);
        }
Beispiel #5
0
        public void Example1Test()
        {
            var subject = new Example1Subject
            {
                Text = null
            };
            var ruleEngine = RuleEngine <Example1Subject> .CreateTypedRuleEngine();

            var result = ruleEngine.ExecuteAllRules(subject);

            Assert.IsTrue(result.HasRuleViolation);

            // The rule engine will let you know what object violated the rule
            var ruleViolation = result.RuleViolations.Single();

            Assert.AreSame(subject, ruleViolation.OffendingObject);

            // It will also let you know what properties are involved in the rule violation
            Assert.AreEqual("Text", ruleViolation.PropertyNames.Single());
        }