Exemplo n.º 1
0
        /// <summary>
        /// Tests that flag of the given permissions value to be the expected output
        /// and then tries cycling through the states of the allow and deny values
        /// for that flag
        /// </summary>
        /// <param name="value"></param>
        /// <param name="flag"></param>
        /// <param name="expected"></param>
        private void TestHelper(OverwritePermissions value, ChannelPermission flag, PermValue expected)
        {
            // check that the value matches
            Assert.Equal(expected, Permissions.GetValue(value.AllowValue, value.DenyValue, flag));

            // check toggling bits for both allow and deny
            // have to make copies to get around read only property
            ulong allow = value.AllowValue;
            ulong deny  = value.DenyValue;

            // both unset should be inherit
            Permissions.UnsetFlag(ref allow, (ulong)flag);
            Permissions.UnsetFlag(ref deny, (ulong)flag);
            Assert.Equal(PermValue.Inherit, Permissions.GetValue(allow, deny, flag));

            // allow set should be allow
            Permissions.SetFlag(ref allow, (ulong)flag);
            Permissions.UnsetFlag(ref deny, (ulong)flag);
            Assert.Equal(PermValue.Allow, Permissions.GetValue(allow, deny, flag));

            // deny should be deny
            Permissions.UnsetFlag(ref allow, (ulong)flag);
            Permissions.SetFlag(ref deny, (ulong)flag);
            Assert.Equal(PermValue.Deny, Permissions.GetValue(allow, deny, flag));

            // allow takes precedence
            Permissions.SetFlag(ref allow, (ulong)flag);
            Permissions.SetFlag(ref deny, (ulong)flag);
            Assert.Equal(PermValue.Allow, Permissions.GetValue(allow, deny, flag));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tests the flag of the given permissions value to the expected output
        /// and then tries to toggle the flag on and off
        /// </summary>
        /// <param name="rawValue"></param>
        /// <param name="flagValue"></param>
        /// <param name="expected"></param>
        private void TestHelper(ulong rawValue, ulong flagValue, bool expected)
        {
            Assert.Equal(expected, Permissions.GetValue(rawValue, flagValue));

            // check that toggling the bit works
            Permissions.UnsetFlag(ref rawValue, flagValue);
            Assert.False(Permissions.GetValue(rawValue, flagValue));
            Permissions.SetFlag(ref rawValue, flagValue);
            Assert.True(Permissions.GetValue(rawValue, flagValue));

            // do the same, but with the SetValue method
            Permissions.SetValue(ref rawValue, true, flagValue);
            Assert.True(Permissions.GetValue(rawValue, flagValue));
            Permissions.SetValue(ref rawValue, false, flagValue);
            Assert.False(Permissions.GetValue(rawValue, flagValue));
        }