2 // GlobalizationSectionTest.cs
3 // - unit tests for System.Web.Configuration.GlobalizationSection
6 // Chris Toshok <toshok@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using NUnit.Framework;
35 using System.Configuration;
36 using System.Reflection;
40 using System.Web.Configuration;
42 using System.Web.Security;
44 using MonoTests.SystemWeb.Framework;
45 using MonoTests.stand_alone.WebHarness;
47 namespace MonoTests.System.Web.Configuration {
50 public class GlobalizationSectionTest {
55 WebTest.CopyResource (GetType (), "GlobalizationEncodingName.aspx", "GlobalizationEncodingName.aspx");
59 public void Defaults ()
61 GlobalizationSection g = new GlobalizationSection ();
63 Assert.AreEqual ("", g.Culture, "A1");
64 Assert.IsFalse (g.EnableBestFitResponseEncoding, "A2");
65 Assert.IsFalse (g.EnableClientBasedCulture, "A3");
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");
76 public void PreSerialize ()
80 MethodInfo mi = typeof (GlobalizationSection).GetMethod ("PreSerialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
81 GlobalizationSection s;
82 object[] parms = new object[1];
85 sw = new StringWriter ();
86 writer = new XmlTextWriter (sw);
88 s = new GlobalizationSection();
97 s.Culture = "illegal-culture";
100 catch (TargetInvocationException e) {
101 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A2");
104 Assert.IsFalse (failed, "A2");
110 s.UICulture = "illegal-culture";
111 mi.Invoke (s, parms);
113 catch (TargetInvocationException e) {
114 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A3");
117 Assert.IsFalse (failed, "A3");
122 s.ResourceProviderFactoryType = "invalid-type";
123 mi.Invoke (s, parms);
125 /* 5 (null writer) */
127 mi.Invoke (s, parms);
131 public void PostDeserialize ()
133 MethodInfo mi = typeof (GlobalizationSection).GetMethod ("PostDeserialize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
134 GlobalizationSection s;
135 object[] parms = new object[0];
138 s = new GlobalizationSection();
141 mi.Invoke (s, parms);
146 s.Culture = "illegal-culture";
147 mi.Invoke (s, parms);
149 catch (TargetInvocationException e) {
150 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A2");
153 Assert.IsFalse (failed, "A2");
158 s.UICulture = "illegal-culture";
159 mi.Invoke (s, parms);
161 catch (TargetInvocationException e) {
162 Assert.AreEqual (typeof (ConfigurationErrorsException), e.InnerException.GetType (), "A3");
165 Assert.IsFalse (failed, "A3");
169 s.ResourceProviderFactoryType = "invalid-type";
170 mi.Invoke (s, parms);
174 public void GlobalizationEncodingName ()
176 string pageHtml = new WebTest ("GlobalizationEncodingName.aspx").Run ();
177 string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
178 string originalHtml = "GOOD";
179 Assert.AreEqual (originalHtml, renderedHtml, "#A1");