Пример #1
0
        public void TestGetResourceId_PropertyDoesNotExist()
        {
            var resourceType   = "project";
            var permissionName = "edit";
            var instance       = new ABindingModel();
            var permission     = new ModelPermission("model.X", typeof(ABindingModel), permissionName, resourceType);
            var dictionary     = GetActionArgumentsDictionary(instance, "model");

            permission.Invoking(y => y.GetResourceId(dictionary)).ShouldThrow <NotSupportedException>()
            .WithMessage(String.Format("The property [{0}] does not exist in the model of type [{1}].", "X", "ABindingModel"));
        }
Пример #2
0
        public void TestGetResourceId_PropertyIsNotNumeric()
        {
            var resourceType   = "project";
            var permissionName = "edit";
            var instance       = new ABindingModel();
            var permission     = new ModelPermission("model.S", typeof(ABindingModel), permissionName, resourceType);
            var dictionary     = GetActionArgumentsDictionary(instance, "model");

            permission.Invoking(y => y.GetResourceId(dictionary)).ShouldThrow <NotSupportedException>()
            .WithMessage(String.Format("The nested property [{0}] in the model's property hierarchy [{1}] must be an integer.", "S", "model.S"));
        }
Пример #3
0
        public void TestGetResourceId_CaseInsensitive()
        {
            var resourceType   = "project";
            var permissionName = "edit";
            var value          = 1;
            var instance       = new ABindingModel();

            instance.Id = value;
            var permission = new ModelPermission("model.iD", typeof(ABindingModel), permissionName, resourceType);
            var dictionary = GetActionArgumentsDictionary(instance, "model");

            Assert.AreEqual(value, permission.GetResourceId(dictionary));
        }
Пример #4
0
        public void TestGetResourceId_ArgumentIsFirstLevelNode_MultipleDictionaryKeys()
        {
            var resourceType   = "project";
            var permissionName = "edit";
            var value          = 1;
            var instance       = new ABindingModel();

            instance.Id = value;
            var permission = new ModelPermission("model.Id", typeof(ABindingModel), permissionName, resourceType);
            var dictionary = GetActionArgumentsDictionary(instance, "model");

            dictionary.Add("key", "value");

            Assert.AreEqual(value, permission.GetResourceId(dictionary));
        }
Пример #5
0
        public void TestToString()
        {
            var resourceType   = "project";
            var permissionName = "edit";
            var instance       = new ABindingModel();
            var permission     = new ModelPermission("model.S", typeof(ABindingModel), permissionName, resourceType);

            Assert.AreEqual(
                String.Format("Permission Name:  [{0}], Resource Type:  [{1}], Model Type:  [{2}], Property:  [{3}]",
                              permission.PermissionName,
                              permission.ResourceType,
                              typeof(ABindingModel).Name,
                              "model.S"),
                permission.ToString());
        }
Пример #6
0
        public void TestGetResourceId_ArgumentIsSecondLevelNode()
        {
            var resourceType   = "project";
            var permissionName = "edit";
            var value          = 1;
            var instance       = new ABindingModel();

            instance.B = new BBindingModel
            {
                OtherId = value
            };
            var permission = new ModelPermission("model.B.OtherId", typeof(ABindingModel), permissionName, resourceType);
            var dictionary = GetActionArgumentsDictionary(instance, "model");

            Assert.AreEqual(value, permission.GetResourceId(dictionary));
        }