// <Snippet2> // IsSubsetOf determines whether the current permission is a subset of the specified permission. private bool IsSubsetOfDemo() { try { //<Snippet9> GacIdentityPermission Gac1 = new GacIdentityPermission(); GacIdentityPermission Gac2 = new GacIdentityPermission(PermissionState.None); if (Gac1.Equals(Gac2)) { Console.WriteLine("GacIdentityPermission() equals GacIdentityPermission(PermissionState.None)."); } //</Snippet9> if (Gac1.IsSubsetOf(Gac2)) { Console.WriteLine(Gac1 + " is a subset of " + Gac2); } else { Console.WriteLine(Gac1 + " is not a subset of " + Gac2); } } catch (Exception e) { Console.WriteLine("An exception was thrown : " + e); return(false); } return(true); }
// </Snippet2> // <Snippet3> // Union creates a new permission that is the union of the current permission // and the specified permission. private bool UnionDemo() { //<Snippet7> GacIdentityPermission Gac1 = new GacIdentityPermission(PermissionState.None); //</Snippet7> //<Snippet8> GacIdentityPermission Gac2 = new GacIdentityPermission(); //</Snippet8> try { GacIdentityPermission p3 = (GacIdentityPermission)Gac1.Union(Gac2); if (p3 != null) { Console.WriteLine("The union of two GacIdentityPermissions was successful."); } else { Console.WriteLine("The union of two GacIdentityPermissions failed."); return(false); } } catch (Exception e) { Console.WriteLine("An exception was thrown : " + e); return(false); } return(true); }
// </Snippet3> // <Snippet4> // Intersect creates and returns a new permission that is the intersection of the // current permission and the specified permission. private bool IntersectDemo() { GacIdentityPermission Gac1 = new GacIdentityPermission(); GacIdentityPermission Gac2 = new GacIdentityPermission(); try { GacIdentityPermission p3 = (GacIdentityPermission)Gac1.Intersect(Gac2); if (p3 != null) { Console.WriteLine("The intersection of the two permissions = " + p3.ToString() + "\n"); } else { Console.WriteLine("The intersection of the two permissions is null.\n"); } } catch (Exception e) { Console.WriteLine("An exception was thrown : " + e); return(false); } return(true); }
public void Union_DifferentPermissions() { GacIdentityPermission a = new GacIdentityPermission(PermissionState.None); SecurityPermission b = new SecurityPermission(PermissionState.None); a.Union(b); }
static void Main(string[] args) { //<Snippet2> GacInstalled myGacInstalled = new GacInstalled(); //</Snippet2> //<Snippet3> Object [] hostEvidence = { myGacInstalled }; Object [] assemblyEvidence = {}; Evidence myEvidence = new Evidence(hostEvidence, assemblyEvidence); GacIdentityPermission myPerm = (GacIdentityPermission)myGacInstalled.CreateIdentityPermission( myEvidence); Console.WriteLine(myPerm.ToXml().ToString()); //</Snippet3> //<Snippet4> GacInstalled myGacInstalledCopy = (GacInstalled)myGacInstalled.Copy(); bool result = myGacInstalled.Equals(myGacInstalledCopy); //</Snippet4> //<Snippet5> Console.WriteLine( "Hashcode = " + myGacInstalled.GetHashCode().ToString()); //</Snippet5> //<Snippet6> Console.WriteLine(myGacInstalled.ToString()); //</Snippet6> }
public void IsSubsetOf_DifferentPermissions() { GacIdentityPermission a = new GacIdentityPermission(PermissionState.None); SecurityPermission b = new SecurityPermission(PermissionState.None); a.IsSubsetOf(b); }
//</Snippet5> //<Snippet6> // ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a // permission with the specified state from the XML encoding. private bool ToFromXmlDemo() { GacIdentityPermission Gac1 = new GacIdentityPermission(); GacIdentityPermission Gac2 = new GacIdentityPermission(); Console.WriteLine("**************************************************************************"); try { Gac2 = new GacIdentityPermission(PermissionState.None); Gac2.FromXml(Gac1.ToXml()); bool result = Gac2.Equals(Gac1); if (Gac2.IsSubsetOf(Gac1) && Gac1.IsSubsetOf(Gac2)) { Console.WriteLine("Result of ToFromXml = " + Gac2.ToString()); } else { Console.WriteLine(Gac2.ToString()); Console.WriteLine(Gac1.ToString()); return(false); } } catch (Exception e) { Console.WriteLine("ToFromXml failed. " + e); return(false); } return(true); }
public void Intersect_DifferentPermissions() { GacIdentityPermission a = new GacIdentityPermission(PermissionState.None); SecurityPermission b = new SecurityPermission(PermissionState.None); a.Intersect(b); }
public void FromXml_WrongTagCase() { GacIdentityPermission gip = new GacIdentityPermission(); SecurityElement se = gip.ToXml(); se.Tag = "IPERMISSION"; // instead of IPermission gip.FromXml(se); }
public void FromXml_WrongTag() { GacIdentityPermission gip = new GacIdentityPermission(); SecurityElement se = gip.ToXml(); se.Tag = "IMono"; gip.FromXml(se); }
public void FromXml_WrongVersion() { GacIdentityPermission gip = new GacIdentityPermission(); SecurityElement se = gip.ToXml(); se.Attributes.Remove("version"); se.Attributes.Add("version", "2"); gip.FromXml(se); }
public void IsSubsetOf() { GacIdentityPermission gip = new GacIdentityPermission(); Assert.IsFalse(gip.IsSubsetOf(null), "gip.IsSubsetOf (null)"); GacIdentityPermission empty = new GacIdentityPermission(PermissionState.None); Assert.IsFalse(empty.IsSubsetOf(null), "empty.IsSubsetOf (null)"); }
public void FromXml_NoVersion() { GacIdentityPermission gip = new GacIdentityPermission(); SecurityElement se = gip.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("class", se.Attribute("class")); gip.FromXml(w); }
public void FromXml_NoClass() { GacIdentityPermission gip = new GacIdentityPermission(); SecurityElement se = gip.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("version", se.Attribute("version")); gip.FromXml(w); // doesn't even care of the class attribute presence }
public static void GacIdentityPermissionCallMethods() { GacIdentityPermission gip = new GacIdentityPermission(); IPermission ip = gip.Copy(); IPermission ip2 = gip.Intersect(ip); bool issubset = gip.IsSubsetOf(ip); IPermission ip3 = gip.Union(ip2); SecurityElement se = new SecurityElement(""); gip.FromXml(se); se = gip.ToXml(); }
public void FromXml_WrongClass() { GacIdentityPermission gip = new GacIdentityPermission(); SecurityElement se = gip.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("class", "Wrong" + se.Attribute("class")); w.AddAttribute("version", se.Attribute("version")); gip.FromXml(w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
public void PermissionStateNone() { GacIdentityPermission gip = new GacIdentityPermission(PermissionState.None); SecurityElement se = gip.ToXml(); // only class and version are present Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes"); Assert.IsNull(se.Children, "Xml-Children"); GacIdentityPermission copy = (GacIdentityPermission)gip.Copy(); Assert.IsFalse(Object.ReferenceEquals(gip, copy), "ReferenceEquals"); }
public void Intersect() { GacIdentityPermission gip = new GacIdentityPermission(); GacIdentityPermission intersect = (GacIdentityPermission)gip.Intersect(null); Assert.IsNull(intersect, "gip N null"); GacIdentityPermission empty = new GacIdentityPermission(PermissionState.None); intersect = (GacIdentityPermission)gip.Intersect(empty); Assert.IsNotNull(intersect, "gip N null"); intersect = (GacIdentityPermission)gip.Intersect(gip); Assert.IsNotNull(intersect, "gip N gip"); }
public void Union() { GacIdentityPermission gip = new GacIdentityPermission(); GacIdentityPermission union = (GacIdentityPermission)gip.Union(null); Assert.IsNotNull(union, "gip U null"); GacIdentityPermission empty = new GacIdentityPermission(PermissionState.None); union = (GacIdentityPermission)gip.Union(empty); Assert.IsNotNull(union, "gip U empty"); union = (GacIdentityPermission)gip.Union(gip); Assert.IsNotNull(union, "gip U gip"); // note: can't be tested with PermissionState.Unrestricted }
public void PermissionStateUnrestricted() { GacIdentityPermission gip = new GacIdentityPermission(PermissionState.Unrestricted); // FX 2.0 now supports Unrestricted for Identity Permissions // However the XML doesn't show the Unrestricted status... SecurityElement se = gip.ToXml(); // only class and version are present Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes"); Assert.IsNull(se.Children, "Xml-Children"); GacIdentityPermission copy = (GacIdentityPermission)gip.Copy(); Assert.IsFalse(Object.ReferenceEquals(gip, copy), "ReferenceEquals"); // ... and because it doesn't implement IUnrestrictedPermission // there is not way to know if it's unrestricted so... Assert.IsTrue(gip.Equals(new GacIdentityPermission(PermissionState.None)), "Unrestricted==None"); // there is not much difference after all ;-) }
//</Snippet4> //<Snippet5> //Copy creates and returns an identical copy of the current permission. private bool CopyDemo() { GacIdentityPermission Gac1 = new GacIdentityPermission(); GacIdentityPermission Gac2 = new GacIdentityPermission(); Console.WriteLine("**************************************************************************"); try { Gac2 = (GacIdentityPermission)Gac1.Copy(); if (Gac2 != null) { Console.WriteLine("Result of copy = " + Gac2.ToString() + "\n"); } } catch (Exception e) { Console.WriteLine("Copy failed : " + Gac1.ToString() + e); return(false); } return(true); }
public void FromXml_Null() { GacIdentityPermission gip = new GacIdentityPermission(); gip.FromXml(null); }
public void PermissionStateInvalid() { GacIdentityPermission gip = new GacIdentityPermission((PermissionState)2); }
public void IsGranted_GacIdentityPermission() { GacIdentityPermission gip = new GacIdentityPermission(); Assert.IsTrue(SecurityManager.IsGranted(gip)); }
public void GacIdentityPermission_Empty() { GacIdentityPermission gip = new GacIdentityPermission(); Assert.IsNotNull(gip); }