GlobalizationSectionTest.cs 4.4 KB

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