Exemple #1
0
        public void Check_WithColumnRestrictions_ShouldReturnRestricted()
        {
            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var permissions = new GuardianPermissions();

            permissions.RowLevel.Add(new TestRowPermission()
            {
                AccessType     = AccessTypes.Get,
                EntityTypeName = model.GetType().Name,
                RowIdentifier  = "1"
            });

            permissions.ColumnLevel.Add(new TestColumnRestriction()
            {
                AccessType     = AccessTypes.Get,
                EntityTypeName = model.GetType().Name,
                PropertyName   = "Property1"
            });

            _kernel.Permissions = permissions;

            var policyContext = GetPolicyContext(model);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(true, result);

            Assert.Equal(true, model.ProtectedProperties.Contains("Property1"));
        }
        public void Check_WithRowLevelPermission_ShouldReturnTrue()
        {
            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var permissions = new GuardianPermissions();

            permissions.RowLevel.Add(new TestRowPermission()
            {
                AccessType     = AccessTypes.Add,
                EntityTypeName = model.GetType().Name,
                RowIdentifier  = "1"
            });

            _kernel.Permissions = permissions;

            var policyContext = GetPolicyContext(model, AccessTypes.Add);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(true, result);
        }
        public void Check_WithGeneralPermission_ShouldReturnTrue()
        {
            var model = new Model1()
            {
                Id        = 1,
                Property1 = "Property1",
                Property2 = "Property2"
            };

            var permissions = new GuardianPermissions();

            permissions.General.Add(new TestPermission()
            {
                AccessType     = AccessTypes.Update,
                EntityTypeName = model.GetType().Name
            });
            _kernel.Permissions = permissions;

            var policyContext = GetPolicyContext(model, AccessTypes.Update);

            var result = _policy.Check(policyContext, _kernel);

            Assert.Equal(true, result);
        }
Exemple #4
0
 public static IEnumerable GetRootCollection(Model1 db, string collectionPropertyName)
 {
   PropertyInfo p = db.GetType().GetProperty(collectionPropertyName);
   return (IEnumerable)p.GetValue(db);
 }