2 // MonoTests.System.Collections.Generic.Test.CollectionTest
5 // David Waite (mass@akuma.org)
7 // Copyright (C) 2005 David Waite
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Generic;
34 using System.Collections.ObjectModel;
36 using NUnit.Framework;
38 namespace MonoTests.System.Collections.ObjectModel
41 public class CollectionTest
44 public void UsableSyncLockTest ()
46 List <int> list = new List <int> ();
47 Collection <int> c = new Collection <int> (list);
49 object listLock = ((ICollection) list).SyncRoot;
50 object cLock = ((ICollection) c).SyncRoot;
52 Assert.AreSame (listLock, cLock);
56 public void UnusableSyncLockTest ()
58 UnimplementedList <int> list = new UnimplementedList <int> ();
59 Collection <int> c = new Collection <int> (list);
61 object cLock = ((ICollection) c).SyncRoot;
63 Assert.IsNotNull (cLock);
64 Assert.IsTrue (cLock.GetType ().Equals (typeof (object)));
67 class UnimplementedList <T> : IList <T>
70 #region IList <T> Members
72 int IList <T>.IndexOf (T item)
74 throw new Exception ("The method or operation is not implemented.");
77 void IList <T>.Insert (int index, T item)
79 throw new Exception ("The method or operation is not implemented.");
82 void IList <T>.RemoveAt (int index)
84 throw new Exception ("The method or operation is not implemented.");
87 T IList <T>.this [int index]
91 throw new Exception ("The method or operation is not implemented.");
95 throw new Exception ("The method or operation is not implemented.");
101 #region ICollection <T> Members
103 void ICollection <T>.Add (T item)
105 throw new Exception ("The method or operation is not implemented.");
108 void ICollection <T>.Clear ()
110 throw new Exception ("The method or operation is not implemented.");
113 bool ICollection <T>.Contains (T item)
115 throw new Exception ("The method or operation is not implemented.");
118 void ICollection <T>.CopyTo (T [] array, int arrayIndex)
120 throw new Exception ("The method or operation is not implemented.");
123 int ICollection <T>.Count
125 get { throw new Exception ("The method or operation is not implemented."); }
128 bool ICollection <T>.IsReadOnly
130 get { throw new Exception ("The method or operation is not implemented."); }
133 bool ICollection <T>.Remove (T item)
135 throw new Exception ("The method or operation is not implemented.");
140 #region IEnumerable <T> Members
142 IEnumerator <T> IEnumerable <T>.GetEnumerator ()
144 throw new Exception ("The method or operation is not implemented.");
149 #region IEnumerable Members
151 IEnumerator IEnumerable.GetEnumerator ()
153 throw new Exception ("The method or operation is not implemented.");