2 // MembershipUserCollectionTest.cs
3 // - Unit tests for System.Web.Security.MembershipUserCollection
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
33 using System.Collections;
34 using System.Web.Security;
36 using NUnit.Framework;
38 namespace MonoTests.System.Web.Security {
41 public class MembershipUserCollectionTest {
43 private MembershipUser GetMember (string name)
45 return new MembershipUser (Membership.Provider.Name, name, null, String.Empty, String.Empty, String.Empty,
46 true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
50 public void Default ()
52 MembershipUserCollection muc = new MembershipUserCollection ();
53 Assert.IsFalse (muc.IsSynchronized, "IsSynchronized");
54 Assert.IsTrue (Object.ReferenceEquals (muc, muc.SyncRoot), "SyncRoot");
58 [ExpectedException (typeof (ArgumentNullException))]
59 public void Add_Null ()
61 MembershipUserCollection muc = new MembershipUserCollection ();
66 [ExpectedException (typeof (NotSupportedException))]
67 public void Add_ReadOnly ()
69 MembershipUserCollection muc = new MembershipUserCollection ();
71 muc.Add (GetMember ("me"));
75 [ExpectedException (typeof (ArgumentException))]
76 public void Add_Twice ()
78 MembershipUserCollection muc = new MembershipUserCollection ();
79 muc.Add (GetMember ("me"));
80 muc.Add (GetMember ("me"));
86 MembershipUserCollection muc = new MembershipUserCollection ();
87 Assert.AreEqual (0, muc.Count, "0");
88 muc.Add (GetMember ("me"));
89 Assert.AreEqual (1, muc.Count, "1");
90 muc.Add (GetMember ("me too"));
91 Assert.AreEqual (2, muc.Count, "2");
93 Assert.AreEqual (2, muc.Count, "2b");
97 public void GetEnumerator ()
99 MembershipUserCollection muc = new MembershipUserCollection ();
101 muc.Add (GetMember ("me"));
102 muc.Add (GetMember ("me too"));
103 IEnumerator e = muc.GetEnumerator ();
104 Assert.IsNotNull (e, "GetEnumerator");
105 while (e.MoveNext ()) i++;
106 Assert.AreEqual (2, i, "2");
112 MembershipUserCollection muc = new MembershipUserCollection ();
113 muc.Add (GetMember ("me"));
114 Assert.IsNotNull (muc["me"], "me");
115 Assert.IsNull (muc["me too"], "me too");
119 [ExpectedException (typeof (ArgumentNullException))]
120 public void Remove_Null ()
122 MembershipUserCollection muc = new MembershipUserCollection ();
127 [ExpectedException (typeof (NotSupportedException))]
128 public void Remove_ReadOnly ()
130 MembershipUserCollection muc = new MembershipUserCollection ();
131 muc.Add (GetMember ("me"));
137 public void Remove_Unexisting ()
139 MembershipUserCollection muc = new MembershipUserCollection ();
140 muc.Add (GetMember ("me"));
141 muc.Remove ("me too");
145 public void SetReadOnly ()
147 MembershipUserCollection muc = new MembershipUserCollection ();
148 muc.Add (GetMember ("me"));
150 muc.SetReadOnly (); // twice