Class1.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using System.Text;
  3. using NUnit.Framework;
  4. using MonoTests.SystemWeb.Framework;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Drawing;
  9. using System.Runtime.Serialization;
  10. using System.IO;
  11. using System.Reflection;
  12. using System.Diagnostics;
  13. namespace Test1
  14. {
  15. [TestFixture]
  16. public class Class1
  17. {
  18. public void TearDownFixture ()
  19. {
  20. WebTest.Unload ();
  21. }
  22. #if NET_2_0
  23. [Test]
  24. public void RenderSiteMapPath ()
  25. {
  26. PageInvoker pi = PageInvoker.CreateOnLoad (_RenderSiteMapPath);
  27. string res = new WebTest (pi).Run ();
  28. Console.WriteLine (res);
  29. Assert.IsFalse (string.IsNullOrEmpty (res));
  30. }
  31. public static void _RenderSiteMapPath (Page p)
  32. {
  33. SiteMapPath smp = new SiteMapPath ();
  34. p.Controls.Add (smp);
  35. }
  36. [Test]
  37. public void RenderSiteMapPathProp ()
  38. {
  39. PageInvoker pi = PageInvoker.CreateOnLoad (_RenderSiteMapPathProp);
  40. string res = new WebTest (pi).Run ();
  41. Console.WriteLine (res);
  42. Assert.IsFalse (string.IsNullOrEmpty (res));
  43. }
  44. public static void _RenderSiteMapPathProp (Page p)
  45. {
  46. SiteMapPath smp = new SiteMapPath ();
  47. smp.BackColor = Color.Red;
  48. p.Controls.Add (smp);
  49. }
  50. [Test]
  51. public void TestMasterPage ()
  52. {
  53. PageInvoker pi = PageInvoker.CreateOnLoad (_TestMasterPage);
  54. WebTest t = new WebTest (pi);
  55. t.Request.Url = StandardUrl.PAGE_WITH_MASTER;
  56. string res = t.Run ();
  57. Console.WriteLine (res);
  58. Assert.IsFalse (string.IsNullOrEmpty (res));
  59. }
  60. public static void _TestMasterPage (Page p)
  61. {
  62. MasterPage mp = p.Master;
  63. Assert.IsNotNull (mp);
  64. }
  65. #endif
  66. [Test]
  67. public void TestStyle ()
  68. {
  69. string res = new WebTest (PageInvoker.CreateOnLoad (
  70. new PageDelegate(_TestStyle))).Run ();
  71. Assert.IsNotNull (res);
  72. Assert.IsTrue (res != string.Empty);
  73. }
  74. public static void _TestStyle (Page p)
  75. {
  76. Button b = new Button ();
  77. b.BackColor = Color.Red;
  78. b.ID = "Yoni";
  79. p.Controls.Add (b);
  80. }
  81. [Test]
  82. public void TestDefaultRender ()
  83. {
  84. string str = new WebTest (PageInvoker.CreateOnLoad (
  85. new PageDelegate(_TestDefaultRender))).Run ();
  86. Assert.IsTrue (str!=null && str!=string.Empty);
  87. }
  88. public static void _TestDefaultRender (Page p)
  89. {
  90. LiteralControl lcb = new LiteralControl ("aaa");
  91. LiteralControl lce = new LiteralControl ("bbb");
  92. p.Controls.Add (lcb);
  93. #if NET_2_0
  94. Menu menu = new Menu ();
  95. p.Controls.Add (menu);
  96. #endif
  97. p.Controls.Add (lce);
  98. }
  99. #if NET_2_0
  100. [Test]
  101. public void TestSkin ()
  102. {
  103. Assembly SampleAssembly;
  104. // Instantiate a target object.
  105. Int32 Integer1 = new Int32 ();
  106. Type Type1;
  107. // Set the Type instance to the target class type.
  108. Type1 = Integer1.GetType ();
  109. // Instantiate an Assembly class to the assembly housing the Integer type.
  110. SampleAssembly = Assembly.GetAssembly (Integer1.GetType ());
  111. // Display the physical location of the assembly containing the manifest.
  112. Console.WriteLine ("Location=" + SampleAssembly.Location);
  113. WebTest.CopyResource (GetType (), "Test1.Resources.Default.skin", "App_Themes/Black/Default.skin");
  114. WebTest.CopyResource (GetType (), "Test1.Resources.MyPageWithTheme.aspx", "MyPageWithTheme.aspx");
  115. string res = new WebTest ("MyPageWithTheme.aspx").Run ();
  116. Debug.WriteLine (res);
  117. }
  118. #endif
  119. [Test]
  120. public void UnloadTest ()
  121. {
  122. new WebTest (new PageInvoker (new PageDelegates ())).Run ();
  123. WebTest.Unload ();
  124. new WebTest (new PageInvoker (new PageDelegates ())).Run ();
  125. }
  126. [Test]
  127. public void PostBack ()
  128. {
  129. WebTest.CopyResource (GetType (), "Test1.Resources.Postback.aspx", "Postback.aspx");
  130. WebTest t = new WebTest ("Postback.aspx");
  131. string res1 = t.Run ();
  132. FormRequest fr = new FormRequest (t.Response, "form1");
  133. fr.Controls.Add ("txt1");
  134. fr.Controls ["txt1"].Value = "value";
  135. t.Request = fr;
  136. string res2 = t.Run ();
  137. WebTest t1 = new WebTest (fr);
  138. }
  139. [Test]
  140. public void PostRequest ()
  141. {
  142. WebTest t = new WebTest (PageInvoker.CreateOnLoad (
  143. new PageDelegate (CheckPostRequest)));
  144. PostableRequest pr = new PostableRequest ();
  145. pr.IsPost = true;
  146. t.Request = pr;
  147. t.Run ();
  148. }
  149. static public void CheckPostRequest (Page p)
  150. {
  151. Assert.AreEqual ("POST", HttpContext.Current.Request.RequestType);
  152. }
  153. }
  154. }