NunitWeb test framework major API refactoring; downport to net 1.1
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / FormViewTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.FormView.cs 
3 //
4 // Author:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using NUnit.Framework;
33 using System;
34 using System.IO;
35 using System.Collections;
36 using System.Globalization;
37 using System.Web;
38 using System.Web.UI;
39 using System.Web.UI.WebControls;
40 using MonoTests.SystemWeb.Framework;
41 using System.Text.RegularExpressions;
42 using System.Reflection;
43 using System.Threading;
44
45 namespace MonoTests.System.Web.UI.WebControls
46 {
47         [TestFixture]   
48         public class FormViewTest {     
49                 class Poker : FormView {
50                         public Poker () {
51                                 TrackViewState ();
52                         }
53
54                         public object SaveState () {
55                                 return SaveViewState ();
56                         }
57
58                         public void LoadState (object state) {
59                                 LoadViewState (state);
60                         }
61                         
62                         public void DoConfirmInitState ()
63                         {
64                                 base.ConfirmInitState ();
65                         }
66         
67                         public void DoOnPreRender (EventArgs e)
68                         {
69                                 base.OnPreRender (e);
70                         }
71                 }
72                 
73                 [Test]
74                 public void Defaults ()
75                 {
76                         Poker p = new Poker ();
77
78                         Assert.IsFalse (p.AllowPaging, "A1");
79                         Assert.AreEqual ("", p.BackImageUrl, "A2");
80                         Assert.IsNull (p.BottomPagerRow, "A3");
81                         Assert.AreEqual ("", p.Caption, "A4");
82                         Assert.AreEqual (TableCaptionAlign.NotSet, p.CaptionAlign ,"A5");
83                         Assert.AreEqual (-1, p.CellPadding, "A6");
84                         Assert.AreEqual (0, p.CellSpacing, "A7");
85                         Assert.AreEqual (FormViewMode.ReadOnly, p.CurrentMode, "A8");
86                         Assert.AreEqual (FormViewMode.ReadOnly, p.DefaultMode, "A9");
87                         Assert.IsNotNull (p.DataKeyNames, "A10");
88                         Assert.AreEqual (0, p.DataKeyNames.Length, "A10.1");
89                         Assert.IsNotNull (p.DataKey, "A11");
90                         Assert.AreEqual (0, p.DataKey.Values.Count, "A11.1");
91                         Assert.IsNull (p.EditItemTemplate, "A12");
92                         Assert.IsNotNull (p.EditRowStyle, "A13");
93
94                         Assert.IsNotNull (p.EmptyDataRowStyle, "A14");
95
96                         Assert.IsNull (p.EmptyDataTemplate, "A15");
97                         Assert.AreEqual ("", p.EmptyDataText, "A16");
98                         Assert.IsNull (p.FooterRow, "A17");
99                         Assert.IsNull (p.FooterTemplate, "A18");
100                         Assert.AreEqual ("", p.FooterText, "A19");
101                         Assert.IsNotNull (p.FooterStyle, "A20");
102
103                         Assert.AreEqual (GridLines.None, p.GridLines, "A21");
104                         Assert.IsNull (p.HeaderRow, "A22");
105                         Assert.IsNotNull (p.HeaderStyle, "A23");
106
107                         Assert.IsNull (p.HeaderTemplate, "A24");
108                         Assert.AreEqual ("", p.HeaderText, "A25");
109                         Assert.AreEqual (HorizontalAlign.NotSet, p.HorizontalAlign, "A26");
110                         Assert.IsNull (p.InsertItemTemplate, "A27");
111                         Assert.IsNotNull (p.InsertRowStyle, "A28");
112
113                         Assert.IsNull (p.ItemTemplate, "A29");
114                         Assert.AreEqual (0, p.PageCount, "A30");
115                         Assert.AreEqual (0, p.PageIndex, "A31");
116                         Assert.IsNull (p.PagerTemplate, "A32");
117                         Assert.IsNull (p.Row, "A33");
118                         Assert.IsNotNull (p.RowStyle, "A34");
119
120                         Assert.IsNull (p.SelectedValue, "A35");
121                         Assert.IsNull (p.TopPagerRow, "A36");
122                         Assert.IsNull (p.DataItem, "A37");
123                         Assert.AreEqual (0, p.DataItemCount, "A38");
124                         Assert.AreEqual (0, p.DataItemIndex, "A39");
125                 }
126                 
127                 [Test]
128                 public void PageIndex ()
129                 {
130                         ObjectDataSource ds = new ObjectDataSource ();
131                         ds.ID = "ObjectDataSource1";
132                         ds.TypeName = "System.Guid";
133                         ds.SelectMethod = "ToByteArray";
134                         Page p = new Page ();
135                         Poker f = new Poker ();
136                         f.Page = p;
137                         ds.Page = p;
138                         p.Controls.Add (f);
139                         p.Controls.Add (ds);
140                         f.DataSourceID = "ObjectDataSource1";
141                         f.DoConfirmInitState ();
142                         f.DoOnPreRender (EventArgs.Empty);
143                         object cur = f.DataItem;
144                         f.PageIndex = 1;
145                         Assert.IsTrue (cur != f.DataItem, "#01");
146                 }
147                 
148                 [Test]
149                 public void PageCount ()
150                 {
151                         ObjectDataSource ds = new ObjectDataSource ();
152                         ds.ID = "ObjectDataSource1";
153                         ds.TypeName = "System.Guid";
154                         ds.SelectMethod = "ToByteArray";
155                         Page p = new Page ();
156                         Poker f = new Poker ();
157                         f.Page = p;
158                         ds.Page = p;
159                         p.Controls.Add (f);
160                         p.Controls.Add (ds);
161                         f.DataSourceID = "ObjectDataSource1";
162                         f.DoConfirmInitState ();
163                         f.DoOnPreRender (EventArgs.Empty);
164                         f.PageIndex = 1;
165                         Assert.AreEqual (16, f.PageCount, "#01");
166                 }
167                 
168                 [TestFixtureTearDown]
169                 public void TearDown ()
170                 {
171                         Thread.Sleep (100);
172                         WebTest.Unload ();
173                 }
174         
175                 //[TestFixtureStartUp]
176                 //public void StartUp ()
177                 //{
178                 //      WebTest.CopyResource (GetType (), "FormView.aspx", "FormView.aspx");
179                 //}
180
181                 [Test]
182                 [Category("NunitWeb")]
183                 public void FormViewCssClass ()
184                 {
185                         WebTest.CopyResource (GetType (), "FormView.aspx", "FormView.aspx");
186                         string res = new WebTest ("FormView.aspx").Run ();
187                         Assert.IsTrue (Regex.IsMatch (
188                                 res, ".*<table[^>]*class=\"[^\"]*test1[^\"]*\"[^>]*>.*",
189                                 RegexOptions.IgnoreCase|RegexOptions.Singleline),
190                                 "check that <table class=\"test1\"> is found. Actual: "+res);
191                         Assert.IsFalse (Regex.IsMatch (
192                                 res, ".*<table[^>]*class=\"\"[^>]*>.*",
193                                 RegexOptions.IgnoreCase|RegexOptions.Singleline),
194                                 "check that <table class=\"\"> is not found. Actual: "+res);
195                 }
196
197         }
198 }
199 #endif