GlobalizationSectionTest.cs 4.9 KB

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