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 ("NotDotNet")] // Must be removed after adding AppRelativeVirtualPath property
167 [Category ("NunitWeb")]
168 public void TemplateControl_ParseControl ()
170 WebTest t = new WebTest (PageInvoker.CreateOnLoad (ParseControlTest));
171 string html = t.Run ();
172 if (html.IndexOf ("<span id=\"lb\">test</span>") < 0)
173 Assert.Fail ("ParseControl failed");
176 public static void ParseControlTest (Page p)
178 PokerTemplateControl t = new PokerTemplateControl ();
179 //Does not have definition , must be uncommented
180 //t.AppRelativeVirtualPath = "~\\";
181 Control c = t.ParseControl ("<asp:label id='lb' runat='server' text='test' />");
186 public void TemplateControl_ReadStringResource ()
189 // The ReadStringResource method is not intended for use from within your code
193 [Category ("NotWorking")]
194 [Category ("NunitWeb")]
195 public void TemplateControl_TestDeviceFilter ()
197 //Have no definition to TestDeviceFilter
198 WebTest t = new WebTest (PageInvoker.CreateOnLoad (TestDeviceFilter));
199 string html = t.Run ();
203 public static void TestDeviceFilter (Page p)
205 //Have no definition to TestDeviceFilter
206 // bool res = p.TestDeviceFilter("test");
207 // Assert.AreEqual (false, res, "TestDeviceFilter#1");
208 //Have no definition to TestDeviceFilter
209 // res = p.TestDeviceFilter ("IE");
210 // Assert.AreEqual (true, res, "TestDeviceFilter#2");
214 public void TemplateControl_Construct ()
216 eventchecker = false;
217 PokerTemplateControl t = new PokerTemplateControl ();
218 Assert.AreEqual (true, eventchecker, "Construct Failed");
222 [Category ("NunitWeb")]
223 [Category ("NotWorking")]
224 public void TemplateControl_Eval ()
226 // In this test aspx page used as template control
228 WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.EvalTest.aspx", "EvalTest.aspx");
230 WebTest.CopyResource (GetType (), "EvalTest.aspx", "EvalTest.aspx");
232 WebTest t = new WebTest ("EvalTest.aspx");
233 PageDelegates pd = new PageDelegates ();
234 pd.PreRender = _templatePreRender;
235 t.Invoker = new PageInvoker (pd);
237 string html = t.Run ();
238 if (html.IndexOf ("My databind test") < 0)
239 Assert.Fail ("Eval not done fail");
242 public static void _templatePreRender (Page p)
244 Repeater rep = p.FindControl ("Repeater1") as Repeater;
246 Assert.Fail ("Aspx page not creation failed");
247 Assert.AreEqual (1, rep.Items.Count, "Data items bounding failed");
251 public void TemplateControl_XPath_XPathSelect ()
253 //These two method are tested on XmlDataSourceTest.cs
257 public void TemplateControl_CreateResourceBasedLiteralControl ()
259 // The CreateResourceBasedLiteralControl method is not intended
260 // for use from within your code.
264 public void TemplateControl_SetStringResourcePointer ()
266 // The SetStringResourcePointer method is not intended
267 // for use from within your code.
271 public void TemplateControl_WriteUTF8ResourceString ()
273 //This method supports the .NET Framework infrastructure and is not intended to be used directly from your code.
274 //Writes a resource string to an HtmlTextWriter control.
275 //The WriteUTF8ResourceString method is used by generated classes and is not intended for use from within your code.
279 bool abortTransaction;
280 bool commitTransaction;
284 public void TemplateControl_AbortTransaction ()
286 PokerTemplateControl t = new PokerTemplateControl ();
287 t.AbortTransaction += new EventHandler (t_AbortTransaction);
288 Assert.AreEqual (false, abortTransaction, "Before transaction aborted");
289 t.DoOnAbortTransaction (new EventArgs ());
290 Assert.AreEqual (true, abortTransaction, "After transaction aborted");
293 void t_AbortTransaction (object sender, EventArgs e)
295 abortTransaction = true;
299 public void TemplateControl_CommitTransaction ()
301 PokerTemplateControl t = new PokerTemplateControl ();
302 t.CommitTransaction += new EventHandler (t_CommitTransaction);
303 Assert.AreEqual (false, commitTransaction, "Before transaction Commited");
304 t.DoOnCommitTransaction (new EventArgs ());
305 Assert.AreEqual (true, commitTransaction, "After transaction Commited");
308 void t_CommitTransaction (object sender, EventArgs e)
310 commitTransaction = true;
314 public void TemplateControl_Error ()
316 PokerTemplateControl t = new PokerTemplateControl ();
317 t.Error += new EventHandler (t_Error);
318 Assert.AreEqual (false, error, "Before error");
319 t.DoOnError (new EventArgs ());
320 Assert.AreEqual (true, error, "After error");
323 void t_Error (object sender, EventArgs e)
330 [Category ("NotWorking")]
331 [ExpectedException (typeof (InvalidOperationException))]
332 public void TemplateControl_EvalException ()
334 PokerTemplateControl t = new PokerTemplateControl ();
339 [ExpectedException (typeof (ArgumentNullException))]
340 public void TemplateControl_LoadControlException()
342 PokerTemplateControl t = new PokerTemplateControl ();
343 t.LoadControl (null);
348 [Category ("NotWorking")]
349 //[ExpectedException(typeof(ArgumentNullException))]
350 public void TemplateControl_AppRelativeVirtualPathException1 ()
352 PokerTemplateControl t = new PokerTemplateControl ();
353 //Does not have definition
354 //t.AppRelativeVirtualPath = null;
358 [Category ("NotWorking")]
359 //[ExpectedException (typeof (ArgumentException))]
360 public void TemplateControl_AppRelativeVirtualPathException2 ()
362 PokerTemplateControl t = new PokerTemplateControl ();
363 //Does not have definition
364 //t.AppRelativeVirtualPath = "fake";
367 [TestFixtureTearDown]
368 public void TearDown ()