SettingsPropertyValueCollectionTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // System.Configuration.SettingsPropertyCollectionTest.cs - Unit tests
  3. // for System.Configuration.SettingsPropertyCollection.
  4. //
  5. // Author:
  6. // Chris Toshok <[email protected]>
  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. #if NET_2_0
  30. using System;
  31. using System.Text;
  32. using System.Configuration;
  33. using System.Collections.Specialized;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.Configuration {
  36. [TestFixture]
  37. public class SettingsPropertyValueCollectionTest {
  38. [Test]
  39. public void Add ()
  40. {
  41. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  42. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  43. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  44. Assert.AreEqual (0, col.Count, "A1");
  45. col.Add (val);
  46. Assert.AreEqual (1, col.Count, "A2");
  47. }
  48. [Test]
  49. [ExpectedException (typeof (ArgumentException))]
  50. public void AddDuplicate ()
  51. {
  52. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  53. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  54. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  55. col.Add (val);
  56. Assert.AreEqual (1, col.Count, "A1");
  57. col.Add (val);
  58. Assert.AreEqual (1, col.Count, "A2");
  59. }
  60. [Test]
  61. public void Remove ()
  62. {
  63. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  64. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  65. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  66. col.Add (val);
  67. Assert.AreEqual (1, col.Count, "A1");
  68. col.Remove ("test_prop");
  69. Assert.AreEqual (0, col.Count, "A2");
  70. }
  71. [Test]
  72. public void Remove_NonExistant ()
  73. {
  74. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  75. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  76. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  77. col.Add (val);
  78. Assert.AreEqual (1, col.Count, "A1");
  79. col.Remove ("test_prop2");
  80. Assert.AreEqual (1, col.Count, "A2");
  81. }
  82. [Test]
  83. public void Clear ()
  84. {
  85. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  86. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  87. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  88. col.Add (val);
  89. Assert.AreEqual (1, col.Count, "A1");
  90. col.Clear ();
  91. Assert.AreEqual (0, col.Count, "A2");
  92. }
  93. [Test]
  94. [ExpectedException (typeof (NotSupportedException))]
  95. public void ReadOnly_Add ()
  96. {
  97. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  98. col.SetReadOnly ();
  99. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  100. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  101. col.Add (val);
  102. }
  103. [Test]
  104. [ExpectedException (typeof (NotSupportedException))]
  105. public void ReadOnly_Remove ()
  106. {
  107. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  108. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  109. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  110. col.Add (val);
  111. col.SetReadOnly ();
  112. col.Remove ("test_prop");
  113. }
  114. [Test]
  115. [ExpectedException (typeof (NotSupportedException))]
  116. public void ReadOnly_Clear ()
  117. {
  118. SettingsPropertyValueCollection col = new SettingsPropertyValueCollection ();
  119. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  120. SettingsPropertyValue val = new SettingsPropertyValue (test_prop);
  121. col.Add (val);
  122. col.SetReadOnly ();
  123. col.Clear ();
  124. }
  125. }
  126. }
  127. #endif