public void TestArgumentExceptions() { var enumeratedRights = new [] { AccessRight.OpenFolder, AccessRight.CreateFolder }; var array = new AccessRight[10]; var rights = new AccessRights(enumeratedRights); Assert.Throws <ArgumentNullException> (() => rights.AddRange((string)null)); Assert.Throws <ArgumentNullException> (() => rights.AddRange((IEnumerable <AccessRight>)null)); Assert.Throws <ArgumentNullException> (() => new AccessRights((string)null)); Assert.Throws <ArgumentNullException> (() => new AccessRights((IEnumerable <AccessRight>)null)); Assert.Throws <ArgumentOutOfRangeException> (() => { var x = rights [-1]; }); Assert.Throws <ArgumentNullException> (() => rights.CopyTo(null, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => rights.CopyTo(array, -1)); var control = new AccessControl("control"); Assert.Throws <ArgumentNullException> (() => new AccessControl(null)); Assert.Throws <ArgumentNullException> (() => new AccessControl(null, "rk")); Assert.Throws <ArgumentNullException> (() => new AccessControl(null, enumeratedRights)); Assert.Throws <ArgumentNullException> (() => new AccessControl("name", (string)null)); Assert.Throws <ArgumentNullException> (() => new AccessControl("name", (IEnumerable <AccessRight>)null)); var list = new AccessControlList(); Assert.Throws <ArgumentNullException> (() => new AccessControlList(null)); //Assert.Throws<ArgumentNullException> (() => list.Add (null)); Assert.Throws <ArgumentNullException> (() => list.AddRange(null)); }
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"); }