Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuleEventArgs"/> class.
 /// </summary>
 /// <param name="rule">The rule.</param>
 /// <exception cref="System.ArgumentNullException">rule</exception>
 public RuleEventArgs(RulePolicy rule)
 {
     if(rule == null)
     {
         throw new ArgumentNullException("rule");
     }
     this.rule = rule;
 }
Beispiel #2
0
        public void A_RulePolicy_can_be_properly_serialized_to_json()
        {
            var adminRoleRule = new ClaimRule {
                ClaimType = "role", ClaimValue = "admin"
            };
            var powerUserRoleRule = new ClaimRule {
                ClaimType = "role", ClaimValue = "power user"
            };
            var salesDepartmentRule = new ClaimRule {
                ClaimType = "department", ClaimValue = "sales"
            };
            var nameDynauthorizerRule = new ClaimRule {
                ClaimType = "name", ClaimValue = "Dynauthorizer"
            };

            var salesPowerUserRuleSet = new RuleSet(new[] { powerUserRoleRule, salesDepartmentRule }, RuleSetOperator.And);
            var rootRuleSet           = new RuleSet(new IRule[] { adminRoleRule, nameDynauthorizerRule, salesPowerUserRuleSet }, RuleSetOperator.Or);

            var policy = new RulePolicy {
                Name = "MyPolicy", RootRule = rootRuleSet
            };

            var jsonString = JsonConvert.SerializeObject(policy, Formatting.Indented);

            var expectedString = @"{
  ""name"": ""MyPolicy"",
  ""rootRule"": {
    ""rules"": [
      {
        ""claimType"": ""role"",
        ""claimValue"": ""admin""
      },
      {
        ""claimType"": ""name"",
        ""claimValue"": ""Dynauthorizer""
      },
      {
        ""rules"": [
          {
            ""claimType"": ""role"",
            ""claimValue"": ""power user""
          },
          {
            ""claimType"": ""department"",
            ""claimValue"": ""sales""
          }
        ],
        ""operator"": ""And""
      }
    ],
    ""operator"": ""Or""
  }
}";

            Assert.Equal(expectedString, jsonString);
        }
Beispiel #3
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="Result" /> class.
 /// </summary>
 /// <param name="rulePolicy"> The rule policy. </param>
 public Result(RulePolicy rulePolicy)
 {
     this.rulePolicy = rulePolicy;
     isValid         = rulePolicy.IsValid;
     message         = rulePolicy.Message;
 }
Beispiel #4
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="Result" /> class.
 /// </summary>
 /// <param name="rulePolicy"> The rule policy. </param>
 public Result(RulePolicy rulePolicy)
 {
     this.rulePolicy = rulePolicy;
     isValid = rulePolicy.IsValid;
     message = rulePolicy.Message;
 }