2006-12-10 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.Security / MembershipUserCollectionTest.cs
1 //
2 // MembershipUserCollectionTest.cs
3 //      - Unit tests for System.Web.Security.MembershipUserCollection
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
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
30 #if NET_2_0
31
32 using System;
33 using System.Collections;
34 using System.Web.Security;
35
36 using NUnit.Framework;
37
38 namespace MonoTests.System.Web.Security {
39
40         [TestFixture]
41         public class MembershipUserCollectionTest {
42
43                 private MembershipUser GetMember (string name)
44                 {
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);
47                 }
48
49                 [Test]
50                 public void Default ()
51                 {
52                         MembershipUserCollection muc = new MembershipUserCollection ();
53                         Assert.IsFalse (muc.IsSynchronized, "IsSynchronized");
54                         Assert.IsTrue (Object.ReferenceEquals (muc, muc.SyncRoot), "SyncRoot");
55                 }
56
57                 [Test]
58                 [ExpectedException (typeof (ArgumentNullException))]
59                 public void Add_Null ()
60                 {
61                         MembershipUserCollection muc = new MembershipUserCollection ();
62                         muc.Add (null);
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (NotSupportedException))]
67                 public void Add_ReadOnly ()
68                 {
69                         MembershipUserCollection muc = new MembershipUserCollection ();
70                         muc.SetReadOnly ();
71                         muc.Add (GetMember ("me"));
72                 }
73
74                 [Test]
75                 [ExpectedException (typeof (ArgumentException))]
76                 public void Add_Twice ()
77                 {
78                         MembershipUserCollection muc = new MembershipUserCollection ();
79                         muc.Add (GetMember ("me"));
80                         muc.Add (GetMember ("me"));
81                 }
82
83                 [Test]
84                 public void Count ()
85                 {
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");
92                         muc.SetReadOnly ();
93                         Assert.AreEqual (2, muc.Count, "2b");
94                 }
95
96                 [Test]
97                 public void GetEnumerator ()
98                 {
99                         MembershipUserCollection muc = new MembershipUserCollection ();
100                         int i = 0;
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");
107                 }
108
109                 [Test]
110                 public void Item ()
111                 {
112                         MembershipUserCollection muc = new MembershipUserCollection ();
113                         muc.Add (GetMember ("me"));
114                         Assert.IsNotNull (muc["me"], "me");
115                         Assert.IsNull (muc["me too"], "me too");
116                 }
117
118                 [Test]
119                 [ExpectedException (typeof (ArgumentNullException))]
120                 public void Remove_Null ()
121                 {
122                         MembershipUserCollection muc = new MembershipUserCollection ();
123                         muc.Remove (null);
124                 }
125
126                 [Test]
127                 [ExpectedException (typeof (NotSupportedException))]
128                 public void Remove_ReadOnly ()
129                 {
130                         MembershipUserCollection muc = new MembershipUserCollection ();
131                         muc.Add (GetMember ("me"));
132                         muc.SetReadOnly ();
133                         muc.Remove ("me");
134                 }
135
136                 [Test]
137                 public void Remove_Unexisting ()
138                 {
139                         MembershipUserCollection muc = new MembershipUserCollection ();
140                         muc.Add (GetMember ("me"));
141                         muc.Remove ("me too");
142                 }
143
144                 [Test]
145                 public void SetReadOnly ()
146                 {
147                         MembershipUserCollection muc = new MembershipUserCollection ();
148                         muc.Add (GetMember ("me"));
149                         muc.SetReadOnly ();
150                         muc.SetReadOnly ();     // twice
151                 }
152         }
153 }
154
155 #endif