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