+2008-01-20 Juraj Skripsky <js@hotfeet.ch>
+
+ * ReadOnlyCollection.cs: Fix the getters for ICollection.IsSynchronized,
+ ICollection.SyncRoot and IList.IsFixedSize to match MS.NET.
+
2008-01-13 Juraj Skripsky <js@hotfeet.ch>
* Collection.cs, ReadonlyCollection.cs (ICollection.CopyTo):
public class ReadOnlyCollection <T> : IList <T>, ICollection <T>, IEnumerable <T>, IList, ICollection, IEnumerable
{
IList <T> list;
- object syncRoot;
public ReadOnlyCollection (IList <T> list)
{
if (list == null)
throw new ArgumentNullException ("list");
this.list = list;
- ICollection c = list as ICollection;
- syncRoot = (c != null) ? c.SyncRoot : new object ();
}
void ICollection<T>.Add (T item)
}
bool ICollection.IsSynchronized {
- get { return Collection <T>.IsSynchronized (list); }
+ get { return false; }
}
object ICollection.SyncRoot {
- get { return syncRoot; }
+ get { return this; }
}
bool IList.IsFixedSize {
- get { return Collection <T>.IsFixedSize (list); }
+ get { return true; }
}
bool IList.IsReadOnly {
+2008-01-20 Juraj Skripsky <js@hotfeet.ch>
+
+ * ReadOnlyCollectionTest.cs: Add test to verify that ReadOnlyCollection
+ is indeed only a simple wrapper for a given IList.
+ Add tests for ICollection.IsSynchronized, IList.IsFixedSize and
+ IList.IsReadOnly.
+
2008-01-13 Gert Driesen <drieseng@users.sourceforge.net>
* CollectionTest.cs: Added test for ICollection.CopyTo.
namespace MonoTests.System.Collections.ObjectModel
{
+ class SyncPretendingList<T> : List<T>, ICollection
+ {
+ bool ICollection.IsSynchronized {
+ get { return true; }
+ }
+ }
+
[TestFixture]
public class ReadOnlyCollectionTest
{
Assert.AreEqual (10, r [0], "#1");
Assert.AreEqual (7, r [1], "#2");
}
+
+ [Test]
+ public void IsSimpleWrapper ()
+ {
+ Collection <int> c = new Collection <int> ();
+ c.Add (1);
+
+ ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (c);
+ Assert.AreEqual (1, r.Count, "#1");
+
+ c.Remove (1);
+ Assert.AreEqual (0, r.Count, "#2");
+ }
+
+ [Test]
+ public void IList_Properties ()
+ {
+ List <int> l = new List <int> ();
+ ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (l);
+
+ Assert.IsTrue (((IList)r).IsReadOnly, "#1");
+ Assert.IsTrue (((IList)r).IsFixedSize, "#2");
+ }
+
+ [Test]
+ public void ICollection_Properties ()
+ {
+ List <int> l = new SyncPretendingList <int> ();
+ ReadOnlyCollection <int> r = new ReadOnlyCollection <int> (l);
+
+ Assert.IsFalse (((ICollection)r).IsSynchronized, "#1");
+ }
[Test]
public void Constructor0_List_Null ()