// 2.0 metadata format internal static PermissionSetCollection CreateFromBinaryFormat(byte[] data) { if ((data == null) || (data [0] != 0x2E) || (data.Length < 2)) { string msg = Locale.GetText("Invalid data in 2.0 metadata format."); throw new SecurityException(msg); } int pos = 1; int numattr = PermissionSet.ReadEncodedInt(data, ref pos); PermissionSetCollection psc = new PermissionSetCollection(); for (int i = 0; i < numattr; i++) { IPermission p = PermissionSet.ProcessAttribute(data, ref pos); if (p == null) { string msg = Locale.GetText("Unsupported data found in 2.0 metadata format."); throw new SecurityException(msg); } PermissionSet ps = new PermissionSet(PermissionState.None); ps.DeclarativeSecurity = true; ps.AddPermission(p); psc.Add(ps); } return(psc); }
public PermissionSetCollection Copy () { PermissionSetCollection psc = new PermissionSetCollection (); foreach (PermissionSet ps in _list) { psc._list.Add (ps.Copy ()); } return psc; }
public PermissionSetCollection Copy() { PermissionSetCollection psc = new PermissionSetCollection(); foreach (PermissionSet ps in _list) { psc._list.Add(ps.Copy()); } return(psc); }
public void FromXml_Roundtrip () { PermissionSetCollection psc = new PermissionSetCollection (); string expected = psc.ToString (); SecurityElement se = psc.ToXml (); psc.FromXml (se); string actual = psc.ToString (); Assert.AreEqual (expected, actual, "Empty"); PermissionSet none = new PermissionSet (PermissionState.None); psc.Add (none); expected = psc.ToString (); se = psc.ToXml (); psc.FromXml (se); actual = psc.ToString (); Assert.AreEqual (expected, actual, "1-None"); none.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion)); expected = psc.ToString (); se = psc.ToXml (); psc.FromXml (se); actual = psc.ToString (); Assert.AreEqual (expected, actual, "1-Assertion"); Assert.AreEqual (1, psc.Count, "1"); PermissionSet unr = new PermissionSet (PermissionState.Unrestricted); psc.Add (unr); expected = psc.ToString (); se = psc.ToXml (); psc.FromXml (se); actual = psc.ToString (); Assert.AreEqual (expected, actual, "2-Assertion+Unrestricted"); Assert.AreEqual (2, psc.Count, "2"); }
public void FromXml_BadName () { PermissionSetCollection psc = new PermissionSetCollection (); SecurityElement se = new SecurityElement ("PermissionZetCollection"); psc.FromXml (se); }
public void FromXml_Null () { PermissionSetCollection psc = new PermissionSetCollection (); psc.FromXml (null); }
public void RemoveSet () { PermissionSetCollection psc = new PermissionSetCollection (); PermissionSet unr = new PermissionSet (PermissionState.Unrestricted); psc.Add (unr); psc.RemoveSet (0); Assert.AreEqual (0, psc.Count, "Count"); }
public void RemoveSet_Zero_Empty () { PermissionSetCollection psc = new PermissionSetCollection (); psc.RemoveSet (0); }
public void GetSet () { PermissionSetCollection psc = new PermissionSetCollection (); PermissionSet unr = new PermissionSet (PermissionState.Unrestricted); psc.Add (unr); PermissionSet ps = psc.GetSet (0); Assert.AreEqual (unr.ToString (), ps.ToString (), "Same XML"); Assert.IsTrue (Object.ReferenceEquals (unr, ps), "Same Object Reference"); }
public void Add () { PermissionSet none = new PermissionSet (PermissionState.None); PermissionSet unr = new PermissionSet (PermissionState.Unrestricted); PermissionSetCollection psc = new PermissionSetCollection (); Assert.AreEqual (0, psc.PermissionSets.Count, "Count-0"); Assert.AreEqual (0, psc.Count, "Count-0"); psc.Add (none); Assert.AreEqual (1, psc.PermissionSets.Count, "Count-1"); // re-add same permissionset psc.Add (none); Assert.AreEqual (2, psc.PermissionSets.Count, "Count-2"); psc.Add (unr); Assert.AreEqual (3, psc.PermissionSets.Count, "Count-3"); Assert.AreEqual (3, psc.Count, "Count-3"); }
public void Add_Null () { PermissionSetCollection psc = new PermissionSetCollection (); psc.Add (null); }
public void SyncRoot () { PermissionSetCollection psc = new PermissionSetCollection (); Assert.IsNull (psc.SyncRoot, "SyncRoot"); }
public void Constructor () { PermissionSetCollection psc = new PermissionSetCollection (); Assert.AreEqual (0, psc.Count, "Count"); Assert.IsFalse (psc.IsSynchronized, "IsSynchronized"); Assert.AreEqual (0, psc.PermissionSets.Count, "PermissionSets.Count"); Assert.AreEqual (psc.ToXml ().ToString (), psc.ToString (), "ToXml().ToString()==ToString()"); Assert.IsNotNull (psc.GetEnumerator (), "GetEnumerator"); }
// 2.0 metadata format internal static PermissionSetCollection CreateFromBinaryFormat (byte[] data) { if ((data == null) || (data [0] != 0x2E) || (data.Length < 2)) { string msg = Locale.GetText ("Invalid data in 2.0 metadata format."); throw new SecurityException (msg); } int pos = 1; int numattr = PermissionSet.ReadEncodedInt (data, ref pos); PermissionSetCollection psc = new PermissionSetCollection (); for (int i = 0; i < numattr; i++) { IPermission p = PermissionSet.ProcessAttribute (data, ref pos); if (p == null) { string msg = Locale.GetText ("Unsupported data found in 2.0 metadata format."); throw new SecurityException (msg); } PermissionSet ps = new PermissionSet (PermissionState.None); ps.DeclarativeSecurity = true; ps.AddPermission (p); psc.Add (ps); } return psc; }
public void GetSet_Negative () { PermissionSetCollection psc = new PermissionSetCollection (); psc.GetSet (-1); }
public void GetSet_Zero_Empty () { PermissionSetCollection psc = new PermissionSetCollection (); psc.GetSet (0); }
public void Copy () { PermissionSet none = new PermissionSet (PermissionState.None); PermissionSet unr = new PermissionSet (PermissionState.Unrestricted); PermissionSetCollection psc = new PermissionSetCollection (); PermissionSetCollection copy = psc.Copy (); Assert.AreEqual (0, copy.PermissionSets.Count, "Count-0"); psc.Add (none); Assert.AreEqual (0, copy.PermissionSets.Count, "Count-0b"); copy = psc.Copy (); Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1"); psc.Add (none); // re-add same permissionset Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1b"); copy = psc.Copy (); Assert.AreEqual (2, copy.PermissionSets.Count, "Count-2"); psc.Add (unr); Assert.AreEqual (2, copy.PermissionSets.Count, "Count-2b"); copy = psc.Copy (); Assert.AreEqual (3, copy.PermissionSets.Count, "Count-3"); Assert.AreEqual (3, copy.Count, "Count-3"); }
public void RemoveSet_Negative () { PermissionSetCollection psc = new PermissionSetCollection (); psc.RemoveSet (-1); }
public void Copy_References () { PermissionSet none = new PermissionSet (PermissionState.None); PermissionSetCollection psc = new PermissionSetCollection (); psc.Add (none); PermissionSetCollection copy = psc.Copy (); Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1"); string before = psc.ToString (); none.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion)); Assert.AreEqual (none.ToString (), psc.PermissionSets[0].ToString (), "psc"); Assert.AreEqual (before, copy.ToString (), "copy"); }
public void RemoveSet_MaxInt () { PermissionSetCollection psc = new PermissionSetCollection (); psc.RemoveSet (Int32.MaxValue); }
public void CopyTo () { PermissionSetCollection psc = new PermissionSetCollection (); psc.CopyTo (null, 0); }
public void ToXml () { PermissionSetCollection psc = new PermissionSetCollection (); SecurityElement se = psc.ToXml (); Assert.IsNull (se.Children, "Children==null for 0"); PermissionSet unr = new PermissionSet (PermissionState.Unrestricted); psc.Add (unr); se = psc.ToXml (); Assert.AreEqual (1, se.Children.Count, "Children==1"); Assert.AreEqual (unr.ToString (), se.Children[0].ToString (), "XML"); }
public void CopyTo_ICollection () { PermissionSetCollection psc = new PermissionSetCollection (); ICollection c = (psc as ICollection); c.CopyTo (null, 0); }