public void TestAccessRights() { var expected = new [] { AccessRight.OpenFolder, AccessRight.CreateFolder, AccessRight.DeleteFolder, AccessRight.ExpungeFolder, AccessRight.AppendMessages, AccessRight.SetMessageDeleted }; var rights = new AccessRights(); int i; Assert.IsFalse(rights.IsReadOnly, "IsReadOnly"); Assert.IsTrue(rights.Add(AccessRight.OpenFolder), "Add OpenFolder"); Assert.AreEqual(1, rights.Count, "Count after adding OpenFolder"); Assert.IsFalse(rights.Add(AccessRight.OpenFolder), "Add OpenFolder again"); Assert.AreEqual(1, rights.Count, "Count after adding OpenFolder again"); Assert.IsTrue(rights.Add(AccessRight.CreateFolder.Right), "Add CreateFolder"); Assert.AreEqual(2, rights.Count, "Count after adding CreateFolder"); Assert.IsFalse(rights.Add(AccessRight.CreateFolder), "Add CreateFolder again"); Assert.AreEqual(2, rights.Count, "Count after adding OpenFolder again"); rights.AddRange(new [] { AccessRight.DeleteFolder, AccessRight.ExpungeFolder }); Assert.AreEqual(4, rights.Count, "Count after adding DeleteFolder and ExpungeFolder"); Assert.IsTrue(rights.Contains(AccessRight.DeleteFolder), "Contains DeleteFolder"); Assert.IsTrue(rights.Contains(AccessRight.ExpungeFolder), "Contains ExpungeFolder"); Assert.IsFalse(rights.Contains(AccessRight.Administer), "Contains Administer"); rights.AddRange("it"); Assert.AreEqual(6, rights.Count, "Count after adding AppendMessages and SetMessageDeleted"); Assert.IsTrue(rights.Contains(AccessRight.AppendMessages), "Contains AppendMessages"); Assert.IsTrue(rights.Contains(AccessRight.SetMessageDeleted), "Contains SetMessageDeleted"); Assert.IsFalse(rights.Contains(AccessRight.Administer), "Contains Administer"); for (i = 0; i < 6; i++) { Assert.AreEqual(expected[i], rights[i], "rights[{0}]", i); } ((ICollection <AccessRight>)rights).Add(AccessRight.Administer); Assert.IsTrue(rights.Remove(AccessRight.Administer), "Remove Administer"); Assert.IsFalse(rights.Remove(AccessRight.Administer), "Remove Administer again"); i = 0; foreach (var right in rights) { Assert.AreEqual(expected[i], right, "foreach rights[{0}]", i++); } i = 0; foreach (AccessRight right in ((IEnumerable)rights)) { Assert.AreEqual(expected[i], right, "generic foreach rights[{0}]", i++); } var array = new AccessRight[rights.Count]; rights.CopyTo(array, 0); for (i = 0; i < 6; i++) { Assert.AreEqual(expected[i], array[i], "CopyTo[{0}]", i); } Assert.AreEqual("rkxeit", rights.ToString(), "ToString"); }