SiteMapPathTest.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. //
  2. // Tests for System.Web.UI.WebControls.SiteMapPath.cs
  3. //
  4. // Author:
  5. // Yoni Klein ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  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:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  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.
  28. #if NET_2_0
  29. using NUnit.Framework;
  30. using System;
  31. using System.Web;
  32. using System.Web.UI;
  33. using System.Web.UI.WebControls;
  34. using System.Threading;
  35. using System.Drawing;
  36. using System.Configuration;
  37. using MyWebControl = System.Web.UI.WebControls;
  38. using MonoTests.SystemWeb.Framework;
  39. using MonoTests.stand_alone.WebHarness;
  40. namespace MonoTests.System.Web.UI.WebControls
  41. {
  42. class PokerSiteMapPath : SiteMapPath
  43. {
  44. public PokerSiteMapPath ()
  45. {
  46. TrackViewState ();
  47. }
  48. public StateBag StateBag
  49. {
  50. get { return base.ViewState; }
  51. }
  52. public object SaveState ()
  53. {
  54. return SaveViewState ();
  55. }
  56. public void LoadState (object o)
  57. {
  58. LoadViewState (o);
  59. }
  60. public void InitilizeItems (SiteMapNodeItem I)
  61. {
  62. InitializeItem (I);
  63. }
  64. public void DoCreateControlHierarchy ()
  65. {
  66. CreateControlHierarchy ();
  67. }
  68. public void DoOnDataBinding (EventArgs e)
  69. {
  70. base.OnDataBinding (e);
  71. }
  72. public void DoOnItemDataBound (SiteMapNodeItemEventArgs e)
  73. {
  74. base.OnItemDataBound (e);
  75. }
  76. public void DoOnItemCteated (SiteMapNodeItemEventArgs e)
  77. {
  78. base.OnItemCreated (e);
  79. }
  80. }
  81. [Serializable]
  82. [TestFixture]
  83. public class SiteMapPathTest
  84. {
  85. [TestFixtureSetUp]
  86. public void Set_Up ()
  87. {
  88. #if DOT_NET
  89. WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.Web.sitemap","Web.sitemap");
  90. #else
  91. WebTest.CopyResource (GetType (), "Web.sitemap", "Web.sitemap");
  92. #endif
  93. }
  94. [SetUp]
  95. public void SetupTestCase ()
  96. {
  97. Thread.Sleep (100);
  98. }
  99. [Test]
  100. public void SiteMapPath_DefaultProperties ()
  101. {
  102. PokerSiteMapPath p = new PokerSiteMapPath ();
  103. Assert.IsTrue (p.CurrentNodeStyle.IsEmpty, "CurrentNodeStyle");
  104. Assert.IsNull (p.CurrentNodeTemplate, "CurrentNodeTemplate");
  105. Assert.IsTrue (p.NodeStyle.IsEmpty, "NodeStyle");
  106. Assert.IsNull (p.NodeTemplate, "NodeTemplate");
  107. Assert.AreEqual (-1, p.ParentLevelsDisplayed, "ParentLevelsDisplayed");
  108. Assert.AreEqual (PathDirection.RootToCurrent, p.PathDirection, "PathDirection");
  109. Assert.IsNull (p.PathSeparatorTemplate, "PathSeparatorTemplate");
  110. Assert.IsFalse (p.RenderCurrentNodeAsLink, "RenderCurrentNodeAsLink");
  111. Assert.IsTrue (p.RootNodeStyle.IsEmpty, "RootNodeStyle");
  112. Assert.IsNull (p.RootNodeTemplate, "RootNodeTemplate");
  113. Assert.IsTrue (p.ShowToolTips, "ShowToolTips");
  114. Assert.AreEqual ("", p.SiteMapProvider, "SiteMapProvider");
  115. Assert.AreEqual ("Skip Navigation Links", p.SkipLinkText, "Skip Navigation Links");
  116. }
  117. [Test]
  118. public void SiteMapPath_DefaultNotWorkingProperties()
  119. {
  120. PokerSiteMapPath p = new PokerSiteMapPath ();
  121. Assert.AreEqual (" > ", p.PathSeparator, "PathSeparator");
  122. }
  123. [Test]
  124. public void SiteMapPath_ChangeProperties ()
  125. {
  126. PokerSiteMapPath p = new PokerSiteMapPath ();
  127. p.ShowToolTips = false;
  128. Assert.IsFalse (p.ShowToolTips, "ShowToolTips");
  129. Style currentNodeStyle = new Style ();
  130. p.CurrentNodeStyle.ForeColor = Color.AliceBlue;
  131. Assert.AreEqual (Color.AliceBlue, p.CurrentNodeStyle.ForeColor, "CurrentNodeStyle");
  132. Style NodeStyle = new Style ();
  133. p.NodeStyle.BackColor = Color.Aqua;
  134. Assert.AreEqual (Color.Aqua, p.NodeStyle.BackColor, "NodeStyle");
  135. p.PathDirection = PathDirection.CurrentToRoot;
  136. Assert.AreEqual (PathDirection.CurrentToRoot, p.PathDirection, "PathDirection");
  137. p.PathSeparator = " - ";
  138. Assert.AreEqual (" - ", p.PathSeparator, "PathSeparator");
  139. Style RootNodeStyle = new Style ();
  140. p.RootNodeStyle.BackColor = Color.Red;
  141. Assert.IsFalse (p.RootNodeStyle.IsEmpty, "RootNodeStyle#1");
  142. Assert.AreEqual (Color.Red, p.RootNodeStyle.BackColor, "RootNodeStyle#2");
  143. p.ParentLevelsDisplayed = 2;
  144. Assert.AreEqual (2, p.ParentLevelsDisplayed, "ParentLevelsDisplayed");
  145. p.RenderCurrentNodeAsLink = true;
  146. Assert.IsTrue (p.RenderCurrentNodeAsLink, "RenderCurrentNodeAsLink");
  147. p.SiteMapProvider = "test";
  148. Assert.AreEqual ("test", p.SiteMapProvider, "SiteMapProvider");
  149. p.SkipLinkText = "test";
  150. Assert.AreEqual ("test", p.SkipLinkText, "Skip Navigation Links");
  151. //programmatically create template
  152. MyWebControl.Image myImage = new MyWebControl.Image ();
  153. myImage.ImageUrl = "myimage.jpg";
  154. ImageTemplate rootNodeImageTemplate = new ImageTemplate ();
  155. rootNodeImageTemplate.MyImage = myImage;
  156. // end create template image
  157. p.RootNodeTemplate = rootNodeImageTemplate;
  158. Assert.IsNotNull (p.RootNodeTemplate, "RootNodeTemplate");
  159. Assert.AreEqual (rootNodeImageTemplate, p.RootNodeTemplate, "RootNodeTemplate");
  160. p.NodeTemplate = rootNodeImageTemplate;
  161. Assert.IsNotNull (p.NodeTemplate, "NodeTemplate");
  162. Assert.AreEqual (rootNodeImageTemplate, p.NodeTemplate, "NodeTemplate");
  163. p.CurrentNodeTemplate = rootNodeImageTemplate;
  164. Assert.IsNotNull (p.CurrentNodeTemplate, "RootNodeTemplate");
  165. Assert.AreEqual (rootNodeImageTemplate, p.CurrentNodeTemplate, "RootNodeTemplate");
  166. }
  167. [Test]
  168. public void SiteMapPath_NullProperties ()
  169. {
  170. PokerSiteMapPath p = new PokerSiteMapPath ();
  171. p.ShowToolTips = false;
  172. Assert.IsFalse (p.ShowToolTips, "ShowToolTips");
  173. Assert.AreEqual (1, p.StateBag.Count, "NullProperties#1");
  174. p.PathDirection = PathDirection.CurrentToRoot;
  175. Assert.AreEqual (PathDirection.CurrentToRoot, p.PathDirection, "PathDirection");
  176. Assert.AreEqual (2, p.StateBag.Count, "NullProperties#2");
  177. p.PathSeparator = " - ";
  178. Assert.AreEqual (3, p.StateBag.Count, "NullProperties#3");
  179. p.SiteMapProvider = "test";
  180. Assert.AreEqual (4, p.StateBag.Count, "NullProperties#4");
  181. p.SkipLinkText = "test";
  182. Assert.AreEqual (5, p.StateBag.Count, "NullProperties#5");
  183. p.SkipLinkText = null;
  184. }
  185. // Rendering tests
  186. [Test]
  187. [Category ("NunitWeb")]
  188. public void SiteMapPath_RenderProperty ()
  189. {
  190. string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (DoTestPropertyRender)).Run ();
  191. string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
  192. string OriginControlHtml = @"<span style=""display:inline-block;color:Red;background-color:Red;border-color:Red;border-width:3px;border-style:Dashed;"">
  193. <a href=""#ctl01_SkipLink""><img alt=""Skip Navigation Links"" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd""
  194. style=""border-width:0px;"" /></a><span>node1</span><span>-</span><span><a title=""test"" href=""/NunitWeb/MyPageWithMaster.aspx"">root</a>
  195. </span><a id=""ctl01_SkipLink""></a></span>";
  196. HtmlDiff.AssertAreEqual(OriginControlHtml,RenderedControlHtml,"RenderProperty");
  197. }
  198. [Test]
  199. [Category ("NunitWeb")]
  200. public void SiteMapPath_RenderStyles ()
  201. {
  202. string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (DoTestStylesRender)).Run ();
  203. string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
  204. string OriginControlHtml = @"<span style=""background-color:Red;""><a href=""#ctl01_SkipLink"">
  205. <img alt=""Skip Navigation Links"" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd""
  206. style=""border-width:0px;"" /></a><span><a title=""test"" href=""/NunitWeb/MyPageWithMaster.aspx""
  207. style=""background-color:Beige;border-color:Purple;"">root</a></span>
  208. <span style=""background-color:RoyalBlue;""> &gt; </span><span style=""background-color:Pink;border-color:Purple;"">node1</span>
  209. <a id=""ctl01_SkipLink""></a></span>";
  210. HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml,"RenderStyles");
  211. }
  212. [Test]
  213. [Category ("NunitWeb")]
  214. public void SiteMapPath_DefaultRender()
  215. {
  216. string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (DoTestDefaultRender)).Run ();
  217. string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
  218. string OriginControlHtml = @"<span><a href=""#ctl01_SkipLink"">
  219. <img alt=""Skip Navigation Links"" height=""0"" width=""0"" src=""/NunitWeb/WebResource.axd""
  220. style=""border-width:0px;"" /></a><span><a title=""test"" href=""/NunitWeb/MyPageWithMaster.aspx"">root</a>
  221. </span><span> &gt; </span><span>node1</span><a id=""ctl01_SkipLink""></a></span>";
  222. HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml,"RenderDefault");
  223. }
  224. /// <summary>
  225. /// All this methods are delegates for running tests in host assembly.
  226. /// </summary>
  227. public static void DoTestDefaultRender (Page p)
  228. {
  229. LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
  230. LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
  231. SiteMapPath smp = new SiteMapPath ();
  232. p.Form.Controls.Add (lcb);
  233. p.Form.Controls.Add (smp);
  234. p.Form.Controls.Add (lce);
  235. }
  236. public static void DoTestPropertyRender (Page p)
  237. {
  238. SiteMapPath smp = new SiteMapPath ();
  239. smp.BackColor = Color.Red;
  240. smp.BorderColor = Color.Red;
  241. smp.BorderStyle = BorderStyle.Dashed;
  242. smp.BorderWidth = 3;
  243. smp.ForeColor = Color.Red;
  244. smp.PathDirection = PathDirection.CurrentToRoot;
  245. smp.PathSeparator = "-";
  246. LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
  247. LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
  248. p.Form.Controls.Add (lcb);
  249. p.Form.Controls.Add (smp);
  250. p.Form.Controls.Add (lce);
  251. }
  252. public static void DoTestStylesRender (Page p)
  253. {
  254. PokerSiteMapPath smp = new PokerSiteMapPath ();
  255. smp.ControlStyle.BackColor = Color.Red;
  256. smp.CurrentNodeStyle.BackColor = Color.Pink;
  257. smp.NodeStyle.BorderColor = Color.Purple;
  258. smp.PathSeparatorStyle.BackColor = Color.RoyalBlue;
  259. smp.RootNodeStyle.BackColor = Color.Beige;
  260. LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
  261. LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
  262. p.Form.Controls.Add (lcb);
  263. p.Form.Controls.Add (smp);
  264. p.Form.Controls.Add (lce);
  265. }
  266. [Test]
  267. public void SiteMapPath_ViewState ()
  268. {
  269. PokerSiteMapPath p = new PokerSiteMapPath ();
  270. p.ShowToolTips = false;
  271. Style currentNodeStyle = new Style ();
  272. p.CurrentNodeStyle.ForeColor = Color.AliceBlue;
  273. Style NodeStyle = new Style ();
  274. p.NodeStyle.BackColor = Color.Aqua;
  275. p.PathDirection = PathDirection.CurrentToRoot;
  276. Assert.AreEqual (PathDirection.CurrentToRoot, p.PathDirection, "PathDirection");
  277. p.PathSeparator = " - ";
  278. Style RootNodeStyle = new Style ();
  279. p.RootNodeStyle.BackColor = Color.Red;
  280. p.ParentLevelsDisplayed = 2;
  281. p.RenderCurrentNodeAsLink = true;
  282. p.SiteMapProvider = "test";
  283. p.SkipLinkText = "test";
  284. object state = p.SaveState ();
  285. PokerSiteMapPath copy = new PokerSiteMapPath ();
  286. copy.LoadState (state);
  287. Assert.IsFalse (copy.ShowToolTips, "ShowToolTips");
  288. Assert.AreEqual (Color.AliceBlue, copy.CurrentNodeStyle.ForeColor, "CurrentNodeStyle");
  289. Assert.AreEqual (Color.Aqua, p.NodeStyle.BackColor, "NodeStyle");
  290. Assert.AreEqual (" - ", p.PathSeparator, "PathSeparator");
  291. Assert.IsFalse (p.RootNodeStyle.IsEmpty, "RootNodeStyle#1");
  292. Assert.AreEqual (Color.Red, p.RootNodeStyle.BackColor, "RootNodeStyle#2");
  293. Assert.AreEqual (2, p.ParentLevelsDisplayed, "ParentLevelsDisplayed");
  294. Assert.IsTrue (p.RenderCurrentNodeAsLink, "RenderCurrentNodeAsLink");
  295. Assert.AreEqual ("test", p.SiteMapProvider, "SiteMapProvider");
  296. Assert.AreEqual ("test", p.SkipLinkText, "Skip Navigation Links");
  297. }
  298. [Test]
  299. [Category ("NunitWeb")]
  300. public void SiteMapPath_InitializeItemCurrent ()
  301. {
  302. new WebTest (PageInvoker.CreateOnLoad (InitializeItemCurrent)).Run ();
  303. }
  304. public static void InitializeItemCurrent (Page p)
  305. {
  306. PokerSiteMapPath smp = new PokerSiteMapPath ();
  307. SiteMapNodeItem I = new SiteMapNodeItem (1, SiteMapNodeItemType.Current);
  308. smp.CurrentNodeStyle.BackColor = Color.Red;
  309. smp.NodeStyle.BorderColor = Color.Red;
  310. smp.DoCreateControlHierarchy ();
  311. I.SiteMapNode = smp.Provider.CurrentNode;
  312. smp.InitilizeItems (I);
  313. Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
  314. Assert.AreEqual (typeof (Literal), I.Controls[0].GetType (), "InitializeItem#2");
  315. Assert.AreEqual (Color.Red, I.BackColor , "InitializeItem#3");
  316. Assert.AreEqual (Color.Red, I.BorderColor, "InitializeItem#4");
  317. I.Controls.Clear ();
  318. smp.RenderCurrentNodeAsLink = true;
  319. smp.InitilizeItems (I);
  320. Assert.AreEqual (1, I.Controls.Count, "InitializeItem#5");
  321. Assert.AreEqual (typeof (HyperLink), I.Controls[0].GetType (), "InitializeItem#6");
  322. Assert.AreEqual (Color.Red, I.BackColor, "InitializeItem#7");
  323. Assert.AreEqual (Color.Red, I.BorderColor, "InitializeItem#8");
  324. }
  325. [Test]
  326. [Category ("NunitWeb")]
  327. public void SiteMapPath_InitializeItemRoot ()
  328. {
  329. new WebTest (PageInvoker.CreateOnLoad (InitializeItemRoot)).Run ();
  330. }
  331. public static void InitializeItemRoot (Page p)
  332. {
  333. PokerSiteMapPath smp = new PokerSiteMapPath ();
  334. SiteMapNodeItem I = new SiteMapNodeItem (0, SiteMapNodeItemType.Root);
  335. smp.RootNodeStyle.BackColor = Color.Red;
  336. smp.NodeStyle.BorderColor = Color.Red;
  337. smp.DoCreateControlHierarchy ();
  338. I.SiteMapNode = smp.Provider.RootNode;
  339. smp.InitilizeItems (I);
  340. Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
  341. Assert.AreEqual (typeof (HyperLink), I.Controls[0].GetType (), "InitializeItem#2");
  342. Assert.AreEqual (Color.Red, ((HyperLink)I.Controls[0]).ControlStyle.BackColor, "InitializeItem#3");
  343. Assert.AreEqual (Color.Red, ((HyperLink)I.Controls[0]).ControlStyle.BorderColor, "InitializeItem#4");
  344. }
  345. [Test]
  346. [Category ("NunitWeb")]
  347. public void SiteMapPath_InitializeItemParent ()
  348. {
  349. new WebTest (PageInvoker.CreateOnLoad (InitializeItemParent)).Run ();
  350. }
  351. public static void InitializeItemParent (Page p)
  352. {
  353. PokerSiteMapPath smp = new PokerSiteMapPath ();
  354. SiteMapNodeItem I = new SiteMapNodeItem (0, SiteMapNodeItemType.Parent);
  355. smp.NodeStyle.BorderColor = Color.Red;
  356. smp.DoCreateControlHierarchy ();
  357. I.SiteMapNode = smp.Provider.RootNode;
  358. smp.InitilizeItems (I);
  359. Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
  360. Assert.AreEqual (typeof (HyperLink), I.Controls[0].GetType (), "InitializeItem#2");
  361. Assert.AreEqual (Color.Red, ((HyperLink) I.Controls[0]).ControlStyle.BorderColor, "InitializeItem#4");
  362. }
  363. [Test]
  364. [Category ("NunitWeb")]
  365. public void SiteMapPath_InitializeItemPathSeparator ()
  366. {
  367. new WebTest (PageInvoker.CreateOnLoad (InitializeItemPathSeparator)).Run ();
  368. }
  369. public static void InitializeItemPathSeparator (Page p)
  370. {
  371. PokerSiteMapPath smp = new PokerSiteMapPath ();
  372. SiteMapNodeItem I = new SiteMapNodeItem (0, SiteMapNodeItemType.PathSeparator);
  373. smp.PathSeparatorStyle.BorderColor = Color.Red;
  374. smp.InitilizeItems (I);
  375. Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
  376. Assert.AreEqual (typeof (Literal), I.Controls[0].GetType (), "InitializeItem#2");
  377. Assert.AreEqual (Color.Red, I.BorderColor, "InitializeItem#3");
  378. }
  379. [Test]
  380. [Category ("NunitWeb")]
  381. public void SiteMapPath_InitializeItemTemplates ()
  382. {
  383. new WebTest (PageInvoker.CreateOnLoad (InitializeItemTemplates)).Run ();
  384. }
  385. public static void InitializeItemTemplates (Page p)
  386. {
  387. PokerSiteMapPath smp = new PokerSiteMapPath ();
  388. SiteMapNodeItem I = new SiteMapNodeItem (1, SiteMapNodeItemType.Current);
  389. smp.CurrentNodeTemplate = new CompiledTemplateBuilder (templatebuilder);
  390. smp.CurrentNodeStyle.BackColor = Color.Red;
  391. smp.DoCreateControlHierarchy ();
  392. I.SiteMapNode = smp.Provider.CurrentNode;
  393. smp.InitilizeItems (I);
  394. Assert.AreEqual (1, I.Controls.Count, "InitializeItem#1");
  395. Assert.AreEqual (typeof (TextBox), I.Controls[0].GetType (), "InitializeItem#2");
  396. Assert.AreEqual (Color.Red, I.BackColor, "InitializeItem#3");
  397. }
  398. private static void templatebuilder (Control container)
  399. {
  400. TextBox ctrl;
  401. ctrl = new TextBox ();
  402. ctrl.ID = "TextBox1";
  403. container.Controls.Add (ctrl);
  404. }
  405. [Test]
  406. [Category ("NunitWeb")]
  407. public void SiteMapPath_SiteMapRootNode ()
  408. {
  409. new WebTest (PageInvoker.CreateOnLoad (SiteMapRootNode)).Run ();
  410. }
  411. [Test]
  412. [Category ("NunitWeb")]
  413. public void SiteMapPath_SiteMapChildNode ()
  414. {
  415. new WebTest (PageInvoker.CreateOnLoad (InitializeItemPathSeparator)).Run ();
  416. }
  417. public static void SiteMapRootNode (Page p)
  418. {
  419. PokerSiteMapPath smp = new PokerSiteMapPath ();
  420. Assert.AreEqual ("root", smp.Provider.RootNode.Title, "RootNode");
  421. }
  422. public static void SiteMapChildNode (Page p)
  423. {
  424. PokerSiteMapPath smp = new PokerSiteMapPath ();
  425. SiteMapNodeCollection myCol = smp.Provider.GetChildNodes (smp.Provider.RootNode);
  426. Assert.AreEqual (1, myCol.Count, "SiteMapChildNode#1");
  427. }
  428. // Events Stuff
  429. private bool DataBinding;
  430. private bool ItemDataBounding;
  431. private bool ItemCreated;
  432. private void DataBindingHandler (object sender, EventArgs e)
  433. {
  434. DataBinding = true;
  435. }
  436. private void ItemDataBoundHandler (object sender, SiteMapNodeItemEventArgs e)
  437. {
  438. ItemDataBounding = true;
  439. }
  440. private void ItemCreatedHandler (object sender, SiteMapNodeItemEventArgs e)
  441. {
  442. ItemCreated = true;
  443. }
  444. private void ResetEvents ()
  445. {
  446. DataBinding = false;
  447. ItemDataBounding = false;
  448. ItemCreated = false;
  449. }
  450. [Test]
  451. [Category ("NunitWeb")]
  452. public void SiteMapPath_Events ()
  453. {
  454. new WebTest (PageInvoker.CreateOnLoad (Events)).Run ();
  455. }
  456. public void Events (Page p)
  457. {
  458. PokerSiteMapPath smp = new PokerSiteMapPath ();
  459. ResetEvents ();
  460. smp.DataBinding += new EventHandler (DataBindingHandler);
  461. smp.ItemDataBound += new SiteMapNodeItemEventHandler (ItemDataBoundHandler);
  462. smp.ItemCreated += new SiteMapNodeItemEventHandler (ItemCreatedHandler);
  463. Assert.AreEqual (false, DataBinding, "BeforeDataBinding");
  464. smp.DoOnDataBinding (new EventArgs ());
  465. Assert.AreEqual (true, DataBinding, "AfterDataBinding");
  466. ResetEvents ();
  467. Assert.AreEqual (false, ItemDataBounding, "BeforeItemDataBound");
  468. SiteMapNodeItem i = new SiteMapNodeItem (0, SiteMapNodeItemType.Root);
  469. smp.DoOnItemDataBound (new SiteMapNodeItemEventArgs (i));
  470. Assert.AreEqual (true, ItemDataBounding, "AfterItemDataBound");
  471. ResetEvents ();
  472. SiteMapNodeItemEventArgs MyArgs = new SiteMapNodeItemEventArgs (new SiteMapNodeItem(0,SiteMapNodeItemType.Parent));
  473. Assert.AreEqual (false, ItemCreated, "BeforeItemCreated");
  474. smp.DoOnItemCteated (MyArgs);
  475. Assert.AreEqual (true, ItemCreated, "AfterItemCreated");
  476. }
  477. //[Test]
  478. //[Category ("NotWorking")] //throws System.IndexOutOfRangeException : Array index is out of range
  479. //[ExpectedException (typeof (ConfigurationErrorsException))]
  480. //public void SiteMapPath_CreateControlHierarchy ()
  481. //{
  482. // PokerSiteMapPath p = new PokerSiteMapPath ();
  483. // p.DoCreateControlHierarchy ();
  484. //}
  485. //[Test]
  486. //[Category ("NotWorking")] //throws System.IndexOutOfRangeException : Array index is out of range
  487. //[ExpectedException (typeof (ConfigurationErrorsException))]
  488. //public void SiteMapPath_DataBindExeption ()
  489. //{
  490. // PokerSiteMapPath p = new PokerSiteMapPath ();
  491. // p.DataBind ();
  492. //}
  493. [TestFixtureTearDown]
  494. public void TearDown ()
  495. {
  496. WebTest.Unload ();
  497. }
  498. // A simple Template class to wrap an image.
  499. public class ImageTemplate : ITemplate
  500. {
  501. private MyWebControl.Image myImage;
  502. public MyWebControl.Image MyImage
  503. {
  504. get
  505. {
  506. return myImage;
  507. }
  508. set
  509. {
  510. myImage = value;
  511. }
  512. }
  513. public void InstantiateIn (Control container)
  514. {
  515. container.Controls.Add (MyImage);
  516. }
  517. }
  518. }
  519. }
  520. #endif