Пример #1
0
 public void CanAuthorizeAgainstAType()
 {
     UserPermission user = new UserPermission();
     Create createAction = new Create();
     createAction.AddSubject(typeof(AddressModel));
     user.AddAuthorization(createAction);
     Assert.IsTrue(createAction.AppliesTo(typeof(AddressModel)));
     bool? canCreate = user.Can(Actions.Create, typeof(AddressModel));
     Assert.IsTrue(canCreate == true);
 }
Пример #2
0
        public void CanAuthorizedAgainstAnInstanceButNotAgainstAnotherInstance()
        {
            UserPermission user = new UserPermission();
            AddressModel address = new AddressModel();
            Create createAction = new Create();
            createAction.AddSubject(address);

            user.AddAuthorization(createAction);

            bool? canUpdate = user.Can(Actions.Create, address);
            Assert.IsTrue(canUpdate == true);

            AddressModel secondAddress = new AddressModel();
            canUpdate = user.Can(Actions.Create, secondAddress);
            Assert.IsTrue(canUpdate == false);
        }
Пример #3
0
        public void GetAuthorizationsForPersistance()
        {
            UserPermission user = new UserPermission();
            Create createAction = new Create(typeof(AddressModel));
            user.AddAuthorization(createAction);

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All,
                Formatting = Formatting.Indented
            };
            string serialized = JsonConvert.SerializeObject(user, settings);
            UserPermission deserializedUser = JsonConvert.DeserializeObject<UserPermission>(serialized, settings);

            // Now make sure deserialized object has same behaviour
            Assert.IsTrue(user.Can(Actions.Create, typeof(AddressModel)) == true);
            Assert.IsTrue(deserializedUser.Can(Actions.Create, typeof(AddressModel)) == true);
        }