Exemple #1
0
        private void VerifyInvariants(XamlLoadPermission original, bool isUnrestricted = false)
        {
            Assert.AreEqual(original, original);
            Assert.AreEqual(isUnrestricted, original.IsUnrestricted());

            XamlLoadPermission copy = (XamlLoadPermission)original.Copy();

            Assert.AreEqual(original, copy);
            Assert.AreEqual(original.IsUnrestricted(), copy.IsUnrestricted());
            Assert.IsTrue(original.IsSubsetOf(copy));
            Assert.IsTrue(copy.IsSubsetOf(original));

            XamlLoadPermission xmlCopy = new XamlLoadPermission(PermissionState.None);

            xmlCopy.FromXml(original.ToXml());
            Assert.AreEqual(original, xmlCopy);

            var intersect = (XamlLoadPermission)original.Intersect(copy);

            Assert.AreEqual(original, intersect);
            var union = (XamlLoadPermission)original.Union(copy);

            Assert.AreEqual(original, union);

            intersect = (XamlLoadPermission)original.Intersect(s_EmptyPerm);
            Assert.AreEqual(s_EmptyPerm, intersect);
            union = (XamlLoadPermission)original.Union(s_EmptyPerm);
            Assert.AreEqual(original, union);

            intersect = (XamlLoadPermission)original.Intersect(s_UnrestrictedPerm);
            Assert.AreEqual(original, intersect);
            union = (XamlLoadPermission)original.Union(s_UnrestrictedPerm);
            Assert.AreEqual(s_UnrestrictedPerm, union);
        }
Exemple #2
0
        public static void XamlLoadPermissionCallMethods()
        {
            XamlAccessLevel    accessLevel = XamlAccessLevel.AssemblyAccessTo(Assembly.GetExecutingAssembly().GetName());
            XamlLoadPermission xp          = new XamlLoadPermission(accessLevel);
            XamlLoadPermission xp2         = new XamlLoadPermission(PermissionState.Unrestricted);
            XamlLoadPermission xp3         = new XamlLoadPermission(Array.Empty <XamlAccessLevel>());
            bool        testbool           = xp.IsUnrestricted();
            IPermission ip  = xp.Copy();
            IPermission ip2 = xp.Intersect(ip);
            IPermission ip3 = xp.Union(ip);

            testbool = xp.IsSubsetOf(ip);
            testbool = xp.Equals(new object());
            testbool = xp.Includes(accessLevel);
            int             hash = xp.GetHashCode();
            SecurityElement se   = new SecurityElement("");

            xp.FromXml(se);
            se = xp.ToXml();
        }