Example #1
0
        public void TestMatchAndTranslate()
        {
            /// Arrange
            RuleApplyer <string, string> translateApplyer = new RuleApplyer <string, string>();

            translateApplyer.Rules.Add(new RuleMatchAndTranslate('3', "Foo"));
            translateApplyer.Rules.Add(new RuleMatchAndTranslate('5', "Bar"));
            translateApplyer.Rules.Add(new RuleMatchAndTranslate('7', "Qix"));
            string theInput = "357";



            /// Act
            var results = translateApplyer.ApplyRules(theInput);


            /// Assert
            string result = "";

            foreach (var res in results)
            {
                result += res.Value;
            }
            Assert.Matches("FooBarQix", result);
        }
Example #2
0
        public void TestDevidedAndGenerate()
        {
            /// Arrange


            RuleApplyer <int, string> divideApplyer = new RuleApplyer <int, string>();

            divideApplyer.Rules.Add(new RuleDividedByAndGenerate(3, "Foo"));
            divideApplyer.Rules.Add(new RuleDividedByAndGenerate(5, "Bar"));
            divideApplyer.Rules.Add(new RuleDividedByAndGenerate(7, "Qix"));
            int theInput = 15;

            /// Act

            var results = divideApplyer.ApplyRules(theInput);

            /// Assert
            string result = "";

            foreach (var res in results)
            {
                result += res.Value;
            }
            Assert.Matches("FooBar", result);
        }
Example #3
0
        static string Compute(string theInput)
        {
            string result = "";
            int    parsedValue;

            bool parsed = Int32.TryParse(theInput, out parsedValue);

            if (parsed == false)
            {
                return(" Please enter a valid Digit");
            }
            RuleApplyer <int, string> divideApplyer = new RuleApplyer <int, string>();

            divideApplyer.Rules.Add(new RuleDividedByAndGenerate(3, "Foo"));
            divideApplyer.Rules.Add(new RuleDividedByAndGenerate(5, "Bar"));
            divideApplyer.Rules.Add(new RuleDividedByAndGenerate(7, "Quix"));


            var results = divideApplyer.ApplyRules(parsedValue);

            foreach (var res in results)
            {
                result += res.Value;
            }

            RuleApplyer <string, string> translateApplyer = new RuleApplyer <string, string>();

            translateApplyer.Rules.Add(new RuleMatchAndTranslate('3', "Foo"));
            translateApplyer.Rules.Add(new RuleMatchAndTranslate('5', "Bar"));
            translateApplyer.Rules.Add(new RuleMatchAndTranslate('7', "Quix"));
            translateApplyer.Rules.Add(new RuleMatchAndTranslate('0', "*"));
            var results2 = translateApplyer.ApplyRules(theInput);

            foreach (var res in results2)
            {
                result += res.Value;
            }



            RuleApplyer <string, string> replaceApplyer = new RuleApplyer <string, string>();

            replaceApplyer.Rules.Add(new RuleMatchAndTranslate('0', "*"));



            return(result);
        }
Example #4
0
        public void TestMatchAndReplace()
        {
            /// Arrange

            RuleApplyer <string, string> replaceApplyer = new RuleApplyer <string, string>();

            replaceApplyer.Rules.Add(new RuleMatchAndReplace('0', "*"));
            string theInput = "101";

            /// Act

            var results = replaceApplyer.ApplyRules(theInput);

            /// Assert
            Assert.Matches("1*1", results[0].Value);
        }
        public void TestRuleApplayer()
        {
            /// Arrange
            RuleApplyer <int, string> ruleApplyer = new RuleApplyer <int, string>();
            Condition <int>           condition   = new Condition <int> {
                IsSatisfied = (int value) => (value % 5 == 0)
            };
            int theInput = 15;

            Rule <int, string> rule = new Rule <int, string>();

            rule.Conditions.Add(condition);
            rule.Action.Apply = context => { return("Bar"); };

            ruleApplyer.Rules.Add(rule);

            /// Act
            var results = ruleApplyer.ApplyRules(theInput);

            /// Assert
            Assert.Equal(1, results.Count);
            Assert.Matches("Bar", results[0].Value);
        }