예제 #1
0
        public void AuthorizingAgainstTheTypeGivesAuthorityForAllInstances()
        {
            UserPermission user = new UserPermission();
            Update updateAction = new Update();
            AddressModel address = new AddressModel();

            updateAction.AddSubject(typeof(AddressModel));
            user.AddAuthorization(updateAction);
            Assert.IsTrue(updateAction.AppliesTo(address));
            bool? canUpdate = user.Can(Actions.Update, address);
            Assert.IsTrue(canUpdate == true);
        }
예제 #2
0
        public void UnauthorizedAgainstTheTypePreventsAuthorizationForAllInstances()
        {
            // If we are unauthorized against a type,
            // then even if we authorize against an instance
            // we are not authorized
            UserPermission user = new UserPermission();
            Update updateAction = new Update(typeof(AddressModel));
            AddressModel address = new AddressModel();

            user.AddUnauthorization(updateAction);
            Assert.IsTrue(updateAction.AppliesTo(address));
            bool? canUpdate = user.Can(Actions.Update, address);
            Assert.IsTrue(canUpdate == false);

            // now authorize against an instance

            Update authorizeInstanceUpdateAction = new Update();

            authorizeInstanceUpdateAction.AddSubject(address);
            user.AddAuthorization(authorizeInstanceUpdateAction);
            canUpdate = user.Can(Actions.Update, address);
            Assert.IsTrue(canUpdate == false);
        }