2
0

MembershipUserCollectionTest.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // MembershipUserCollectionTest.cs
  3. // - Unit tests for System.Web.Security.MembershipUserCollection
  4. //
  5. // Author:
  6. // Sebastien Pouliot <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Collections;
  32. using System.Web.Security;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Web.Security {
  35. [TestFixture]
  36. public class MembershipUserCollectionTest {
  37. private MembershipUser GetMember (string name)
  38. {
  39. return new MembershipUser (Membership.Provider.Name, name, null, String.Empty, String.Empty, String.Empty,
  40. true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
  41. }
  42. [Test]
  43. public void Default ()
  44. {
  45. MembershipUserCollection muc = new MembershipUserCollection ();
  46. Assert.IsFalse (muc.IsSynchronized, "IsSynchronized");
  47. Assert.IsTrue (Object.ReferenceEquals (muc, muc.SyncRoot), "SyncRoot");
  48. }
  49. [Test]
  50. [ExpectedException (typeof (ArgumentNullException))]
  51. public void Add_Null ()
  52. {
  53. MembershipUserCollection muc = new MembershipUserCollection ();
  54. muc.Add (null);
  55. }
  56. [Test]
  57. [ExpectedException (typeof (NotSupportedException))]
  58. public void Add_ReadOnly ()
  59. {
  60. MembershipUserCollection muc = new MembershipUserCollection ();
  61. muc.SetReadOnly ();
  62. muc.Add (GetMember ("me"));
  63. }
  64. [Test]
  65. [ExpectedException (typeof (ArgumentException))]
  66. public void Add_Twice ()
  67. {
  68. MembershipUserCollection muc = new MembershipUserCollection ();
  69. muc.Add (GetMember ("me"));
  70. muc.Add (GetMember ("me"));
  71. }
  72. [Test]
  73. public void Count ()
  74. {
  75. MembershipUserCollection muc = new MembershipUserCollection ();
  76. Assert.AreEqual (0, muc.Count, "0");
  77. muc.Add (GetMember ("me"));
  78. Assert.AreEqual (1, muc.Count, "1");
  79. muc.Add (GetMember ("me too"));
  80. Assert.AreEqual (2, muc.Count, "2");
  81. muc.SetReadOnly ();
  82. Assert.AreEqual (2, muc.Count, "2b");
  83. }
  84. [Test]
  85. public void GetEnumerator ()
  86. {
  87. MembershipUserCollection muc = new MembershipUserCollection ();
  88. int i = 0;
  89. muc.Add (GetMember ("me"));
  90. muc.Add (GetMember ("me too"));
  91. IEnumerator e = muc.GetEnumerator ();
  92. Assert.IsNotNull (e, "GetEnumerator");
  93. while (e.MoveNext ()) i++;
  94. Assert.AreEqual (2, i, "2");
  95. }
  96. [Test]
  97. public void Item ()
  98. {
  99. MembershipUserCollection muc = new MembershipUserCollection ();
  100. muc.Add (GetMember ("me"));
  101. Assert.IsNotNull (muc["me"], "me");
  102. Assert.IsNull (muc["me too"], "me too");
  103. }
  104. [Test]
  105. [ExpectedException (typeof (ArgumentNullException))]
  106. public void Remove_Null ()
  107. {
  108. MembershipUserCollection muc = new MembershipUserCollection ();
  109. muc.Remove (null);
  110. }
  111. [Test]
  112. [ExpectedException (typeof (NotSupportedException))]
  113. public void Remove_ReadOnly ()
  114. {
  115. MembershipUserCollection muc = new MembershipUserCollection ();
  116. muc.Add (GetMember ("me"));
  117. muc.SetReadOnly ();
  118. muc.Remove ("me");
  119. }
  120. [Test]
  121. public void Remove_Unexisting ()
  122. {
  123. MembershipUserCollection muc = new MembershipUserCollection ();
  124. muc.Add (GetMember ("me"));
  125. muc.Remove ("me too");
  126. }
  127. [Test]
  128. public void SetReadOnly ()
  129. {
  130. MembershipUserCollection muc = new MembershipUserCollection ();
  131. muc.Add (GetMember ("me"));
  132. muc.SetReadOnly ();
  133. muc.SetReadOnly (); // twice
  134. }
  135. }
  136. }
  137. #endif