2
0

ProviderCollectionTest.cs 4.8 KB

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