Esempio n. 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);
        }
Esempio n. 2
0
        public void SingleAssembly()
        {
            XamlAccessLevel    assemblyAccess = XamlAccessLevel.AssemblyAccessTo(typeof(LoadPermissionTests).Assembly);
            XamlLoadPermission assemblyPerm   = new XamlLoadPermission(assemblyAccess);

            VerifyInvariants(assemblyPerm);

            XamlLoadPermission testPerm, intersect, union;

            // Identical permission
            XamlAccessLevel sameAssemblyAccess = XamlAccessLevel.AssemblyAccessTo(typeof(LoadPermissionTests).Assembly);

            testPerm = new XamlLoadPermission(sameAssemblyAccess);
            VerifyInvariants(testPerm);
            Assert.AreEqual(assemblyPerm, testPerm);
            Assert.IsTrue(testPerm.IsSubsetOf(assemblyPerm));
            Assert.IsTrue(assemblyPerm.IsSubsetOf(testPerm));
            intersect = (XamlLoadPermission)testPerm.Intersect(assemblyPerm);
            Assert.AreEqual(assemblyPerm, intersect);
            union = (XamlLoadPermission)testPerm.Union(assemblyPerm);
            Assert.AreEqual(assemblyPerm, union);
            Assert.IsTrue(testPerm.Includes(sameAssemblyAccess));

            // Type permission to same assembly
            XamlAccessLevel typeAccess = XamlAccessLevel.PrivateAccessTo(typeof(LoadPermissionTests));

            testPerm = new XamlLoadPermission(typeAccess);
            VerifyInvariants(testPerm);
            Assert.AreNotEqual(assemblyPerm, testPerm);
            Assert.IsFalse(testPerm.IsSubsetOf(assemblyPerm));
            Assert.IsTrue(assemblyPerm.IsSubsetOf(testPerm));
            intersect = (XamlLoadPermission)testPerm.Intersect(assemblyPerm);
            Assert.AreEqual(assemblyPerm, intersect);
            union = (XamlLoadPermission)testPerm.Union(assemblyPerm);
            Assert.AreEqual(testPerm, union);
            Assert.IsTrue(testPerm.Includes(sameAssemblyAccess));
            Assert.IsTrue(testPerm.Includes(typeAccess));

            // Assembly permission on different assembly
            XamlAccessLevel diffAssemblyAccess = XamlAccessLevel.AssemblyAccessTo(typeof(string).Assembly);

            testPerm = new XamlLoadPermission(diffAssemblyAccess);
            VerifyInvariants(testPerm);
            Assert.AreNotEqual(assemblyPerm, testPerm);
            Assert.IsFalse(testPerm.IsSubsetOf(assemblyPerm));
            Assert.IsFalse(assemblyPerm.IsSubsetOf(testPerm));
            intersect = (XamlLoadPermission)testPerm.Intersect(assemblyPerm);
            Assert.AreEqual(s_EmptyPerm, intersect);
            union = (XamlLoadPermission)testPerm.Union(assemblyPerm);
            Assert.IsTrue(testPerm.IsSubsetOf(union));
            Assert.IsTrue(assemblyPerm.IsSubsetOf(union));
            Assert.IsFalse(testPerm.Includes(sameAssemblyAccess));
            Assert.IsFalse(testPerm.Includes(typeAccess));
        }
Esempio n. 3
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();
        }