Example #1
0
        public void TestFindRuleByNameWithoutRuleSuffix()
        {
            var rules = new Rules(typeof(IRule).Assembly);

            var soughtRule = rules.RuleByName("LimitAssertsPerTestCase");

            Assert.IsNotNull(soughtRule);
        }
Example #2
0
 /// <summary>
 /// Applies the configuration to the rules found in the given repository.
 /// </summary>
 /// <param name="rules">A repository of rules.</param>
 /// <exception cref="NoSuchRuleException">Thrown if a rule in the configuration cannot be found.
 /// </exception>
 /// <exception cref="MalformedRuleConfiguration">Thrown if a public, writeable setting cannot be 
 /// found on a rule, or if the value of the setting has the wrong type.</exception>
 public void ApplyConfiguration(Rules rules)
 {
     foreach (var entry in _rulesSettings)
     {
         var rule = rules.RuleByName(entry.Key);
         foreach (var setting in entry.Value)
         {
             var prop = FindProperty(rule, setting.Name);
             if (prop == null)
                 throw new MalformedRuleConfiguration("Missing or non-writeable setting: " + setting.Name);
             try
             {
                 var typedValue = Convert.ChangeType(setting.Value, prop.PropertyType);
                 prop.SetValue(rule, typedValue, BindingFlags.Default, null, null, null);
             }
             catch (FormatException)
             {
                 throw new MalformedRuleConfiguration(string.Format("Value for setting {0} does not match the setting type: {1}", setting.Name, setting.Value));
             }
         }
     }
 }
Example #3
0
        public void TestFindingMissingRuleThrows()
        {
            var rules = new Rules(typeof(IRule).Assembly);

            Assert.Catch<NoSuchRuleException>(() => rules.RuleByName("Dummy"));
        }