/**==== Rule Disjunction * * The produce an `any` disjunction rule over many rules you can use the overloaded `|` */ [U] public void RulesDisjunction() { var anyRule = new UsernameRule("u1") | new UsernameRule("u2") | new UsernameRule("u3"); anyRule.Any.Should().NotBeEmpty().And.HaveCount(3); /** using `|=` assignments you can build disjunction rules more dynamically **/ RoleMappingRuleBase rules = null; for (var i = 0; i < 10; i++) { rules |= new UsernameRule($"user_{i}"); } rules.Should().BeOfType <AnyRoleMappingRule>(); anyRule = (AnyRoleMappingRule)rules; anyRule.Any.Should().NotBeEmpty().And.HaveCount(10); }
/**==== Rule Conjunction * * You can create a conjuction of many rules using either `+` or `&` which are both overloaded to produce an `all` rule. */ [U] public void RulesConjunction() { var allRule = new UsernameRule("u1") + new UsernameRule("u2") & new UsernameRule("u3"); allRule.All.Should().NotBeEmpty().And.HaveCount(3); /** using `+=` assignments you can build rules more dynamically **/ RoleMappingRuleBase rules = null; for (var i = 0; i < 10; i++) { rules += new UsernameRule($"user_{i}"); } rules.Should().BeOfType <AllRoleMappingRule>(); allRule = (AllRoleMappingRule)rules; allRule.All.Should().NotBeEmpty().And.HaveCount(10); }