Exemplo n.º 1
0
        public void Example2Test()
        {
            var subject = new Example2Subject {
                IsTrue = false
            };
            var ruleEngine = RuleEngine <Example2Subject> .CreateTypedRuleEngine();

            ruleEngine.ExecuteAllRules(subject);

            Assert.AreEqual("goodbye cruel world", subject.Greeting);
        }
Exemplo n.º 2
0
        public void Example2Test()
        {
            var subject = new Example2Subject
            {
                StartDate = new DateTime(2000, 1, 1),
                EndDate   = new DateTime(1999, 1, 1)
            };
            var ruleEngine = RuleEngine <Example2Subject> .CreateTypedRuleEngine();

            var result = ruleEngine.ExecuteAllRules(subject);

            Assert.IsTrue(result.HasRuleViolation);

            var ruleViolation = result.RuleViolations.Single();

            Assert.AreEqual(Resource.SectionB_StartDateMustComeAfterEndDate, ruleViolation.Message);
        }
Exemplo n.º 3
0
        public void Example2Test()
        {
            var subject = new Example2Subject
            {
                EmailAddress = "InvalidEmailAddress"
            };
            var ruleEngine = RuleEngine <Example2Subject> .CreateTypedRuleEngine();

            var result = ruleEngine.ExecuteAllRules(subject);

            // Since FavoriteFruit is not null but it isn't a valid email address
            Assert.IsTrue(result.HasRuleViolation);

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

            Assert.AreEqual("MustBeValidEmailAddress", ruleViolation.Rule.Name);
        }