private static (string Name, object Value) GetActionNameAndValue( GenericRule genericRule) { var props = genericRule.GetType().GetProperties(); return(( from p in props let v = p.GetValue(genericRule) where v != null select(p.Name, v) ).Single()); }
public void RunTests() { BusinessRulesRepository <User> UserRules = new BusinessRulesRepository <User>(); UserRole adminRole = new UserRole() { RoleName = "Admin", RolePrecedence = 1 }; UserRole readerRole = new UserRole() { RoleName = "Reader", RolePrecedence = 2 }; UserRole debugRole = new UserRole() { RoleName = "Debug", RolePrecedence = -1 }; User testUser = new User(); testUser.Username = "******"; testUser.Roles.Add(readerRole); BusinessRule <User> UserIsTristan = new GenericRule <User>("User is named tdube", u => u.Username == "tdube"); UserIsTristan.ContinueProcessingOtherRules = false; UserRules.RuleSet.Add(UserIsTristan); BusinessRule <User> UserHasEnoughPermissions = new GenericRule <User>("User must be admin", u => u.Roles.Any(r => r.CompareTo(adminRole) <= 0)); UserRules.RuleSet.Add(UserHasEnoughPermissions); var result = UserRules.Apply(testUser); var failed = UserRules.GetFailedRules(testUser); int i = 0; }
public void RuleURIWithGenericObjectRule() { var rule = new GenericRule <AddressEdit>(); Assert.AreEqual("rule://csla.test.validationrules.genericrule-csla.test.validationrules/.AddressEdit-/(object)", rule.RuleName); }
private IAction ConvertSingle( GenericRule arg) { var(name, value) = GetActionNameAndValue(arg); return(ConvertSingle(name, value)); }