2 // Tests for System.Web.UI.WebControls.FormView.cs
5 // Chris Toshok (toshok@ximian.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using NUnit.Framework;
35 using System.Collections;
36 using System.Globalization;
39 using System.Web.UI.WebControls;
40 using MonoTests.SystemWeb.Framework;
41 using System.Text.RegularExpressions;
42 using System.Reflection;
43 using System.Threading;
45 namespace MonoTests.System.Web.UI.WebControls
48 public class FormViewTest {
49 class Poker : FormView {
54 public object SaveState () {
55 return SaveViewState ();
58 public void LoadState (object state) {
59 LoadViewState (state);
62 public void DoConfirmInitState ()
64 base.ConfirmInitState ();
67 public void DoOnPreRender (EventArgs e)
74 public void Defaults ()
76 Poker p = new Poker ();
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");
94 Assert.IsNotNull (p.EmptyDataRowStyle, "A14");
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");
103 Assert.AreEqual (GridLines.None, p.GridLines, "A21");
104 Assert.IsNull (p.HeaderRow, "A22");
105 Assert.IsNotNull (p.HeaderStyle, "A23");
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");
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");
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");
128 public void PageIndex ()
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 ();
140 f.DataSourceID = "ObjectDataSource1";
141 f.DoConfirmInitState ();
142 f.DoOnPreRender (EventArgs.Empty);
143 object cur = f.DataItem;
145 Assert.IsTrue (cur != f.DataItem, "#01");
149 public void PageCount ()
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 ();
161 f.DataSourceID = "ObjectDataSource1";
162 f.DoConfirmInitState ();
163 f.DoOnPreRender (EventArgs.Empty);
165 Assert.AreEqual (16, f.PageCount, "#01");
168 [TestFixtureTearDown]
169 public void TearDown ()
175 //[TestFixtureStartUp]
176 //public void StartUp ()
178 // WebTest.CopyResource (GetType (), "FormView.aspx", "FormView.aspx");
182 [Category("NunitWeb")]
183 public void FormViewCssClass ()
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);