コード例 #1
0
        public void PermissionStateNone()
        {
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None);

            Assert.AreEqual(String.Empty, snip.Name, "Name");
            Assert.IsNull(snip.PublicKey, "PublicKey");
            Assert.AreEqual("0.0", snip.Version.ToString(), "Version");

            SecurityElement se = snip.ToXml();

#if NET_2_0
            Assert.IsNull(se.Attribute("Name"), "Xml-Name");
            Assert.IsNull(se.Attribute("AssemblyVersion"), "Xml-AssemblyVersion");
#else
            Assert.AreEqual(String.Empty, se.Attribute("Name"), "Xml-Name");
            Assert.AreEqual("0.0", se.Attribute("AssemblyVersion"), "Xml-AssemblyVersion");
#endif
            Assert.IsNull(se.Attribute("PublicKeyBlob"), "Xml-PublicKeyBlob");

            // because Name == String.Empty, which is illegal using the other constructor
            StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy();
            Assert.AreEqual(String.Empty, copy.Name, "Copy-Name");
#if NET_2_0
            // Strangely once copied the Name becomes equals to String.Empty in 2.0 [FDBK19351]
            Assert.IsNull(se.Attribute("AssemblyVersion"), "Copy-Version");
#else
            Assert.AreEqual("0.0", copy.Version.ToString(), "Copy-Version");
#endif
            Assert.IsNull(copy.PublicKey, "Copy-PublicKey");
        }
コード例 #2
0
        public void Copy_NameEmpty()
        {
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None);

            snip.PublicKey = new StrongNamePublicKeyBlob(ecma);
            snip.Version   = new Version("1.2.3.4");

            // because Name == String.Empty, which is illegal using the other constructor
            // but (somewhat) required to copy the teo other informations
            StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy();

            Assert.IsTrue(copy.Equals(snip), "Equals");
        }
コード例 #3
0
        public static void StrongNameIdentityPermissionCallMethods()
        {
            StrongNameIdentityPermission snip  = new StrongNameIdentityPermission(new Permissions.PermissionState());
            StrongNameIdentityPermission snip2 = new StrongNameIdentityPermission(new Permissions.StrongNamePublicKeyBlob(new byte[1]), "test", new Version(1, 2));
            IPermission ip       = snip.Copy();
            IPermission ip2      = snip.Intersect(ip);
            bool        testbool = snip.IsSubsetOf(ip);

            ip2 = snip.Union(ip);
            SecurityElement se = new SecurityElement("");

            snip.FromXml(se);
            se = snip.ToXml();
        }
コード例 #4
0
    //</Snippet4>
    //<Snippet5>
    //Copy creates and returns an identical copy of the current permission.
    private bool CopyDemo()
    {
        bool returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
        //<Snippet7>
        snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);
        //</Snippet7>

        snIdPerm2 = (StrongNameIdentityPermission)snIdPerm1.Copy();
        Console.WriteLine("Result of copy = " + snIdPerm2.ToString() + "\n");

        return(returnValue);
    }
コード例 #5
0
        public void PermissionStateUnrestricted()
        {
            // In 2.0 Unrestricted are permitted for identity permissions
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.Unrestricted);

            Assert.AreEqual(String.Empty, snip.Name, "Name");
            Assert.IsNull(snip.PublicKey, "PublicKey");
            Assert.AreEqual("0.0", snip.Version.ToString(), "Version");
            SecurityElement se = snip.ToXml();

            Assert.IsNull(se.Attribute("Name"), "Xml-Name");
            Assert.IsNull(se.Attribute("PublicKeyBlob"), "Xml-PublicKeyBlob");
            Assert.IsNull(se.Attribute("AssemblyVersion"), "Xml-AssemblyVersion");
            StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy();

            Assert.IsTrue(snip.Equals(copy), "snip Equals copy");
            Assert.IsTrue(copy.Equals(snip), "copy Equals snip");
            // and they aren't equals to None
            Assert.IsFalse(snip.Equals(new StrongNameIdentityPermission(PermissionState.None)), "Not Equals None");
        }
コード例 #6
0
        public void StrongNameIdentityPermission_All()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            Assert.AreEqual("mono", snip.Name, "Name");
            Assert.AreEqual("00000000000000000400000000000000", snip.PublicKey.ToString(), "PublicKey");
            Assert.AreEqual("1.2.3.4", snip.Version.ToString(), "Version");

            SecurityElement se = snip.ToXml();

            Assert.AreEqual("mono", se.Attribute("Name"), "Xml-Name");
            Assert.AreEqual("00000000000000000400000000000000", se.Attribute("PublicKeyBlob"), "Xml-PublicKeyBlob");
            Assert.AreEqual("1.2.3.4", se.Attribute("AssemblyVersion"), "Xml-AssemblyVersion");

            StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy();

            Assert.AreEqual("mono", se.Attribute("Name"), "Copy-Name");
            Assert.AreEqual("00000000000000000400000000000000", se.Attribute("PublicKeyBlob"), "Copy-PublicKeyBlob");
            Assert.AreEqual("1.2.3.4", se.Attribute("AssemblyVersion"), "Copy-AssemblyVersion");
        }
コード例 #7
0
ファイル: PermissionTests.cs プロジェクト: Corillian/corefx
 public static void StrongNameIdentityPermissionCallMethods()
 {
     StrongNameIdentityPermission snip = new StrongNameIdentityPermission(new Permissions.PermissionState());
     StrongNameIdentityPermission snip2 = new StrongNameIdentityPermission(new Permissions.StrongNamePublicKeyBlob(new byte[1]), "test", new System.Version(1, 2));
     IPermission ip = snip.Copy();
     IPermission ip2 = snip.Intersect(ip);
     bool testbool = snip.IsSubsetOf(ip);
     ip2 = snip.Union(ip);
     SecurityElement se = new SecurityElement("");
     snip.FromXml(se);
     se = snip.ToXml();
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: oblivious/Oblivious
	//Copy creates and returns an identical copy of the current permission. 
	private bool CopyDemo()
	{
		bool returnValue = true;

		StrongNameIdentityPermission snIdPerm1, snIdPerm2;

		snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
		snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None);

		snIdPerm2 = (StrongNameIdentityPermission)snIdPerm1.Copy();
		Console.WriteLine("Result of copy = " + snIdPerm2.ToString() + "\n");

		return returnValue;
	}