CollectionTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // MonoTests.System.Collections.Generic.Test.CollectionTest
  3. //
  4. // Authors:
  5. // David Waite ([email protected])
  6. //
  7. // Copyright (C) 2005 David Waite
  8. //
  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:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  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.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Collections;
  31. using System.Collections.Generic;
  32. using System.Collections.ObjectModel;
  33. using System.Text;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.Collections.ObjectModel
  36. {
  37. [TestFixture]
  38. public class CollectionTest
  39. {
  40. [Test]
  41. public void UsableSyncLockTest ()
  42. {
  43. List <int> list = new List <int> ();
  44. Collection <int> c = new Collection <int> (list);
  45. object listLock = ((ICollection) list).SyncRoot;
  46. object cLock = ((ICollection) c).SyncRoot;
  47. Assert.AreSame (listLock, cLock);
  48. }
  49. [Test]
  50. public void UnusableSyncLockTest ()
  51. {
  52. UnimplementedList <int> list = new UnimplementedList <int> ();
  53. Collection <int> c = new Collection <int> (list);
  54. object cLock = ((ICollection) c).SyncRoot;
  55. Assert.IsNotNull (cLock);
  56. Assert.IsTrue (cLock.GetType ().Equals (typeof (object)));
  57. }
  58. class UnimplementedList <T> : IList <T>
  59. {
  60. #region IList <T> Members
  61. int IList <T>.IndexOf (T item)
  62. {
  63. throw new Exception ("The method or operation is not implemented.");
  64. }
  65. void IList <T>.Insert (int index, T item)
  66. {
  67. throw new Exception ("The method or operation is not implemented.");
  68. }
  69. void IList <T>.RemoveAt (int index)
  70. {
  71. throw new Exception ("The method or operation is not implemented.");
  72. }
  73. T IList <T>.this [int index]
  74. {
  75. get
  76. {
  77. throw new Exception ("The method or operation is not implemented.");
  78. }
  79. set
  80. {
  81. throw new Exception ("The method or operation is not implemented.");
  82. }
  83. }
  84. #endregion
  85. #region ICollection <T> Members
  86. void ICollection <T>.Add (T item)
  87. {
  88. throw new Exception ("The method or operation is not implemented.");
  89. }
  90. void ICollection <T>.Clear ()
  91. {
  92. throw new Exception ("The method or operation is not implemented.");
  93. }
  94. bool ICollection <T>.Contains (T item)
  95. {
  96. throw new Exception ("The method or operation is not implemented.");
  97. }
  98. void ICollection <T>.CopyTo (T [] array, int arrayIndex)
  99. {
  100. throw new Exception ("The method or operation is not implemented.");
  101. }
  102. int ICollection <T>.Count
  103. {
  104. get { throw new Exception ("The method or operation is not implemented."); }
  105. }
  106. bool ICollection <T>.IsReadOnly
  107. {
  108. get { throw new Exception ("The method or operation is not implemented."); }
  109. }
  110. bool ICollection <T>.Remove (T item)
  111. {
  112. throw new Exception ("The method or operation is not implemented.");
  113. }
  114. #endregion
  115. #region IEnumerable <T> Members
  116. IEnumerator <T> IEnumerable <T>.GetEnumerator ()
  117. {
  118. throw new Exception ("The method or operation is not implemented.");
  119. }
  120. #endregion
  121. #region IEnumerable Members
  122. IEnumerator IEnumerable.GetEnumerator ()
  123. {
  124. throw new Exception ("The method or operation is not implemented.");
  125. }
  126. #endregion
  127. }
  128. }
  129. }
  130. #endif