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.
32 using System.Collections;
33 using System.Web.Security;
35 using NUnit.Framework;
37 namespace MonoTests.System.Web.Security {
40 public class MembershipUserCollectionTest {
42 private MembershipUser GetMember (string name)
44 return new MembershipUser (Membership.Provider.Name, name, null, String.Empty, String.Empty, String.Empty,
45 true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
49 public void Default ()
51 MembershipUserCollection muc = new MembershipUserCollection ();
52 Assert.IsFalse (muc.IsSynchronized, "IsSynchronized");
53 Assert.IsTrue (Object.ReferenceEquals (muc, muc.SyncRoot), "SyncRoot");
57 [ExpectedException (typeof (ArgumentNullException))]
58 public void Add_Null ()
60 MembershipUserCollection muc = new MembershipUserCollection ();
65 [ExpectedException (typeof (NotSupportedException))]
66 public void Add_ReadOnly ()
68 MembershipUserCollection muc = new MembershipUserCollection ();
70 muc.Add (GetMember ("me"));
74 [ExpectedException (typeof (ArgumentException))]
75 public void Add_Twice ()
77 MembershipUserCollection muc = new MembershipUserCollection ();
78 muc.Add (GetMember ("me"));
79 muc.Add (GetMember ("me"));
85 MembershipUserCollection muc = new MembershipUserCollection ();
86 Assert.AreEqual (0, muc.Count, "0");
87 muc.Add (GetMember ("me"));
88 Assert.AreEqual (1, muc.Count, "1");
89 muc.Add (GetMember ("me too"));
90 Assert.AreEqual (2, muc.Count, "2");
92 Assert.AreEqual (2, muc.Count, "2b");
96 public void GetEnumerator ()
98 MembershipUserCollection muc = new MembershipUserCollection ();
100 muc.Add (GetMember ("me"));
101 muc.Add (GetMember ("me too"));
102 IEnumerator e = muc.GetEnumerator ();
103 Assert.IsNotNull (e, "GetEnumerator");
104 while (e.MoveNext ()) i++;
105 Assert.AreEqual (2, i, "2");
111 MembershipUserCollection muc = new MembershipUserCollection ();
112 muc.Add (GetMember ("me"));
113 Assert.IsNotNull (muc["me"], "me");
114 Assert.IsNull (muc["me too"], "me too");
118 [ExpectedException (typeof (ArgumentNullException))]
119 public void Remove_Null ()
121 MembershipUserCollection muc = new MembershipUserCollection ();
126 [ExpectedException (typeof (NotSupportedException))]
127 public void Remove_ReadOnly ()
129 MembershipUserCollection muc = new MembershipUserCollection ();
130 muc.Add (GetMember ("me"));
136 public void Remove_Unexisting ()
138 MembershipUserCollection muc = new MembershipUserCollection ();
139 muc.Add (GetMember ("me"));
140 muc.Remove ("me too");
144 public void SetReadOnly ()
146 MembershipUserCollection muc = new MembershipUserCollection ();
147 muc.Add (GetMember ("me"));
149 muc.SetReadOnly (); // twice