SettingsPropertyTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // System.Configuration.SettingsPropertyTest.cs - Unit tests for
  3. // System.Configuration.SettingsProperty.
  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 SettingsPropertyTest {
  38. [Test]
  39. public void Ctor_1 ()
  40. {
  41. SettingsProperty p = new SettingsProperty ("property",
  42. typeof (int),
  43. null,
  44. true,
  45. 10,
  46. SettingsSerializeAs.Binary,
  47. null,
  48. true,
  49. false);
  50. Assert.AreEqual ("property", p.Name, "A1");
  51. Assert.AreEqual (typeof (int), p.PropertyType, "A2");
  52. Assert.AreEqual (null, p.Provider, "A3");
  53. Assert.AreEqual (10, (int)p.DefaultValue, "A4");
  54. Assert.AreEqual (SettingsSerializeAs.Binary, p.SerializeAs, "A5");
  55. Assert.IsNull (p.Attributes, "A6");
  56. Assert.IsTrue (p.ThrowOnErrorDeserializing, "A7");
  57. Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
  58. Assert.IsTrue (p.IsReadOnly, "A9");
  59. }
  60. [Test]
  61. public void Ctor_2 ()
  62. {
  63. SettingsProperty q = new SettingsProperty ("property",
  64. typeof (int),
  65. null,
  66. true,
  67. 10,
  68. SettingsSerializeAs.Binary,
  69. new SettingsAttributeDictionary(),
  70. true,
  71. false);
  72. SettingsProperty p = new SettingsProperty (q);
  73. Assert.AreEqual ("property", p.Name, "A1");
  74. Assert.AreEqual (typeof (int), p.PropertyType, "A2");
  75. Assert.AreEqual (null, p.Provider, "A3");
  76. Assert.AreEqual (10, (int)p.DefaultValue, "A4");
  77. Assert.AreEqual (SettingsSerializeAs.Binary, p.SerializeAs, "A5");
  78. Assert.IsNotNull (p.Attributes, "A6");
  79. Assert.IsTrue (p.ThrowOnErrorDeserializing, "A7");
  80. Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
  81. Assert.IsTrue (p.IsReadOnly, "A9");
  82. }
  83. [Test]
  84. [ExpectedException (typeof (ArgumentNullException))]
  85. public void Ctor_2_ArgNull ()
  86. {
  87. /* same as above, but a null
  88. * SettingsAttributeDictionary, which causes a
  89. * ANE in the ctor. */
  90. SettingsProperty q = new SettingsProperty ("property",
  91. typeof (int),
  92. null,
  93. true,
  94. 10,
  95. SettingsSerializeAs.Binary,
  96. null,
  97. true,
  98. false);
  99. SettingsProperty p = new SettingsProperty (q);
  100. }
  101. [Test]
  102. public void Ctor_3 ()
  103. {
  104. SettingsProperty p = new SettingsProperty ("property");
  105. Assert.AreEqual ("property", p.Name, "A1");
  106. Assert.AreEqual (null, p.PropertyType, "A2");
  107. Assert.AreEqual (null, p.Provider, "A3");
  108. Assert.AreEqual (null, p.DefaultValue, "A4");
  109. Assert.AreEqual (SettingsSerializeAs.String, p.SerializeAs, "A5");
  110. Assert.IsNotNull (p.Attributes, "A6");
  111. Assert.IsFalse (p.ThrowOnErrorDeserializing, "A7");
  112. Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
  113. Assert.IsFalse (p.IsReadOnly, "A9");
  114. }
  115. }
  116. }
  117. #endif