A few moves/changes following previous patch review
[mono.git] / mcs / class / System.Web / Test / System.Web.Configuration / GlobalizationSectionTest.cs
1 //
2 // GlobalizationSectionTest.cs 
3 //      - unit tests for System.Web.Configuration.GlobalizationSection
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 System.Reflection;
37 using System.Text;
38 using System.IO;
39 using System.Xml;
40 using System.Web.Configuration;
41 using System.Web;
42 using System.Web.Security;
43
44 using MonoTests.SystemWeb.Framework;
45 using MonoTests.stand_alone.WebHarness;
46
47 namespace MonoTests.System.Web.Configuration {
48
49         [TestFixture]
50         public class GlobalizationSectionTest  {
51
52                 [TestFixtureSetUp]
53                 public void SetUp ()
54                 {
55                         WebTest.CopyResource (GetType (), "GlobalizationEncodingName.aspx", "GlobalizationEncodingName.aspx");
56                 }
57                 
58                 [Test]
59                 public void Defaults ()
60                 {
61                         GlobalizationSection g = new GlobalizationSection ();
62
63                         Assert.AreEqual ("", g.Culture, "A1");
64                         Assert.IsFalse (g.EnableBestFitResponseEncoding, "A2");
65                         Assert.IsFalse (g.EnableClientBasedCulture, "A3");
66
67                         // XXX FileEncoding?
68
69                         Assert.AreEqual (Encoding.UTF8, g.RequestEncoding, "A5");
70                         Assert.AreEqual ("", g.ResourceProviderFactoryType, "A6");
71                         Assert.AreEqual (Encoding.UTF8, g.ResponseHeaderEncoding, "A7");
72                         Assert.AreEqual ("", g.UICulture, "A8");
73                 }
74
75                 [Test]
76                 public void PreSerialize ()
77                 {
78                         StringWriter sw;
79                         XmlWriter writer;
80                         MethodInfo mi = typeof (GlobalizationSection).GetMethod ("PreSerialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
81                         GlobalizationSection s;
82                         object[] parms = new object[1];
83                         bool failed;
84
85                         sw = new StringWriter ();
86                         writer = new XmlTextWriter (sw);
87
88                         s = new GlobalizationSection();
89                         parms[0] = writer;
90
91                         /* 1 */
92                         mi.Invoke (s, parms);
93
94                         /* 2 */
95                         failed = true;
96                         try {
97                                 s.Culture = "illegal-culture";
98                                 mi.Invoke (s, parms);
99                         }
100                         catch (TargetInvocationException e) {
101                                 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A2");
102                                 failed = false;
103                         }
104                         Assert.IsFalse (failed, "A2");
105
106                         /* 3 */
107                         failed = true;
108                         try {
109                                 s.Culture = "";
110                                 s.UICulture = "illegal-culture";
111                                 mi.Invoke (s, parms);
112                         }
113                         catch (TargetInvocationException e) {
114                                 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A3");
115                                 failed = false;
116                         }
117                         Assert.IsFalse (failed, "A3");
118
119                         /* 4 */
120                         s.Culture = "";
121                         s.UICulture = "";
122                         s.ResourceProviderFactoryType = "invalid-type";
123                         mi.Invoke (s, parms);
124
125                         /* 5  (null writer) */
126                         parms[0] =null;
127                         mi.Invoke (s, parms);
128                 }
129
130                 [Test]
131                 public void PostDeserialize ()
132                 {
133                         MethodInfo mi = typeof (GlobalizationSection).GetMethod ("PostDeserialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
134                         GlobalizationSection s;
135                         object[] parms = new object[0];
136                         bool failed;
137
138                         s = new GlobalizationSection();
139
140                         /* 1 */
141                         mi.Invoke (s, parms);
142
143                         /* 2 */
144                         failed = true;
145                         try {
146                                 s.Culture = "illegal-culture";
147                                 mi.Invoke (s, parms);
148                         }
149                         catch (TargetInvocationException e) {
150                                 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A2");
151                                 failed = false;
152                         }
153                         Assert.IsFalse (failed, "A2");
154
155                         failed = true;
156                         try {
157                                 s.Culture = "";
158                                 s.UICulture = "illegal-culture";
159                                 mi.Invoke (s, parms);
160                         }
161                         catch (TargetInvocationException e) {
162                                 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A3");
163                                 failed = false;
164                         }
165                         Assert.IsFalse (failed, "A3");
166
167                         s.Culture = "";
168                         s.UICulture = "";
169                         s.ResourceProviderFactoryType = "invalid-type";
170                         mi.Invoke (s, parms);
171                 }
172
173                 [Test]
174                 public void GlobalizationEncodingName ()
175                 {
176                         string pageHtml = new WebTest ("GlobalizationEncodingName.aspx").Run ();
177                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
178                         string originalHtml = "GOOD";
179                         Assert.AreEqual (originalHtml, renderedHtml, "#A1");
180                 }
181                 
182         }
183 }
184
185 #endif