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