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"); }
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"); }
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(); }
//</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); }
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"); }
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"); }
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(); }
//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; }