ProviderCollectionTest.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // System.Configuration.ProviderCollectionTest.cs - Unit tests for
  3. // System.Configuration.ProviderCollection.
  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.Configuration.Provider;
  34. using System.Collections.Specialized;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Configuration {
  37. class TestProvider : SettingsProvider {
  38. public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
  39. SettingsPropertyCollection collection)
  40. {
  41. throw new NotImplementedException ();
  42. }
  43. public override void SetPropertyValues (SettingsContext context,
  44. SettingsPropertyValueCollection collection)
  45. {
  46. throw new NotImplementedException ();
  47. }
  48. public override string ApplicationName {
  49. get {
  50. throw new NotImplementedException ();
  51. }
  52. set {
  53. throw new NotImplementedException ();
  54. }
  55. }
  56. }
  57. class TestProviderBase : ProviderBase {
  58. }
  59. [TestFixture]
  60. public class ProviderCollectionTest {
  61. [Test]
  62. [ExpectedException (typeof (ArgumentException))]
  63. public void Add_duplicate ()
  64. {
  65. ProviderCollection col = new ProviderCollection();
  66. TestProvider provider;
  67. provider = new TestProvider();
  68. provider.Initialize ("test", null);
  69. col.Add (provider);
  70. col.Add (provider);
  71. }
  72. [Test]
  73. public void Add_providerbase ()
  74. {
  75. ProviderCollection col = new ProviderCollection();
  76. TestProviderBase provider;
  77. provider = new TestProviderBase();
  78. provider.Initialize ("test", null);
  79. col.Add (provider);
  80. Assert.AreEqual (provider, col["test"], "A1");
  81. }
  82. [Test]
  83. public void Get_nonexistant ()
  84. {
  85. ProviderCollection col = new ProviderCollection();
  86. TestProvider provider;
  87. provider = new TestProvider();
  88. provider.Initialize ("test", null);
  89. col.Add (provider);
  90. Assert.AreEqual (provider, col["test"], "A1");
  91. Assert.IsNull (col["test2"], "A2");
  92. }
  93. [Test]
  94. public void Ctor_2 ()
  95. {
  96. SettingsProperty q = new SettingsProperty ("property",
  97. typeof (int),
  98. null,
  99. true,
  100. 10,
  101. SettingsSerializeAs.Binary,
  102. new SettingsAttributeDictionary(),
  103. true,
  104. false);
  105. SettingsProperty p = new SettingsProperty (q);
  106. Assert.AreEqual ("property", p.Name, "A1");
  107. Assert.AreEqual (typeof (int), p.PropertyType, "A2");
  108. Assert.AreEqual (null, p.Provider, "A3");
  109. Assert.AreEqual (10, (int)p.DefaultValue, "A4");
  110. Assert.AreEqual (SettingsSerializeAs.Binary, p.SerializeAs, "A5");
  111. Assert.IsNotNull (p.Attributes, "A6");
  112. Assert.IsTrue (p.ThrowOnErrorDeserializing, "A7");
  113. Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
  114. Assert.IsTrue (p.IsReadOnly, "A9");
  115. }
  116. [Test]
  117. [ExpectedException (typeof (ArgumentNullException))]
  118. public void Ctor_2_ArgNull ()
  119. {
  120. /* same as above, but a null
  121. * SettingsAttributeDictionary, which causes a
  122. * ANE in the ctor. */
  123. SettingsProperty q = new SettingsProperty ("property",
  124. typeof (int),
  125. null,
  126. true,
  127. 10,
  128. SettingsSerializeAs.Binary,
  129. null,
  130. true,
  131. false);
  132. SettingsProperty p = new SettingsProperty (q);
  133. }
  134. [Test]
  135. public void Ctor_3 ()
  136. {
  137. SettingsProperty p = new SettingsProperty ("property");
  138. Assert.AreEqual ("property", p.Name, "A1");
  139. Assert.AreEqual (null, p.PropertyType, "A2");
  140. Assert.AreEqual (null, p.Provider, "A3");
  141. Assert.AreEqual (null, p.DefaultValue, "A4");
  142. Assert.AreEqual (SettingsSerializeAs.String, p.SerializeAs, "A5");
  143. Assert.IsNotNull (p.Attributes, "A6");
  144. Assert.IsFalse (p.ThrowOnErrorDeserializing, "A7");
  145. Assert.IsFalse (p.ThrowOnErrorSerializing, "A8");
  146. Assert.IsFalse (p.IsReadOnly, "A9");
  147. }
  148. }
  149. }
  150. #endif