2 // Tests for System.Web.UI.WebControls.SiteMapPath.cs
\r
5 // Yoni Klein (yonik@mainsoft.com)
\r
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
\r
10 // Permission is hereby granted, free of charge, to any person obtaining
\r
11 // a copy of this software and associated documentation files (the
\r
12 // "Software"), to deal in the Software without restriction, including
\r
13 // without limitation the rights to use, copy, modify, merge, publish,
\r
14 // distribute, sublicense, and/or sell copies of the Software, and to
\r
15 // permit persons to whom the Software is furnished to do so, subject to
\r
16 // the following conditions:
\r
18 // The above copyright notice and this permission notice shall be
\r
19 // included in all copies or substantial portions of the Software.
\r
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 using NUnit.Framework;
\r
35 using System.Web.UI;
\r
36 using System.Web.UI.WebControls;
\r
37 using System.Threading;
\r
38 using System.Drawing;
\r
39 using System.Configuration;
\r
40 using MyWebControl = System.Web.UI.WebControls;
\r
41 using MonoTests.SystemWeb.Framework;
\r
42 using MonoTests.stand_alone.WebHarness;
\r
43 using System.Collections;
\r
45 namespace MonoTests.System.Web.UI.WebControls
\r
47 class PokerSiteMapPath : SiteMapPath
\r
49 public PokerSiteMapPath ()
\r
53 public StateBag StateBag
\r
55 get { return base.ViewState; }
\r
57 public object SaveState ()
\r
59 return SaveViewState ();
\r
61 public void LoadState (object o)
\r
65 public void InitilizeItems (SiteMapNodeItem I)
\r
69 public void DoCreateControlHierarchy ()
\r
71 CreateControlHierarchy ();
\r
73 public void DoOnDataBinding (EventArgs e)
\r
75 base.OnDataBinding (e);
\r
77 public void DoOnItemDataBound (SiteMapNodeItemEventArgs e)
\r
79 base.OnItemDataBound (e);
\r
81 public void DoOnItemCteated (SiteMapNodeItemEventArgs e)
\r
83 base.OnItemCreated (e);
\r
90 public class SiteMapPathTest
\r
93 public void Set_Up ()
\r
95 WebTest.CopyResource (GetType (), "Web.sitemap", "Web.sitemap");
\r
99 public void SetupTestCase ()
\r
101 Thread.Sleep (100);
\r
105 public void SiteMapPath_DefaultProperties ()
\r
107 PokerSiteMapPath p = new PokerSiteMapPath ();
\r
108 Assert.IsTrue (p.CurrentNodeStyle.IsEmpty, "CurrentNodeStyle");
\r
109 Assert.IsNull (p.CurrentNodeTemplate, "CurrentNodeTemplate");
\r
110 Assert.IsTrue (p.NodeStyle.IsEmpty, "NodeStyle");
\r
111 Assert.IsNull (p.NodeTemplate, "NodeTemplate");
\r
112 Assert.AreEqual (-1, p.ParentLevelsDisplayed, "ParentLevelsDisplayed");
\r
113 Assert.AreEqual (PathDirection.RootToCurrent, p.PathDirection, "PathDirection");
\r
114 Assert.IsNull (p.PathSeparatorTemplate, "PathSeparatorTemplate");
\r
115 Assert.IsFalse (p.RenderCurrentNodeAsLink, "RenderCurrentNodeAsLink");
\r
116 Assert.IsTrue (p.RootNodeStyle.IsEmpty, "RootNodeStyle");
\r
117 Assert.IsNull (p.RootNodeTemplate, "RootNodeTemplate");
\r
118 Assert.IsTrue (p.ShowToolTips, "ShowToolTips");
\r
119 Assert.AreEqual ("", p.SiteMapProvider, "SiteMapProvider");
\r
120 Assert.AreEqual ("Skip Navigation Links", p.SkipLinkText, "Skip Navigation Links");
\r
124 public void SiteMapPath_DefaultNotWorkingProperties()
\r
126 PokerSiteMapPath p = new PokerSiteMapPath ();
\r
127 Assert.AreEqual (" > ", p.PathSeparator, "PathSeparator");
\r
131 public void SiteMapPath_ChangeProperties ()
\r
133 PokerSiteMapPath p = new PokerSiteMapPath ();
\r
134 p.ShowToolTips = false;
\r
135 Assert.IsFalse (p.ShowToolTips, "ShowToolTips");
\r
137 Style currentNodeStyle = new Style ();
\r
138 p.CurrentNodeStyle.ForeColor = Color.AliceBlue;
\r
139 Assert.AreEqual (Color.AliceBlue, p.CurrentNodeStyle.ForeColor, "CurrentNodeStyle");
\r
141 Style NodeStyle = new Style ();
\r
142 p.NodeStyle.BackColor = Color.Aqua;
\r
143 Assert.AreEqual (Color.Aqua, p.NodeStyle.BackColor, "NodeStyle");
\r
145 p.PathDirection = PathDirection.CurrentToRoot;
\r
146 Assert.AreEqual (PathDirection.CurrentToRoot, p.PathDirection, "PathDirection");
\r
148 p.PathSeparator = " - ";
\r
149 Assert.AreEqual (" - ", p.PathSeparator, "PathSeparator");
\r
151 Style RootNodeStyle = new Style ();
\r
152 p.RootNodeStyle.BackColor = Color.Red;
\r
153 Assert.IsFalse (p.RootNodeStyle.IsEmpty, "RootNodeStyle#1");
\r
154 Assert.AreEqual (Color.Red, p.RootNodeStyle.BackColor, "RootNodeStyle#2");
\r
156 p.ParentLevelsDisplayed = 2;
\r
157 Assert.AreEqual (2, p.ParentLevelsDisplayed, "ParentLevelsDisplayed");
\r
159 p.RenderCurrentNodeAsLink = true;
\r
160 Assert.IsTrue (p.RenderCurrentNodeAsLink, "RenderCurrentNodeAsLink");
\r
162 p.SiteMapProvider = "test";
\r
163 Assert.AreEqual ("test", p.SiteMapProvider, "SiteMapProvider");
\r
165 p.SkipLinkText = "test";
\r
166 Assert.AreEqual ("test", p.SkipLinkText, "Skip Navigation Links");
\r
168 //programmatically create template
\r
169 MyWebControl.Image myImage = new MyWebControl.Image ();
\r
170 myImage.ImageUrl = "myimage.jpg";
\r
171 ImageTemplate rootNodeImageTemplate = new ImageTemplate ();
\r
172 rootNodeImageTemplate.MyImage = myImage;
\r
173 // end create template image
\r
174 p.RootNodeTemplate = rootNodeImageTemplate;
\r
175 Assert.IsNotNull (p.RootNodeTemplate, "RootNodeTemplate");
\r
176 Assert.AreEqual (rootNodeImageTemplate, p.RootNodeTemplate, "RootNodeTemplate");
\r
178 p.NodeTemplate = rootNodeImageTemplate;
\r
179 Assert.IsNotNull (p.NodeTemplate, "NodeTemplate");
\r
180 Assert.AreEqual (rootNodeImageTemplate, p.NodeTemplate, "NodeTemplate");
\r
182 p.CurrentNodeTemplate = rootNodeImageTemplate;
\r
183 Assert.IsNotNull (p.CurrentNodeTemplate, "RootNodeTemplate");
\r
184 Assert.AreEqual (rootNodeImageTemplate, p.CurrentNodeTemplate, "RootNodeTemplate");
\r
187 public void SiteMapPath_NullProperties ()
\r
189 PokerSiteMapPath p = new PokerSiteMapPath ();
\r
190 p.ShowToolTips = false;
\r
191 Assert.IsFalse (p.ShowToolTips, "ShowToolTips");
\r
192 Assert.AreEqual (1, p.StateBag.Count, "NullProperties#1");
\r
193 p.PathDirection = PathDirection.CurrentToRoot;
\r
194 Assert.AreEqual (PathDirection.CurrentToRoot, p.PathDirection, "PathDirection");
\r
195 Assert.AreEqual (2, p.StateBag.Count, "NullProperties#2");
\r
196 p.PathSeparator = " - ";
\r
197 Assert.AreEqual (3, p.StateBag.Count, "NullProperties#3");
\r
198 p.SiteMapProvider = "test";
\r
199 Assert.AreEqual (4, p.StateBag.Count, "NullProperties#4");
\r
200 p.SkipLinkText = "test";
\r
201 Assert.AreEqual (5, p.StateBag.Count, "NullProperties#5");
\r
202 p.SkipLinkText = null;
\r
208 [Category ("NunitWeb")]
\r
209 public void SiteMapPath_RenderProperty ()
\r
211 string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (DoTestPropertyRender)).Run ();
\r
212 string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
\r
213 string OriginControlHtml = @"<span style=""display:inline-block;color:Red;background-color:Red;border-color:Red;border-width:3px;border-style:Dashed;"">
\r
214 <a href=""#ctl01_SkipLink""><img alt=""Skip Navigation Links"" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd""
\r
215 style=""border-width:0px;"" /></a><span>node1</span><span>-</span><span><a title=""test"" href=""/NunitWeb/MyPageWithMaster.aspx"">root</a>
\r
216 </span><a id=""ctl01_SkipLink""></a></span>";
\r
217 HtmlDiff.AssertAreEqual(OriginControlHtml,RenderedControlHtml,"RenderProperty");
\r
220 [Category ("NunitWeb")]
\r
221 public void SiteMapPath_RenderStyles ()
\r
223 string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (DoTestStylesRender)).Run ();
\r
224 string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
\r
225 string OriginControlHtml = @"<span style=""background-color:Red;""><a href=""#ctl01_SkipLink"">
\r
226 <img alt=""Skip Navigation Links"" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd""
\r
227 style=""border-width:0px;"" /></a><span><a title=""test"" href=""/NunitWeb/MyPageWithMaster.aspx""
\r
228 style=""background-color:Beige;border-color:Purple;"">root</a></span>
\r
229 <span style=""background-color:RoyalBlue;""> > </span><span style=""background-color:Pink;border-color:Purple;"">node1</span>
\r
230 <a id=""ctl01_SkipLink""></a></span>";
\r
231 HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml,"RenderStyles");
\r
234 [Category ("NunitWeb")]
\r
235 public void SiteMapPath_DefaultRender()
\r
237 string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (DoTestDefaultRender)).Run ();
\r
238 string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
\r
239 string OriginControlHtml = @"<span><a href=""#ctl01_SkipLink"">
\r
240 <img alt=""Skip Navigation Links"" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd""
\r
241 style=""border-width:0px;"" /></a><span><a title=""test"" href=""/NunitWeb/MyPageWithMaster.aspx"">root</a>
\r
242 </span><span> > </span><span>node1</span><a id=""ctl01_SkipLink""></a></span>";
\r
243 HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml,"RenderDefault");
\r
247 /// All this methods are delegates for running tests in host assembly.
\r
250 public static void DoTestDefaultRender (Page p)
\r
252 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
\r
253 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
\r
254 SiteMapPath smp = new SiteMapPath ();
\r
255 p.Form.Controls.Add (lcb);
\r
256 p.Form.Controls.Add (smp);
\r
257 p.Form.Controls.Add (lce);
\r
259 public static void DoTestPropertyRender (Page p)
\r
261 SiteMapPath smp = new SiteMapPath ();
\r
262 smp.BackColor = Color.Red;
\r
263 smp.BorderColor = Color.Red;
\r
264 smp.BorderStyle = BorderStyle.Dashed;
\r
265 smp.BorderWidth = 3;
\r
266 smp.ForeColor = Color.Red;
\r
267 smp.PathDirection = PathDirection.CurrentToRoot;
\r
268 smp.PathSeparator = "-";
\r
270 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
\r
271 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
\r
272 p.Form.Controls.Add (lcb);
\r
273 p.Form.Controls.Add (smp);
\r
274 p.Form.Controls.Add (lce);
\r
276 public static void DoTestStylesRender (Page p)
\r
278 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
279 smp.ControlStyle.BackColor = Color.Red;
\r
280 smp.CurrentNodeStyle.BackColor = Color.Pink;
\r
281 smp.NodeStyle.BorderColor = Color.Purple;
\r
282 smp.PathSeparatorStyle.BackColor = Color.RoyalBlue;
\r
283 smp.RootNodeStyle.BackColor = Color.Beige;
\r
284 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
\r
285 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
\r
286 p.Form.Controls.Add (lcb);
\r
287 p.Form.Controls.Add (smp);
\r
288 p.Form.Controls.Add (lce);
\r
291 public void SiteMapPath_ViewState ()
\r
293 PokerSiteMapPath p = new PokerSiteMapPath ();
\r
294 p.ShowToolTips = false;
\r
295 Style currentNodeStyle = new Style ();
\r
296 p.CurrentNodeStyle.ForeColor = Color.AliceBlue;
\r
297 Style NodeStyle = new Style ();
\r
298 p.NodeStyle.BackColor = Color.Aqua;
\r
299 p.PathDirection = PathDirection.CurrentToRoot;
\r
300 Assert.AreEqual (PathDirection.CurrentToRoot, p.PathDirection, "PathDirection");
\r
301 p.PathSeparator = " - ";
\r
302 Style RootNodeStyle = new Style ();
\r
303 p.RootNodeStyle.BackColor = Color.Red;
\r
304 p.ParentLevelsDisplayed = 2;
\r
305 p.RenderCurrentNodeAsLink = true;
\r
306 p.SiteMapProvider = "test";
\r
307 p.SkipLinkText = "test";
\r
309 object state = p.SaveState ();
\r
310 PokerSiteMapPath copy = new PokerSiteMapPath ();
\r
311 copy.LoadState (state);
\r
312 Assert.IsFalse (copy.ShowToolTips, "ShowToolTips");
\r
313 Assert.AreEqual (Color.AliceBlue, copy.CurrentNodeStyle.ForeColor, "CurrentNodeStyle");
\r
314 Assert.AreEqual (Color.Aqua, p.NodeStyle.BackColor, "NodeStyle");
\r
315 Assert.AreEqual (" - ", p.PathSeparator, "PathSeparator");
\r
316 Assert.IsFalse (p.RootNodeStyle.IsEmpty, "RootNodeStyle#1");
\r
317 Assert.AreEqual (Color.Red, p.RootNodeStyle.BackColor, "RootNodeStyle#2");
\r
318 Assert.AreEqual (2, p.ParentLevelsDisplayed, "ParentLevelsDisplayed");
\r
319 Assert.IsTrue (p.RenderCurrentNodeAsLink, "RenderCurrentNodeAsLink");
\r
320 Assert.AreEqual ("test", p.SiteMapProvider, "SiteMapProvider");
\r
321 Assert.AreEqual ("test", p.SkipLinkText, "Skip Navigation Links");
\r
325 [Category ("NunitWeb")]
\r
326 public void SiteMapPath_InitializeItemCurrent ()
\r
328 new WebTest (PageInvoker.CreateOnLoad (InitializeItemCurrent)).Run ();
\r
331 public static void InitializeItemCurrent (Page p)
\r
333 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
334 SiteMapNodeItem I = new SiteMapNodeItem (1, SiteMapNodeItemType.Current);
\r
335 smp.CurrentNodeStyle.BackColor = Color.Red;
\r
336 smp.NodeStyle.BorderColor = Color.Red;
\r
337 smp.DoCreateControlHierarchy ();
\r
338 I.SiteMapNode = smp.Provider.CurrentNode;
\r
339 smp.InitilizeItems (I);
\r
341 Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
\r
342 Assert.AreEqual (typeof (Literal), I.Controls[0].GetType (), "InitializeItem#2");
\r
343 Assert.AreEqual (Color.Red, I.BackColor , "InitializeItem#3");
\r
344 Assert.AreEqual (Color.Red, I.BorderColor, "InitializeItem#4");
\r
346 I.Controls.Clear ();
\r
347 smp.RenderCurrentNodeAsLink = true;
\r
348 smp.InitilizeItems (I);
\r
350 Assert.AreEqual (1, I.Controls.Count, "InitializeItem#5");
\r
351 Assert.AreEqual (typeof (HyperLink), I.Controls[0].GetType (), "InitializeItem#6");
\r
352 Assert.AreEqual (Color.Red, I.BackColor, "InitializeItem#7");
\r
353 Assert.AreEqual (Color.Red, I.BorderColor, "InitializeItem#8");
\r
357 [Category ("NunitWeb")]
\r
358 public void SiteMapPath_InitializeItemRoot ()
\r
360 new WebTest (PageInvoker.CreateOnLoad (InitializeItemRoot)).Run ();
\r
363 public static void InitializeItemRoot (Page p)
\r
365 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
366 SiteMapNodeItem I = new SiteMapNodeItem (0, SiteMapNodeItemType.Root);
\r
367 smp.RootNodeStyle.BackColor = Color.Red;
\r
368 smp.NodeStyle.BorderColor = Color.Red;
\r
369 smp.DoCreateControlHierarchy ();
\r
370 I.SiteMapNode = smp.Provider.RootNode;
\r
371 smp.InitilizeItems (I);
\r
373 Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
\r
374 Assert.AreEqual (typeof (HyperLink), I.Controls[0].GetType (), "InitializeItem#2");
\r
375 Assert.AreEqual (Color.Red, ((HyperLink)I.Controls[0]).ControlStyle.BackColor, "InitializeItem#3");
\r
376 Assert.AreEqual (Color.Red, ((HyperLink)I.Controls[0]).ControlStyle.BorderColor, "InitializeItem#4");
\r
380 [Category ("NunitWeb")]
\r
381 public void SiteMapPath_InitializeItemParent ()
\r
383 new WebTest (PageInvoker.CreateOnLoad (InitializeItemParent)).Run ();
\r
386 public static void InitializeItemParent (Page p)
\r
388 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
389 SiteMapNodeItem I = new SiteMapNodeItem (0, SiteMapNodeItemType.Parent);
\r
390 smp.NodeStyle.BorderColor = Color.Red;
\r
391 smp.DoCreateControlHierarchy ();
\r
392 I.SiteMapNode = smp.Provider.RootNode;
\r
393 smp.InitilizeItems (I);
\r
395 Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
\r
396 Assert.AreEqual (typeof (HyperLink), I.Controls[0].GetType (), "InitializeItem#2");
\r
397 Assert.AreEqual (Color.Red, ((HyperLink) I.Controls[0]).ControlStyle.BorderColor, "InitializeItem#4");
\r
401 [Category ("NunitWeb")]
\r
402 public void SiteMapPath_InitializeItemPathSeparator ()
\r
404 new WebTest (PageInvoker.CreateOnLoad (InitializeItemPathSeparator)).Run ();
\r
407 public static void InitializeItemPathSeparator (Page p)
\r
409 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
410 SiteMapNodeItem I = new SiteMapNodeItem (0, SiteMapNodeItemType.PathSeparator);
\r
411 smp.PathSeparatorStyle.BorderColor = Color.Red;
\r
412 smp.InitilizeItems (I);
\r
413 Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
\r
414 Assert.AreEqual (typeof (Literal), I.Controls[0].GetType (), "InitializeItem#2");
\r
415 Assert.AreEqual (Color.Red, I.BorderColor, "InitializeItem#3");
\r
419 [Category ("NunitWeb")]
\r
420 public void SiteMapPath_InitializeItemTemplates ()
\r
422 new WebTest (PageInvoker.CreateOnLoad (InitializeItemTemplates)).Run ();
\r
425 public static void InitializeItemTemplates (Page p)
\r
427 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
428 SiteMapNodeItem I = new SiteMapNodeItem (1, SiteMapNodeItemType.Current);
\r
429 smp.CurrentNodeTemplate = new CompiledTemplateBuilder (templatebuilder);
\r
430 smp.CurrentNodeStyle.BackColor = Color.Red;
\r
431 smp.DoCreateControlHierarchy ();
\r
432 I.SiteMapNode = smp.Provider.CurrentNode;
\r
433 smp.InitilizeItems (I);
\r
435 Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
\r
436 Assert.AreEqual (typeof (TextBox), I.Controls[0].GetType (), "InitializeItem#2");
\r
437 Assert.AreEqual (Color.Red, I.BackColor, "InitializeItem#3");
\r
440 private static void templatebuilder (Control container)
\r
443 ctrl = new TextBox ();
\r
444 ctrl.ID = "TextBox1";
\r
445 container.Controls.Add (ctrl);
\r
450 [Category ("NunitWeb")]
\r
451 public void SiteMapPath_SiteMapRootNode ()
\r
453 new WebTest (PageInvoker.CreateOnLoad (SiteMapRootNode)).Run ();
\r
457 [Category ("NunitWeb")]
\r
458 public void SiteMapPath_SiteMapChildNode ()
\r
460 new WebTest (PageInvoker.CreateOnLoad (InitializeItemPathSeparator)).Run ();
\r
462 public static void SiteMapRootNode (Page p)
\r
464 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
465 Assert.AreEqual ("root", smp.Provider.RootNode.Title, "RootNode");
\r
468 public static void SiteMapChildNode (Page p)
\r
470 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
471 SiteMapNodeCollection myCol = smp.Provider.GetChildNodes (smp.Provider.RootNode);
\r
472 Assert.AreEqual (1, myCol.Count, "SiteMapChildNode#1");
\r
477 [Category ("NunitWeb")]
\r
478 [Category ("NotWorking")]
\r
479 public void SiteMapPath_FireEvents()
\r
481 WebTest t = new WebTest (PageInvoker.CreateOnInit(FireEvents_Init));
\r
483 ArrayList eventlist = t.UserData as ArrayList;
\r
484 if (eventlist == null)
\r
485 Assert.Fail ("User data does not been created fail");
\r
487 Assert.AreEqual ("ItemCreated", eventlist[0], "#1");
\r
488 Assert.AreEqual ("ItemDataBound", eventlist[1], "#2");
\r
489 Assert.AreEqual ("ItemCreated", eventlist[2], "#3");
\r
490 Assert.AreEqual ("ItemDataBound", eventlist[3], "#4");
\r
491 Assert.AreEqual ("ItemCreated", eventlist[4], "#5");
\r
492 Assert.AreEqual ("ItemDataBound", eventlist[5], "#6");
\r
496 public static void FireEvents_Init (Page p)
\r
498 SiteMapPath s = new SiteMapPath ();
\r
499 s.ItemCreated += new SiteMapNodeItemEventHandler (s_ItemCreated);
\r
500 s.ItemDataBound += new SiteMapNodeItemEventHandler (s_ItemDataBound);
\r
501 p.Form.Controls.Add (s);
\r
504 static void s_ItemDataBound (object sender, SiteMapNodeItemEventArgs e)
\r
506 if (WebTest.CurrentTest.UserData == null) {
\r
507 ArrayList list = new ArrayList ();
\r
508 list.Add ("ItemDataBound");
\r
509 WebTest.CurrentTest.UserData = list;
\r
512 ArrayList list = WebTest.CurrentTest.UserData as ArrayList;
\r
514 throw new NullReferenceException ();
\r
515 list.Add ("ItemDataBound");
\r
516 WebTest.CurrentTest.UserData = list;
\r
520 static void s_ItemCreated (object sender, SiteMapNodeItemEventArgs e)
\r
522 if (WebTest.CurrentTest.UserData == null) {
\r
523 ArrayList list = new ArrayList ();
\r
524 list.Add ("ItemCreated");
\r
525 WebTest.CurrentTest.UserData = list;
\r
528 ArrayList list = WebTest.CurrentTest.UserData as ArrayList;
\r
530 throw new NullReferenceException ();
\r
531 list.Add ("ItemCreated");
\r
532 WebTest.CurrentTest.UserData = list;
\r
538 private bool DataBinding;
\r
539 private bool ItemDataBounding;
\r
540 private bool ItemCreated;
\r
542 private void DataBindingHandler (object sender, EventArgs e)
\r
544 DataBinding = true;
\r
546 private void ItemDataBoundHandler (object sender, SiteMapNodeItemEventArgs e)
\r
548 ItemDataBounding = true;
\r
550 private void ItemCreatedHandler (object sender, SiteMapNodeItemEventArgs e)
\r
552 ItemCreated = true;
\r
554 private void ResetEvents ()
\r
556 DataBinding = false;
\r
557 ItemDataBounding = false;
\r
558 ItemCreated = false;
\r
562 [Category ("NunitWeb")]
\r
563 public void SiteMapPath_Events ()
\r
565 new WebTest (PageInvoker.CreateOnLoad (Events)).Run ();
\r
568 public void Events (Page p)
\r
570 PokerSiteMapPath smp = new PokerSiteMapPath ();
\r
572 smp.DataBinding += new EventHandler (DataBindingHandler);
\r
573 smp.ItemDataBound += new SiteMapNodeItemEventHandler (ItemDataBoundHandler);
\r
574 smp.ItemCreated += new SiteMapNodeItemEventHandler (ItemCreatedHandler);
\r
576 Assert.AreEqual (false, DataBinding, "BeforeDataBinding");
\r
577 smp.DoOnDataBinding (new EventArgs ());
\r
578 Assert.AreEqual (true, DataBinding, "AfterDataBinding");
\r
581 Assert.AreEqual (false, ItemDataBounding, "BeforeItemDataBound");
\r
582 SiteMapNodeItem i = new SiteMapNodeItem (0, SiteMapNodeItemType.Root);
\r
583 smp.DoOnItemDataBound (new SiteMapNodeItemEventArgs (i));
\r
584 Assert.AreEqual (true, ItemDataBounding, "AfterItemDataBound");
\r
587 SiteMapNodeItemEventArgs MyArgs = new SiteMapNodeItemEventArgs (new SiteMapNodeItem(0,SiteMapNodeItemType.Parent));
\r
588 Assert.AreEqual (false, ItemCreated, "BeforeItemCreated");
\r
589 smp.DoOnItemCteated (MyArgs);
\r
590 Assert.AreEqual (true, ItemCreated, "AfterItemCreated");
\r
594 //[Category ("NotWorking")] //throws System.IndexOutOfRangeException : Array index is out of range
\r
595 //[ExpectedException (typeof (ConfigurationErrorsException))]
\r
596 //public void SiteMapPath_CreateControlHierarchy ()
\r
598 // PokerSiteMapPath p = new PokerSiteMapPath ();
\r
599 // p.DoCreateControlHierarchy ();
\r
602 //[Category ("NotWorking")] //throws System.IndexOutOfRangeException : Array index is out of range
\r
603 //[ExpectedException (typeof (ConfigurationErrorsException))]
\r
604 //public void SiteMapPath_DataBindExeption ()
\r
606 // PokerSiteMapPath p = new PokerSiteMapPath ();
\r
611 [TestFixtureTearDown]
\r
612 public void TearDown ()
\r
617 // A simple Template class to wrap an image.
\r
618 public class ImageTemplate : ITemplate
\r
620 private MyWebControl.Image myImage;
\r
621 public MyWebControl.Image MyImage
\r
632 public void InstantiateIn (Control container)
\r
634 container.Controls.Add (MyImage);
\r