2 // Tests for System.Web.UI.WebControls.TemplateControlTest.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.
33 using System.Collections.Generic;
37 using System.Web.UI.WebControls;
40 using MyWebControl = System.Web.UI.WebControls;
41 using System.Collections;
42 using MonoTests.SystemWeb.Framework;
43 using NUnit.Framework;
44 using MonoTests.stand_alone.WebHarness;
45 using System.Threading;
48 namespace MonoTests.System.Web.UI.WebControls
51 class PokerTemplateControl:TemplateControl
53 public PokerTemplateControl ()
58 public bool DoSupportAutoEvents
60 get { return base.SupportAutoEvents; }
63 protected override void Construct ()
65 TemplateControlTest.eventchecker = true;
70 public void DoOnAbortTransaction (EventArgs e)
72 base.OnAbortTransaction (e);
75 public void DoOnCommitTransaction (EventArgs e)
77 base.OnCommitTransaction (e);
80 public void DoOnError (EventArgs e)
85 public object DoEval (string str)
87 return base.Eval (str);
93 public class TemplateControlTest
95 public static bool eventchecker;
96 public string message = "My message text";
99 public void GridViewInit ()
102 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.TemplateUserControl.ascx", "TemplateUserControl.ascx");
104 WebTest.CopyResource (GetType (), "TemplateUserControl.ascx", "TemplateUserControl.ascx");
109 public void SetupTestCase ()
115 public void TemplateControl_DefaultProperty ()
117 PokerTemplateControl t = new PokerTemplateControl ();
118 Assert.AreEqual (true, t.EnableTheming, "EnableTheming");
119 Assert.AreEqual (true, t.DoSupportAutoEvents, "SupportAutoEvents");
123 [Category ("NotWorking")]
124 public void TemplateControl_DefaultPropertyNotWorking ()
126 PokerTemplateControl t = new PokerTemplateControl ();
127 //Does not have definition
128 //Assert.AreEqual (null, t.AppRelativeVirtualPath, "AppRelativeVirtualPath");
132 [Category ("NunitWeb")]
133 public void TemplateControl_LoadControl ()
135 WebTest t = new WebTest (PageInvoker.CreateOnLoad (LoadControlTest));
136 string html = t.Run ();
137 if (html.IndexOf ("TemplateUserControl") < 0)
138 Assert.Fail ("LoadControl failed");
141 public static void LoadControlTest (Page p)
143 PokerTemplateControl t = new PokerTemplateControl ();
144 p.Form.Controls.Add (t.LoadControl ("TemplateUserControl.ascx"));
148 [Category ("NunitWeb")]
149 public void TemplateControl_LoadTemplate ()
151 WebTest t = new WebTest (PageInvoker.CreateOnLoad (LoadTemplateTest));
152 string html = t.Run ();
153 if (html.IndexOf ("TemplateUserControl") < 0)
154 Assert.Fail ("LoadTemplate failed");
157 public static void LoadTemplateTest (Page p)
159 PokerTemplateControl t = new PokerTemplateControl ();
160 ITemplate tmp = t.LoadTemplate ("TemplateUserControl.ascx");
161 tmp.InstantiateIn (p.Form);
165 [Category ("NotWorking")]
166 [Category ("NunitWeb")]
167 public void TemplateControl_ParseControl ()
169 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ParseControlTest));
170 string html = t.Run ();
171 if (html.IndexOf ("<span id=\"lb\">test</span>") < 0)
172 Assert.Fail ("ParseControl failed");
175 public static void ParseControlTest (Page p)
177 PokerTemplateControl t = new PokerTemplateControl ();
178 //Does not have definition , must be uncommented
179 //t.AppRelativeVirtualPath = "~\\";
180 Control c = t.ParseControl ("<asp:label id='lb' runat='server' text='test' />");
185 public void TemplateControl_ReadStringResource ()
188 // The ReadStringResource method is not intended for use from within your code
192 [Category ("NotWorking")]
193 [Category ("NunitWeb")]
194 public void TemplateControl_TestDeviceFilter ()
196 //Have no definition to TestDeviceFilter
197 WebTest t = new WebTest (PageInvoker.CreateOnLoad (TestDeviceFilter));
198 string html = t.Run ();
202 public static void TestDeviceFilter (Page p)
204 //Have no definition to TestDeviceFilter
205 // bool res = p.TestDeviceFilter("test");
206 // Assert.AreEqual (false, res, "TestDeviceFilter#1");
207 //Have no definition to TestDeviceFilter
208 // res = p.TestDeviceFilter ("IE");
209 // Assert.AreEqual (true, res, "TestDeviceFilter#2");
213 public void TemplateControl_Construct ()
215 eventchecker = false;
216 PokerTemplateControl t = new PokerTemplateControl ();
217 Assert.AreEqual (true, eventchecker, "Construct Failed");
221 [Category ("NunitWeb")]
222 [Category ("NotWorking")]
223 public void TemplateControl_Eval ()
225 // In this test aspx page used as template control
227 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.EvalTest.aspx", "EvalTest.aspx");
229 WebTest.CopyResource (GetType (), "EvalTest.aspx", "EvalTest.aspx");
231 WebTest t = new WebTest ("EvalTest.aspx");
232 PageDelegates pd = new PageDelegates ();
233 pd.PreRender = _templatePreRender;
234 t.Invoker = new PageInvoker (pd);
236 string html = t.Run ();
237 if (html.IndexOf ("My databind test") < 0)
238 Assert.Fail ("Eval not done fail");
241 public static void _templatePreRender (Page p)
243 Repeater rep = p.FindControl ("Repeater1") as Repeater;
245 Assert.Fail ("Aspx page not creation failed");
246 Assert.AreEqual (1, rep.Items.Count, "Data items bounding failed");
250 public void TemplateControl_XPath_XPathSelect ()
252 //These two method are tested on XmlDataSourceTest.cs
256 public void TemplateControl_CreateResourceBasedLiteralControl ()
258 // The CreateResourceBasedLiteralControl method is not intended
259 // for use from within your code.
263 public void TemplateControl_SetStringResourcePointer ()
265 // The SetStringResourcePointer method is not intended
266 // for use from within your code.
270 public void TemplateControl_WriteUTF8ResourceString ()
272 //This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.
273 //Writes a resource string to an HtmlTextWriter control.
274 //The WriteUTF8ResourceString method is used by generated classes and is not intended for use from within your code.
278 bool abortTransaction;
279 bool commitTransaction;
283 public void TemplateControl_AbortTransaction ()
285 PokerTemplateControl t = new PokerTemplateControl ();
286 t.AbortTransaction += new EventHandler (t_AbortTransaction);
287 Assert.AreEqual (false, abortTransaction, "Before transaction aborted");
288 t.DoOnAbortTransaction (new EventArgs ());
289 Assert.AreEqual (true, abortTransaction, "After transaction aborted");
292 void t_AbortTransaction (object sender, EventArgs e)
294 abortTransaction = true;
298 public void TemplateControl_CommitTransaction ()
300 PokerTemplateControl t = new PokerTemplateControl ();
301 t.CommitTransaction += new EventHandler (t_CommitTransaction);
302 Assert.AreEqual (false, commitTransaction, "Before transaction Commited");
303 t.DoOnCommitTransaction (new EventArgs ());
304 Assert.AreEqual (true, commitTransaction, "After transaction Commited");
307 void t_CommitTransaction (object sender, EventArgs e)
309 commitTransaction = true;
313 public void TemplateControl_Error ()
315 PokerTemplateControl t = new PokerTemplateControl ();
316 t.Error += new EventHandler (t_Error);
317 Assert.AreEqual (false, error, "Before error");
318 t.DoOnError (new EventArgs ());
319 Assert.AreEqual (true, error, "After error");
322 void t_Error (object sender, EventArgs e)
329 [Category ("NotWorking")]
330 [ExpectedException (typeof (InvalidOperationException))]
331 public void TemplateControl_EvalException ()
333 PokerTemplateControl t = new PokerTemplateControl ();
338 [ExpectedException (typeof (ArgumentNullException))]
339 public void TemplateControl_LoadControlException()
341 PokerTemplateControl t = new PokerTemplateControl ();
342 t.LoadControl (null);
346 [Category ("NotWorking")]
347 [ExpectedException(typeof(ArgumentNullException))]
348 public void TemplateControl_AppRelativeVirtualPathException1 ()
350 PokerTemplateControl t = new PokerTemplateControl ();
351 //Does not have definition
352 //t.AppRelativeVirtualPath = null;
356 [Category ("NotWorking")]
357 [ExpectedException (typeof (ArgumentException))]
358 public void TemplateControl_AppRelativeVirtualPathException2 ()
360 PokerTemplateControl t = new PokerTemplateControl ();
361 //Does not have definition
362 //t.AppRelativeVirtualPath = "fake";
365 [TestFixtureTearDown]
366 public void TearDown ()