2
0

HyperLinkColumnTest.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // PagedDataSourceTest.cs
  3. //
  4. // Author: Duncan Mak ([email protected])
  5. //
  6. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining
  9. // a copy of this software and associated documentation files (the
  10. // "Software"), to deal in the Software without restriction, including
  11. // without limitation the rights to use, copy, modify, merge, publish,
  12. // distribute, sublicense, and/or sell copies of the Software, and to
  13. // permit persons to whom the Software is furnished to do so, subject to
  14. // the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be
  17. // included in all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. //
  27. using NUnit.Framework;
  28. using System;
  29. using System.Collections;
  30. using System.Diagnostics;
  31. using System.Web.UI.WebControls;
  32. namespace MonoTests.System.Web.UI.WebControls {
  33. [TestFixture]
  34. public class HyperLinkColumnTest {
  35. [Test]
  36. public void SetUpTest ()
  37. {
  38. HyperLinkColumn column = new HyperLinkColumn ();
  39. Assert.AreEqual (String.Empty, column.DataNavigateUrlField, "#1");
  40. Assert.AreEqual (String.Empty, column.DataTextField, "2");
  41. Assert.AreEqual (String.Empty, column.DataTextFormatString, "#3");
  42. Assert.AreEqual (String.Empty, column.NavigateUrl, "#4");
  43. Assert.AreEqual (String.Empty, column.Target, "#5");
  44. Assert.AreEqual (String.Empty, column.Text, "#6");
  45. }
  46. [Test]
  47. public void DataNavigateUrlFieldTest ()
  48. {
  49. HyperLinkColumn column = new HyperLinkColumn ();
  50. string foo = "foo";
  51. string bar = "bar";
  52. column.NavigateUrl = foo;
  53. Assert.AreEqual (foo, column.NavigateUrl, "#1");
  54. // Test the bit about DataNavigateUrlField having precedence over NavigateUrl
  55. column.DataNavigateUrlField = bar;
  56. Assert.AreEqual (bar, column.DataNavigateUrlField, "#2");
  57. // what does this mean? shouldn't NavigateUrl be "bar" now?
  58. Assert.AreEqual (foo, column.NavigateUrl, "#3");
  59. }
  60. public class MyColumn : HyperLinkColumn {
  61. public string FormatUrl (object input)
  62. {
  63. return FormatDataNavigateUrlValue (input);
  64. }
  65. public string FormatText (object input)
  66. {
  67. return FormatDataTextValue (input);
  68. }
  69. public void InitCell (TableCell cell, int column_index, ListItemType item_type)
  70. {
  71. base.InitializeCell (cell, column_index, item_type);
  72. }
  73. }
  74. [Test]
  75. public void FormatTest ()
  76. {
  77. MyColumn column = new MyColumn ();
  78. column.DataNavigateUrlFormatString = "!{0}!";
  79. Assert.AreEqual (String.Empty, column.FormatUrl (null), "#1");
  80. Assert.AreEqual ("!foo!", column.FormatUrl ("foo"), "#2");
  81. column.DataTextFormatString = "!{0}!";
  82. Assert.AreEqual (String.Empty, column.FormatText (null), "#3");
  83. Assert.AreEqual ("!foo!", column.FormatText ("foo"), "#4");
  84. }
  85. [Test]
  86. public void InitCellTest ()
  87. {
  88. MyColumn column;
  89. TableCell cell;
  90. /* test that for Header it just sets the cell.Text to HeaderText */
  91. column = new MyColumn();
  92. cell = new TableCell();
  93. column.HeaderText = "This is a Header";
  94. column.InitCell (cell, 0, ListItemType.Header);
  95. Assert.AreEqual ("This is a Header", cell.Text, "#1");
  96. /* test that for Item it adds a HyperLinkControl */
  97. column = new MyColumn();
  98. cell = new TableCell();
  99. column.NavigateUrl = "http://www.novell.com/";
  100. column.Text = "Novell.com";
  101. column.InitCell (cell, 0, ListItemType.Item);
  102. Assert.AreEqual (1, cell.Controls.Count, "#2");
  103. Assert.IsTrue (cell.Controls[0] is HyperLink, "#3");
  104. /* test that for EditItem it adds a HyperLinkControl */
  105. column = new MyColumn();
  106. cell = new TableCell();
  107. column.NavigateUrl = "http://www.novell.com/";
  108. column.Text = "Novell.com";
  109. column.InitCell (cell, 0, ListItemType.EditItem);
  110. Assert.AreEqual (1, cell.Controls.Count, "#4");
  111. Assert.IsTrue (cell.Controls[0] is HyperLink, "#5");
  112. /* test that for AlternatingItem it adds a HyperLinkControl */
  113. column = new MyColumn();
  114. cell = new TableCell();
  115. column.NavigateUrl = "http://www.novell.com/";
  116. column.Text = "Novell.com";
  117. column.InitCell (cell, 0, ListItemType.AlternatingItem);
  118. Assert.AreEqual (1, cell.Controls.Count, "#6");
  119. Assert.IsTrue (cell.Controls[0] is HyperLink, "#7");
  120. /* test that for Footer it just sets the cell.Text to FooterText */
  121. column = new MyColumn();
  122. cell = new TableCell();
  123. column.FooterText = "This is a Footer";
  124. column.InitCell (cell, 0, ListItemType.Footer);
  125. Assert.AreEqual ("This is a Footer", cell.Text, "#8");
  126. }
  127. }
  128. }