Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permission"></param>
        /// <param name="principal"></param>
        public PermissionGrantingContext(PermissionDefinition permission, IPrincipal principal)
        {
            Check.NotNull(permission, nameof(permission));

            Permission = permission;
            Principal  = principal;
        }
Esempio n. 2
0
        public void Name()
        {
            var def = new PermissionDefinition("Test");

            def.Name.ShouldBe("Test");
            def.ToString().ShouldBe("[PermissionDefinition Test]");
        }
Esempio n. 3
0
        public void AddPermission()
        {
            var def = new PermissionDefinition("Test");

            def.Children.ShouldBeEmpty();
            def.AddChild("TestPermission");
            def.Children.ShouldHaveSingleItem().FullName.ShouldBe("Test.TestPermission");
        }
Esempio n. 4
0
        public void Properties()
        {
            var def = new PermissionDefinition("Test");

            def.Properties.ShouldBeEmpty();
            def.Properties.Add("TestKey", "TestValue");
            def.Properties.ShouldHaveSingleItem().Key.ShouldBe("TestKey");
        }
Esempio n. 5
0
        public void This()
        {
            var def = new PermissionDefinition("Test");

            def.Properties.ShouldBeEmpty();
            def["TestKey"].ShouldBeNull();
            def["TestKey"] = "TestValue";
            def.Properties.ShouldHaveSingleItem().Key.ShouldBe("TestKey");
        }
Esempio n. 6
0
        public void DisplayName()
        {
            var def = new PermissionDefinition("Test", "DisplayName");

            def.DisplayName.ShouldBe("DisplayName");
            Should.Throw <ArgumentNullException>(() => def.DisplayName = null);
            Should.NotThrow(() => def.DisplayName = "TestDisplay");
            def.DisplayName.ShouldBe("TestDisplay");
        }
Esempio n. 7
0
        public void GetPermissionsWithChildren()
        {
            var def = new PermissionDefinition("Test");

            def.Children.ShouldBeEmpty();
            def
            .AddChild("TestPermission",
                      p => p.AddChild("TestChild"));
            def.Children.ShouldHaveSingleItem().Children.ShouldHaveSingleItem().FullName.ShouldBe("Test.TestPermission.TestChild");
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissions"></param>
        /// <param name="permission"></param>
        protected virtual void AddPermissionToDictionaryRecursively(Dictionary <string, PermissionDefinition> permissions, PermissionDefinition permission)
        {
            permissions.Add(permission.FullName, permission);

            foreach (var child in permission.Children)
            {
                AddPermissionToDictionaryRecursively(permissions, child);
            }
        }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissions"></param>
        /// <param name="permission"></param>
        protected virtual void AddPermissionToDictionaryRecursively(Dictionary <string, PermissionDefinition> permissions, PermissionDefinition permission)
        {
            if (permissions.ContainsKey(permission.Name))
            {
                throw new ScorpioException("Duplicate permission name: " + permission.Name);
            }

            permissions[permission.Name] = permission;

            foreach (var child in permission.Children)
            {
                AddPermissionToDictionaryRecursively(permissions, child);
            }
        }