ObjectStateFormatterTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // Tests for System.Web.UI.ObjectStateFormatter
  3. //
  4. // Authors:
  5. // Marek Habersack <[email protected]>
  6. //
  7. // Copyright (C) 2009 Novell, Inc (http://novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Web;
  33. using System.Web.UI;
  34. using MonoTests.SystemWeb.Framework;
  35. using MonoTests.stand_alone.WebHarness;
  36. using NUnit.Framework;
  37. namespace MonoTests.System.Web.UI
  38. {
  39. [TestFixture]
  40. public class ObjectStateFormatterTest
  41. {
  42. [TestFixtureSetUp]
  43. public void SetUp ()
  44. {
  45. Type t = GetType ();
  46. WebTest.CopyResource (t, "StateFormatter_CorrectConverter.aspx", "StateFormatter_CorrectConverter.aspx");
  47. WebTest.CopyResource (t, "StateFormatter_CollectionConverter.aspx", "StateFormatter_CollectionConverter.aspx");
  48. WebTest.CopyResource (t, "StateFormatter_CollectionConverter.aspx.cs", "StateFormatter_CollectionConverter.aspx.cs");
  49. }
  50. public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
  51. {
  52. if (e.Name != "System.Web_test")
  53. return null;
  54. return Assembly.GetExecutingAssembly ();
  55. }
  56. [Test (Description="Bug #545979")]
  57. public void StateFormatter_CorrectConverter ()
  58. {
  59. // We test only if it doesn't throw exception on postback
  60. try {
  61. WebTest.Host.AppDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
  62. WebTest t = new WebTest ("StateFormatter_CorrectConverter.aspx");
  63. t.Run ();
  64. var fr = new FormRequest (t.Response, "Form1");
  65. fr.Controls.Add ("Button1");
  66. fr.Controls ["Button1"].Value = "Change";
  67. t.Request = fr;
  68. t.Run ();
  69. fr = new FormRequest (t.Response, "Form1");
  70. fr.Controls.Add ("Button2");
  71. fr.Controls ["Button2"].Value = "Refresh";
  72. } finally {
  73. WebTest.Host.AppDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
  74. }
  75. }
  76. [Test (Description="Bug #565547")]
  77. public void StateFormatter_CollectionFormatter ()
  78. {
  79. WebTest t = new WebTest ("StateFormatter_CollectionConverter.aspx");
  80. t.Run ();
  81. var fr = new FormRequest (t.Response, "form1");
  82. fr.Controls.Add ("btnSearch");
  83. fr.Controls.Add ("ddlDate");
  84. fr.Controls.Add ("txtSearchValue");
  85. fr.Controls ["btnSearch"].Value = "Search";
  86. fr.Controls ["ddlDate"].Value = "2009";
  87. t.Request = fr;
  88. string pageHtml = t.Run ();
  89. string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
  90. string originalHtml = @"<div>
  91. <table id=""gvECCN"" cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"">
  92. <tr>
  93. <th align=""left"" scope=""col"">&nbsp;</th><th align=""left"" scope=""col"">Schedule B</th><th align=""left"" scope=""col"">Count</th><th align=""left"" scope=""col"">Total</th><th align=""left"" scope=""col"">Percent</th>
  94. </tr><tr>
  95. <td style=""height:18px;width:30px;"">1</td><td style=""width:140px;"">test</td><td style=""width:90px;"">1</td><td style=""width:100px;"">100</td><td style=""width:90px;"">250.00 %</td>
  96. </tr>
  97. </table>
  98. </div>";
  99. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
  100. }
  101. #if false
  102. [Test]
  103. public void SerializeOverloads ()
  104. {
  105. ObjectStateFormatter osf = new ObjectStateFormatter ();
  106. string s1 = osf.Serialize (String.Empty);
  107. string s2;
  108. using (MemoryStream ms = new MemoryStream ()) {
  109. osf.Serialize (ms, String.Empty);
  110. s2 = Convert.ToBase64String (ms.ToArray ());
  111. }
  112. Assert.AreEqual (s1, s2, "identical");
  113. }
  114. #endif
  115. }
  116. }
  117. #endif