WebConfigurationManagerTest.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // WebConfigurationManagerTest.cs
  3. // - unit tests for System.Web.Configuration.WebConfigurationManager
  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 NUnit.Framework;
  31. using System;
  32. using System.Configuration;
  33. using _Configuration = System.Configuration.Configuration;
  34. using System.IO;
  35. using System.Web.Configuration;
  36. using System.Web;
  37. using System.Web.Security;
  38. namespace MonoTests.System.Web.Configuration {
  39. [TestFixture]
  40. public class WebConfigurationManagerTest {
  41. [Test]
  42. public void OpenMachineConfiguration_1 ()
  43. {
  44. _Configuration c1 = WebConfigurationManager.OpenMachineConfiguration ();
  45. _Configuration c2 = ConfigurationManager.OpenMachineConfiguration ();
  46. Assert.AreEqual (c1.FilePath, c2.FilePath, "A1");
  47. }
  48. [Test]
  49. public void OpenMachineConfiguration_2 ()
  50. {
  51. _Configuration c1 = WebConfigurationManager.OpenMachineConfiguration ("configTest");
  52. _Configuration c2 = ConfigurationManager.OpenMachineConfiguration ();
  53. Assert.AreEqual (c1.FilePath, c2.FilePath, "A1");
  54. }
  55. [Test]
  56. public void OpenMachineConfiguration_serverNull ()
  57. {
  58. _Configuration c1 = WebConfigurationManager.OpenMachineConfiguration ("configTest", null);
  59. _Configuration c2 = ConfigurationManager.OpenMachineConfiguration ();
  60. Assert.AreEqual (c1.FilePath, c2.FilePath, "A1");
  61. }
  62. [Test]
  63. [Category ("NotWorking")]
  64. public void OpenWebConfiguration_null ()
  65. {
  66. _Configuration web = WebConfigurationManager.OpenWebConfiguration (null);
  67. _Configuration machine = ConfigurationManager.OpenMachineConfiguration ();
  68. Assert.AreEqual ("web.config", Path.GetFileName (web.FilePath), "A1");
  69. Assert.AreEqual (Path.GetDirectoryName (web.FilePath), Path.GetDirectoryName (machine.FilePath), "A2");
  70. }
  71. [Test]
  72. [Category ("NotWorking")]
  73. public void OpenWebConfiguration_empty ()
  74. {
  75. _Configuration web1 = WebConfigurationManager.OpenWebConfiguration (null);
  76. _Configuration web2 = WebConfigurationManager.OpenWebConfiguration ("");
  77. _Configuration machine = ConfigurationManager.OpenMachineConfiguration ();
  78. Assert.AreEqual (web1.FilePath, web2.FilePath, "A1");
  79. Assert.AreEqual (Path.GetDirectoryName (web2.FilePath), Path.GetDirectoryName (machine.FilePath), "A2");
  80. }
  81. [Test]
  82. [Category ("NotWorking")]
  83. public void OpenWebConfiguration_siteNull ()
  84. {
  85. _Configuration web = WebConfigurationManager.OpenWebConfiguration ("", null);
  86. _Configuration machine = ConfigurationManager.OpenMachineConfiguration ();
  87. Assert.AreEqual ("web.config", Path.GetFileName (web.FilePath), "A1");
  88. Assert.AreEqual (Path.GetDirectoryName (web.FilePath), Path.GetDirectoryName (machine.FilePath), "A2");
  89. }
  90. [Test]
  91. [Category ("NotWorking")]
  92. [ExpectedException (typeof (ConfigurationErrorsException))]
  93. public void OpenWebConfiguration_siteNull2_absolutePath ()
  94. {
  95. WebConfigurationManager.OpenWebConfiguration ("", null, "/clientTest");
  96. }
  97. [Test]
  98. [Category ("NotWorking")]
  99. public void OpenWebConfiguration_siteNull2 ()
  100. {
  101. _Configuration web = WebConfigurationManager.OpenWebConfiguration ("", null, "clientTest");
  102. _Configuration machine = ConfigurationManager.OpenMachineConfiguration ();
  103. Assert.AreEqual ("web.config", Path.GetFileName (web.FilePath), "A1");
  104. Assert.AreEqual (Path.GetDirectoryName (web.FilePath), Path.GetDirectoryName (machine.FilePath), "A2");
  105. }
  106. [Test]
  107. [Category ("NotWorking")]
  108. public void GetWebApplicationSection_1 ()
  109. {
  110. Assert.IsNotNull (WebConfigurationManager.GetWebApplicationSection ("system.web/clientTarget"), "A1");
  111. }
  112. [Test]
  113. [Category ("NotWorking")]
  114. public void GetSection_1 ()
  115. {
  116. object sect1 = WebConfigurationManager.GetSection ("system.web/clientTarget");
  117. object sect2 = WebConfigurationManager.GetSection ("system.web/clientTarget");
  118. Assert.AreEqual (sect1, sect2, "A1");
  119. sect1 = WebConfigurationManager.GetSection ("foo");
  120. Assert.IsNull (sect1);
  121. sect1 = WebConfigurationManager.GetSection ("appSettings");
  122. Assert.IsNotNull (sect1, "A2");
  123. sect1 = WebConfigurationManager.GetSection ("connectionStrings");
  124. Assert.IsNotNull (sect1, "A3");
  125. }
  126. [Test]
  127. [Category ("NotWorking")]
  128. [ExpectedException (typeof (InvalidOperationException))]
  129. // InvalidOperationException (WebConfigurationManager.GetSection(sectionName,path) can only be called from within a web application.)
  130. // thrown from WebConfigurationManager.GetSection
  131. public void GetSection_2 ()
  132. {
  133. object sect1 = WebConfigurationManager.GetSection ("system.web/clientTarget", "/clientTest");
  134. Assert.IsNull (sect1, "A1");
  135. }
  136. [Test]
  137. [Category ("NotWorking")]
  138. public void OpenMappedMachineConfiguration ()
  139. {
  140. ConfigurationFileMap map = new ConfigurationFileMap ();
  141. _Configuration c1 = WebConfigurationManager.OpenMappedMachineConfiguration (map, "clientTest");
  142. _Configuration c2 = ConfigurationManager.OpenMappedMachineConfiguration (map);
  143. Assert.AreEqual (c1.FilePath, c2.FilePath, "A1");
  144. }
  145. [Test]
  146. [Category ("NotWorking")]
  147. [ExpectedException (typeof (ConfigurationErrorsException))]
  148. // same stack trace for OpenWebConfiguration_siteNull2_absolutePath.
  149. public void OpenMappedMachineConfiguration_absolute ()
  150. {
  151. ConfigurationFileMap map = new ConfigurationFileMap ();
  152. WebConfigurationManager.OpenMappedMachineConfiguration (map, "/clientTest");
  153. }
  154. [Test]
  155. public void StaticProps ()
  156. {
  157. Assert.IsNotNull (WebConfigurationManager.AppSettings, "A1");
  158. Assert.IsNotNull (WebConfigurationManager.ConnectionStrings, "A2");
  159. }
  160. }
  161. }
  162. #endif