SettingsPropertyCollectionTest.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 SettingsPropertyCollectionTest {
  38. [Test]
  39. public void Add ()
  40. {
  41. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  42. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  43. Assert.AreEqual (0, col.Count, "A1");
  44. col.Add (test_prop);
  45. Assert.AreEqual (1, col.Count, "A2");
  46. }
  47. [Test]
  48. [ExpectedException (typeof (ArgumentException))]
  49. public void AddDuplicate ()
  50. {
  51. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  52. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  53. col.Add (test_prop);
  54. Assert.AreEqual (1, col.Count, "A1");
  55. test_prop = new SettingsProperty ("test_prop");
  56. col.Add (test_prop);
  57. Assert.AreEqual (1, col.Count, "A2");
  58. }
  59. [Test]
  60. public void Remove ()
  61. {
  62. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  63. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  64. col.Add (test_prop);
  65. Assert.AreEqual (1, col.Count, "A1");
  66. col.Remove ("test_prop");
  67. Assert.AreEqual (0, col.Count, "A2");
  68. }
  69. [Test]
  70. public void Remove_NonExistant ()
  71. {
  72. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  73. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  74. col.Add (test_prop);
  75. Assert.AreEqual (1, col.Count, "A1");
  76. col.Remove ("test_prop2");
  77. Assert.AreEqual (1, col.Count, "A2");
  78. }
  79. [Test]
  80. public void Clear ()
  81. {
  82. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  83. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  84. col.Add (test_prop);
  85. Assert.AreEqual (1, col.Count, "A1");
  86. col.Clear ();
  87. Assert.AreEqual (0, col.Count, "A2");
  88. }
  89. [Test]
  90. [ExpectedException (typeof (NotSupportedException))]
  91. public void ReadOnly_Add ()
  92. {
  93. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  94. col.SetReadOnly ();
  95. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  96. col.Add (test_prop);
  97. }
  98. [Test]
  99. [ExpectedException (typeof (NotSupportedException))]
  100. public void ReadOnly_Remove ()
  101. {
  102. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  103. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  104. col.Add (test_prop);
  105. col.SetReadOnly ();
  106. col.Remove ("test_prop");
  107. }
  108. [Test]
  109. [ExpectedException (typeof (NotSupportedException))]
  110. public void ReadOnly_Clear ()
  111. {
  112. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  113. SettingsProperty test_prop = new SettingsProperty ("test_prop");
  114. col.Add (test_prop);
  115. col.SetReadOnly ();
  116. col.Clear ();
  117. }
  118. }
  119. }
  120. #endif