PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/System.Web/Test/System.Web.UI.WebControls/SiteMapPathTest.cs

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