2006-11-22 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / HyperLinkColumnTest.cs
1 //
2 // HyperLinkColumnTest.cs
3 //
4 // Author: Duncan Mak (duncan@novell.com)
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
28 using NUnit.Framework;
29 using System;
30 using System.Collections;
31 using System.Diagnostics;
32 using System.Web.UI.WebControls;
33
34 namespace MonoTests.System.Web.UI.WebControls {
35
36         [TestFixture]
37         public class HyperLinkColumnTest {
38
39                 [Test]
40                 public void SetUpTest ()
41                 {
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");
49                 }
50
51                 [Test]
52                 public void DataNavigateUrlFieldTest ()
53                 {
54                         HyperLinkColumn column = new HyperLinkColumn ();
55                         string foo = "foo";
56                         string bar = "bar";
57
58                         column.NavigateUrl = foo;
59                         Assert.AreEqual (foo, column.NavigateUrl, "#1");
60
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"); 
66                 }
67
68                 public class MyColumn : HyperLinkColumn {
69                         public string FormatUrl (object input)
70                         {
71                                 return FormatDataNavigateUrlValue (input);
72                         }
73
74                         public string FormatText (object input)
75                         {
76                                 return FormatDataTextValue (input);
77                         }
78
79                         public void InitCell (TableCell cell, int column_index, ListItemType item_type)
80                         {
81                           base.InitializeCell (cell, column_index, item_type);
82                         }
83                 }
84
85                 [Test]
86                 public void FormatTest ()
87                 {
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");
92
93                         column.DataTextFormatString = "!{0}!";
94                         Assert.AreEqual (String.Empty, column.FormatText (null), "#3");
95                         Assert.AreEqual ("!foo!", column.FormatText ("foo"), "#4");
96                 }
97
98                 [Test]
99                 public void InitCellTest ()
100                 {
101                         MyColumn column;
102                         TableCell cell;
103
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);
109
110                         Assert.AreEqual ("This is a Header", cell.Text, "#1");
111
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);
118
119                         Assert.AreEqual (1, cell.Controls.Count, "#2");
120                         Assert.IsTrue (cell.Controls[0] is HyperLink, "#3");
121
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);
128
129                         Assert.AreEqual (1, cell.Controls.Count, "#4");
130                         Assert.IsTrue (cell.Controls[0] is HyperLink, "#5");
131
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);
138
139                         Assert.AreEqual (1, cell.Controls.Count, "#6");
140                         Assert.IsTrue (cell.Controls[0] is HyperLink, "#7");
141
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);
147
148                         Assert.AreEqual ("This is a Footer", cell.Text, "#8");
149                 }
150
151         }
152 }