2 // HyperLinkColumnTest.cs
4 // Author: Duncan Mak (duncan@novell.com)
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
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.
28 using NUnit.Framework;
30 using System.Collections;
31 using System.Diagnostics;
32 using System.Web.UI.WebControls;
34 namespace MonoTests.System.Web.UI.WebControls {
37 public class HyperLinkColumnTest {
40 public void SetUpTest ()
42 HyperLinkColumn column = new HyperLinkColumn ();
43 Assert.AreEqual (String.Empty, column.DataNavigateUrlField, "#1");
44 Assert.AreEqual (String.Empty, column.DataTextField, "2");
45 Assert.AreEqual (String.Empty, column.DataTextFormatString, "#3");
46 Assert.AreEqual (String.Empty, column.NavigateUrl, "#4");
47 Assert.AreEqual (String.Empty, column.Target, "#5");
48 Assert.AreEqual (String.Empty, column.Text, "#6");
52 public void DataNavigateUrlFieldTest ()
54 HyperLinkColumn column = new HyperLinkColumn ();
58 column.NavigateUrl = foo;
59 Assert.AreEqual (foo, column.NavigateUrl, "#1");
61 // Test the bit about DataNavigateUrlField having precedence over NavigateUrl
62 column.DataNavigateUrlField = bar;
63 Assert.AreEqual (bar, column.DataNavigateUrlField, "#2");
64 // what does this mean? shouldn't NavigateUrl be "bar" now?
65 Assert.AreEqual (foo, column.NavigateUrl, "#3");
68 public class MyColumn : HyperLinkColumn {
69 public string FormatUrl (object input)
71 return FormatDataNavigateUrlValue (input);
74 public string FormatText (object input)
76 return FormatDataTextValue (input);
79 public void InitCell (TableCell cell, int column_index, ListItemType item_type)
81 base.InitializeCell (cell, column_index, item_type);
86 public void FormatTest ()
88 MyColumn column = new MyColumn ();
89 column.DataNavigateUrlFormatString = "!{0}!";
90 Assert.AreEqual (String.Empty, column.FormatUrl (null), "#1");
91 Assert.AreEqual ("!foo!", column.FormatUrl ("foo"), "#2");
93 column.DataTextFormatString = "!{0}!";
94 Assert.AreEqual (String.Empty, column.FormatText (null), "#3");
95 Assert.AreEqual ("!foo!", column.FormatText ("foo"), "#4");
99 public void InitCellTest ()
104 /* test that for Header it just sets the cell.Text to HeaderText */
105 column = new MyColumn();
106 cell = new TableCell();
107 column.HeaderText = "This is a Header";
108 column.InitCell (cell, 0, ListItemType.Header);
110 Assert.AreEqual ("This is a Header", cell.Text, "#1");
112 /* test that for Item 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.Item);
119 Assert.AreEqual (1, cell.Controls.Count, "#2");
120 Assert.IsTrue (cell.Controls[0] is HyperLink, "#3");
122 /* test that for EditItem it adds a HyperLinkControl */
123 column = new MyColumn();
124 cell = new TableCell();
125 column.NavigateUrl = "http://www.novell.com/";
126 column.Text = "Novell.com";
127 column.InitCell (cell, 0, ListItemType.EditItem);
129 Assert.AreEqual (1, cell.Controls.Count, "#4");
130 Assert.IsTrue (cell.Controls[0] is HyperLink, "#5");
132 /* test that for AlternatingItem it adds a HyperLinkControl */
133 column = new MyColumn();
134 cell = new TableCell();
135 column.NavigateUrl = "http://www.novell.com/";
136 column.Text = "Novell.com";
137 column.InitCell (cell, 0, ListItemType.AlternatingItem);
139 Assert.AreEqual (1, cell.Controls.Count, "#6");
140 Assert.IsTrue (cell.Controls[0] is HyperLink, "#7");
142 /* test that for Footer it just sets the cell.Text to FooterText */
143 column = new MyColumn();
144 cell = new TableCell();
145 column.FooterText = "This is a Footer";
146 column.InitCell (cell, 0, ListItemType.Footer);
148 Assert.AreEqual ("This is a Footer", cell.Text, "#8");