public void Copy() { foreach (PerformanceCounterPermissionAccess pcpa in AllAccess) { PerformanceCounterPermission pcp = new PerformanceCounterPermission(PermissionState.None); PerformanceCounterPermissionEntry pcpe = new PerformanceCounterPermissionEntry(pcpa, pcpa.ToString(), String.Empty); pcp.PermissionEntries.Add(pcpe); PerformanceCounterPermission copy = (PerformanceCounterPermission)pcp.Copy(); Assert.AreEqual(1, copy.PermissionEntries.Count, "Count==1"); Assert.AreEqual(pcpa, pcp.PermissionEntries [0].PermissionAccess, pcpa.ToString()); } }
public void PermissionState_Unrestricted() { PermissionState ps = PermissionState.Unrestricted; PerformanceCounterPermission pcp = new PerformanceCounterPermission(ps); Assert.AreEqual(0, pcp.PermissionEntries.Count, "PermissionEntries"); Assert.IsTrue(pcp.IsUnrestricted(), "IsUnrestricted"); SecurityElement se = pcp.ToXml(); // only class and version are present Assert.AreEqual("true", se.Attribute("Unrestricted"), "Xml-Unrestricted"); Assert.IsNull(se.Children, "Xml-Children"); PerformanceCounterPermission copy = (PerformanceCounterPermission)pcp.Copy(); Assert.IsFalse(Object.ReferenceEquals(pcp, copy), "ReferenceEquals"); Assert.AreEqual(pcp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries"); Assert.AreEqual(pcp.IsUnrestricted(), copy.IsUnrestricted(), "copy-IsUnrestricted ()"); }