public void BuildOrExpression_FailVerification()
 {
     var expr = new PermissionExpressionBuilder().Build("foo | bar", permissionName =>
                                                                         {
                                                                             permissionsChecked.Add(permissionName);
                                                                             return false;
                                                                         });
     Assert.IsFalse(expr.Compile().Invoke());
     AssertPermissionsChecked("foo", "bar");
 }
 public void MixedLogic_LeftToRight_Precedence_And()
 {
     var expr = new PermissionExpressionBuilder().Build("foo & bar | baz", permissionName =>
                                                                               {
                                                                                   permissionsChecked.Add(permissionName);
                                                                                   // foo = true, bar = false, baz = true should force this to be true.  foo & (bar | baz)
                                                                                   return permissionName == "foo" || permissionName == "baz";
                                                                               });
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo", "bar", "baz");
 }
 public void BuildAndExpression_FailVerification_WithShortCircuit()
 {
     var expr = new PermissionExpressionBuilder().Build("foo & bar", permissionName =>
                                                                         {
                                                                             if (permissionName == "foo")
                                                                             {
                                                                                 permissionsChecked.Add("foo");
                                                                                 return true;
                                                                             }
                                                                             return false;
                                                                         });
     Assert.IsFalse(expr.Compile().Invoke());
     AssertPermissionsChecked("foo");
 }
 public void BuildSimplestExpression()
 {
     var expr = new PermissionExpressionBuilder().Build("foo", Verify);
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo");
 }
 public void BuildOrExpression_SuccessfulVerification()
 {
     var expr = new PermissionExpressionBuilder().Build("foo | bar", Verify);
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo"); // short circuit
 }
 public void BuildAndExpression_SuccessfulVerification()
 {
     var expr = new PermissionExpressionBuilder().Build("foo & bar", Verify);
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo", "bar");
 }
 public void MultipleOrs()
 {
     var expr = new PermissionExpressionBuilder().Build("foo | bar | baz", permissionName =>
                                                                               {
                                                                                   permissionsChecked.Add(permissionName);
                                                                                   return permissionName == "baz";
                                                                               });
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo", "bar", "baz");
 }
 public void MultipleAnds()
 {
     var expr = new PermissionExpressionBuilder().Build("foo & bar & baz", Verify);
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo", "bar", "baz");
 }
 public void MixedLogic_LeftToRight_Precedence_Or_ShortCircuit()
 {
     // see MixedLogic_LeftToRight_Precedence_Or
     var expr = new PermissionExpressionBuilder().Build("foo | bar & baz", permissionName =>
                                                                               {
                                                                                   permissionsChecked.Add(permissionName);
                                                                                   // foo = true , bar = false , baz = false should force this to be true.  foo | (bar & baz)
                                                                                   return permissionName == "foo";
                                                                               });
     Assert.IsTrue(expr.Compile().Invoke());
     AssertPermissionsChecked("foo");
 }