2 // Tests for System.Web.UI.WebControls.ThemeTest.cs
5 // Yoni Klein (yonik@mainsoft.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.
29 // Additional resources :
30 // PageWithStyleSheet.aspx; PageWithStyleSheet.aspx.cs;RunTimeSetTheme.aspx;
31 // RunTimeSetTheme.aspx.cs; PageWithTheme.aspx; PageWithTheme.aspx.cs; Theme1.skin
38 using System.Configuration;
41 using System.Web.UI.WebControls;
42 using System.Threading;
43 using MyWebControl = System.Web.UI.WebControls;
44 using System.Reflection;
45 using NUnit.Framework;
46 using MonoTests.SystemWeb.Framework;
48 namespace MonoTests.System.Web.UI.WebControls
52 public class ThemeTest
58 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.Theme1.skin", "App_Themes/Theme1/Theme1.skin");
\r
59 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.WizardTest.skin", "App_Themes/Theme1/WizardTest.skin");
\r
60 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.PageWithStyleSheet.aspx", "PageWithStyleSheet.aspx");
\r
61 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.PageWithTheme.aspx", "PageWithTheme.aspx");
\r
62 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.RunTimeSetTheme.aspx", "RunTimeSetTheme.aspx");
\r
63 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.UrlProperty.aspx", "UrlProperty.aspx");
\r
64 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.UrlProperty.ascx", "UrlProperty.ascx");
\r
65 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.UrlProperty.ascx.cs", "UrlProperty.ascx.cs");
68 WebTest.CopyResource (GetType (), "Theme1.skin", "App_Themes/Theme1/Theme1.skin");
69 WebTest.CopyResource (GetType (), "WizardTest.skin", "App_Themes/Theme1/WizardTest.skin");
70 WebTest.CopyResource (GetType (), "PageWithStyleSheet.aspx", "PageWithStyleSheet.aspx");
71 WebTest.CopyResource (GetType (), "PageWithTheme.aspx", "PageWithTheme.aspx");
72 WebTest.CopyResource (GetType (), "RunTimeSetTheme.aspx", "RunTimeSetTheme.aspx");
73 WebTest.CopyResource (GetType (), "UrlProperty.aspx", "UrlProperty.aspx");
74 WebTest.CopyResource (GetType (), "UrlProperty.ascx", "UrlProperty.ascx");
75 WebTest.CopyResource (GetType (), "UrlProperty.ascx.cs", "UrlProperty.ascx.cs");
82 public void SetupTestCase ()
87 //Run on page with theme
90 [Category ("NunitWeb")]
91 public void Theme_TestLabelTheme ()
93 WebTest t = new WebTest ("PageWithTheme.aspx");
94 t.Invoker = PageInvoker.CreateOnLoad (RenderLabelTest);
98 public static void RenderLabelTest (Page p)
100 Assert.AreEqual (Color.Black,((MyWebControl.Label) p.FindControl ("Label")).BackColor, "Default Theme#1");
101 Assert.AreEqual (Color.Red, ((MyWebControl.Label) p.FindControl ("LabelRed")).BackColor, "Red Skin Theme#2");
102 Assert.AreEqual (Color.Yellow, ((MyWebControl.Label) p.FindControl ("LabelYellow")).BackColor, "Yellow Skin Theme#3");
103 Assert.AreEqual (Color.Black, ((MyWebControl.Label) p.FindControl ("LabelOverride")).BackColor, "Override Skin Theme#4");
107 [Category ("NunitWeb")]
108 public void Theme_TestImageTheme ()
110 WebTest t = new WebTest ("PageWithTheme.aspx");
111 t.Invoker = PageInvoker.CreateOnLoad (RenderImageTest);
115 public static void RenderImageTest (Page p)
117 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("Image")).ImageUrl.IndexOf ("myimageurl") >= 0, "Default Theme#1");
118 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageRed")).ImageUrl.IndexOf ("myredimageurl") >= 0, "RedImage Theme#2");
119 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageYellow")).ImageUrl.IndexOf ("myyellowimageurl") >= 0, "YellowImage Theme#3");
120 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageOverride")).ImageUrl.IndexOf ("myimageurl") >= 0, "OverrideImage Theme#3");
123 // Run on page with StyleSheet
126 [Category ("NunitWeb")]
127 public void Theme_TestLabelStyleSheet ()
129 WebTest t = new WebTest ("PageWithStyleSheet.aspx");
130 t.Invoker = PageInvoker.CreateOnLoad (StyleSheetRenderLabelTest);
134 public static void StyleSheetRenderLabelTest (Page p)
136 Assert.AreEqual (Color.Black, ((MyWebControl.Label) p.FindControl ("Label")).BackColor, "Default Theme#1");
137 Assert.AreEqual (Color.Red, ((MyWebControl.Label) p.FindControl ("LabelRed")).BackColor, "Red Skin Theme#2");
138 Assert.AreEqual (Color.Yellow, ((MyWebControl.Label) p.FindControl ("LabelYellow")).BackColor, "Yellow Skin Theme#3");
139 Assert.AreEqual (Color.White, ((MyWebControl.Label) p.FindControl ("LabelOverride")).BackColor, "Override Skin Theme#4");
143 [Category ("NunitWeb")]
144 public void Theme_TestImageStyleSheet ()
146 WebTest t = new WebTest ("PageWithStyleSheet.aspx");
147 t.Invoker = PageInvoker.CreateOnLoad (StyleSheetRenderImageTest);
151 public static void StyleSheetRenderImageTest (Page p)
153 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("Image")).ImageUrl.IndexOf ("myimageurl") >= 0, "Default Theme#1");
154 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageRed")).ImageUrl.IndexOf ("myredimageurl") >= 0, "RedImage Theme#2");
155 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageYellow")).ImageUrl.IndexOf ("myyellowimageurl") >= 0, "YellowImage Theme#3");
156 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageOverride")).ImageUrl.IndexOf ("overridedurl") >= 0, "OverrideImage Theme#3");
160 [Category ("NunitWeb")]
161 public void Theme_TestRuntimeSetTheme ()
163 PageDelegates p = new PageDelegates ();
\r
164 p.PreInit = RuntimeSetThemePreInit;
\r
165 p.Load = RuntimeSetThemeLoad;
\r
166 WebTest t = new WebTest ("RunTimeSetTheme.aspx");
167 t.Invoker = new PageInvoker (p);
171 public static void RuntimeSetThemePreInit (Page p)
\r
173 p.Theme = "Theme1";
\r
176 public static void RuntimeSetThemeLoad (Page p)
178 Assert.AreEqual (Color.Black, ((MyWebControl.Label) p.FindControl ("Label")).BackColor, "Default Theme#1");
179 Assert.AreEqual (Color.Red, ((MyWebControl.Label) p.FindControl ("LabelRed")).BackColor, "Red Skin Theme#2");
180 Assert.AreEqual (Color.Yellow, ((MyWebControl.Label) p.FindControl ("LabelYellow")).BackColor, "Yellow Skin Theme#3");
181 Assert.AreEqual (Color.Black, ((MyWebControl.Label) p.FindControl ("LabelOverride")).BackColor, "Override Skin Theme#4");
182 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("Image")).ImageUrl.IndexOf ("myimageurl") >= 0, "Default Theme#1");
183 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageRed")).ImageUrl.IndexOf ("myredimageurl") >= 0, "RedImage Theme#2");
184 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageYellow")).ImageUrl.IndexOf ("myyellowimageurl") >= 0, "YellowImage Theme#3");
185 Assert.IsTrue (((MyWebControl.Image) p.FindControl ("ImageOverride")).ImageUrl.IndexOf ("myimageurl") >= 0, "OverrideImage Theme#3");
189 [Category ("NunitWeb")]
190 public void Theme_TestThemeNotExistExeption()
192 WebTest t = new WebTest (PageInvoker.CreateOnPreInit (_ThemeNotExistException));
193 string page = t.Run ();
194 Assert.AreEqual (404, t.Response.StatusCode, "404 status was expected, actual result: "+page);
197 public static void _ThemeNotExistException (Page p)
199 p.Theme = "NotExistTheme";
203 [Category ("NunitWeb")]
204 public void Theme_SetThemeException ()
206 string page=new WebTest (PageInvoker.CreateOnPreInit (SetThemeExeption)).Run ();
207 Assert.IsTrue (page.IndexOf("System.Web.HttpException") >= 0, "System.Web.HttpException was expected, actual result: "+page);
210 //// Delegate running on Page Load , only before PreInit possible set Theme on running time !
212 //[Category ("NunitWeb")]
213 ////Use Assert.Fail to print the actual result
214 ////[ExpectedException (typeof (InvalidOperationException))]
215 //[Category ("NotWorking")]
216 //public void Theme_SetThemeException ()
219 // string res=Helper.Instance.RunInPagePreInit (SetThemeExeption);
220 // Assert.Fail ("InvalidOperationException was expected. Result: "+res);
222 // catch (InvalidOperationException e) {
223 // //swallow the expected exception
227 public static void SetThemeExeption (Page p)
229 p.Theme = "InvalidTheme1";
233 [Category ("NunitWeb")]
\r
234 public void Theme_EnableTheming ()
\r
237 PageDelegates pd = new PageDelegates ();
\r
238 pd.PreInit = new PageDelegate (SetTheme1);
\r
239 pd.Load = new PageDelegate (Theme1Load);
\r
240 PageInvoker pi = new PageInvoker (pd);
\r
242 string page = new WebTest (pi).Run ();
\r
244 Assert.IsTrue (page.IndexOf ("testing") < 0, "Theme_EnableTheming");
\r
246 public static void Theme1Load (Page p)
\r
248 Table t = new Table ();
\r
249 TableRow tr = new TableRow ();
\r
250 TableCell cell = new TableCell ();
\r
252 cell.Controls.Add (new Button ());
\r
253 tr.Cells.Add (cell);
\r
256 t.EnableTheming = false;
\r
257 p.Form.Controls.Add (t);
\r
259 public static void SetTheme1 (Page p)
\r
261 p.Theme = "Theme1";
\r
265 [Category ("NunitWeb")]
\r
266 public void Theme_EnableThemingChild ()
\r
269 PageDelegates pd = new PageDelegates ();
\r
270 pd.PreInit = new PageDelegate (SetTheme1);
\r
271 pd.Load = new PageDelegate (Theme1ChildLoad);
\r
272 PageInvoker pi = new PageInvoker (pd);
\r
274 string page = new WebTest (pi).Run ();
\r
276 Assert.IsTrue (page.IndexOf ("testing") > 0, "Theme_EnableThemingChild");
\r
278 public static void Theme1ChildLoad (Page p)
\r
280 Table t = new Table ();
\r
281 TableRow tr = new TableRow ();
\r
282 TableCell cell = new TableCell ();
\r
284 cell.Controls.Add (new Button ());
\r
285 tr.Cells.Add (cell);
\r
288 t.EnableTheming = false;
\r
289 cell.EnableTheming = true;
\r
290 p.Form.Controls.Add (t);
\r
293 [TestFixtureTearDown]
294 public void TearDown ()
302 [Category("NunitWeb")]
304 [Category ("NotWorking")]
306 public void UrlPropertyTest ()
308 string res = new WebTest ("UrlProperty.aspx").Run ();
310 Assert.IsTrue (res.IndexOf ("Property1 = testProp1") != -1,
311 "Property1 should be assigned as is, actual result: "+res);
312 Assert.IsTrue (res.IndexOf ("UrlProperty2 = ~/App_Themes/Theme1/testProp2") != -1,
313 "UrlProperty2 should be assigned including theme subfolder, actual result: "+res);