2007-02-04 yonik <yonik@mainsoft.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / FormViewRowTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.FormView.cs 
3 //
4 // Author:
5 //      Merav Sudri (meravs@mainsoft.com)
6 //
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if NET_2_0
31
32 using NUnit.Framework;
33 using System;
34 using System.IO;
35 using System.Drawing;
36 using System.Collections;
37 using System.Globalization;
38 using System.Web;
39 using System.Web.UI;
40 using System.Web.UI.WebControls;
41 using MonoTests.SystemWeb.Framework;
42 using MonoTests.stand_alone.WebHarness;
43
44
45 namespace MonoTests.System.Web.UI.WebControls
46 {
47         [TestFixture]   
48         public class FormViewRowTest {  
49
50                 public class PokerFormViewRow : FormViewRow {
51                         
52                         
53                         public PokerFormViewRow (int itemIndex,DataControlRowType rowType,DataControlRowState rowState) : base(itemIndex,rowType,rowState)
54                         {                               
55                         TrackViewState ();
56                         }
57
58                         public object SaveState ()
59                         {
60                         return SaveViewState ();
61                         }
62
63                         public void LoadState (object o)
64                         {
65                         LoadViewState (o);
66                         }
67
68                         public StateBag StateBag 
69                         {
70                            get { return base.ViewState; }
71                         }
72
73                         public void DoOnBubbleEvent (Object sender, EventArgs e)
74                         {
75                                 OnBubbleEvent(sender,e);
76                         }
77
78                         public string Render ()
79                         {
80                                 StringWriter sw = new StringWriter ();
81                                 HtmlTextWriter tw = new HtmlTextWriter (sw);
82                                 Render (tw);
83                                 return sw.ToString ();
84                         }
85                 
86         }
87
88
89                 [Test]
90                 public void FormViewRow_Properties ()
91                 {
92                         PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.DataRow, DataControlRowState.Edit);
93                         Assert.AreEqual (2, row.ItemIndex, "ItemIndex");
94                         Assert.AreEqual (DataControlRowType.DataRow, row.RowType, "RowType");
95                         Assert.AreEqual (DataControlRowState.Edit, row.RowState, "RowState");
96                 }
97
98
99                 private bool dataDeleting=false;
100                 private bool dataInserting = false;
101                 private bool dataUpdating = false;
102                 
103                 [Test]
104                 public void FormViewRow_BubbleEvent ()
105                 {
106                         FormView fv = new FormView ();
107                         PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.Footer, DataControlRowState.Insert);
108                         Button bt=new Button ();
109                         fv.Controls.Add (row);                  
110                         CommandEventArgs com=new CommandEventArgs (new CommandEventArgs ("Delete",null));
111                         fv.ItemDeleting += new FormViewDeleteEventHandler (R_DataBinding);
112                         Assert.AreEqual (false, dataDeleting, "BeforeBubbleEvent");
113                         row.DoOnBubbleEvent (row,com);
114                         Assert.AreEqual (true, dataDeleting, "AfterBubbleEvent");
115                         fv.ChangeMode (FormViewMode.Insert); 
116                         com = new CommandEventArgs (new CommandEventArgs ("Insert", null));
117                         fv.ItemInserting += new FormViewInsertEventHandler (dv_ItemInserting);
118                         Assert.AreEqual (false, dataInserting, "BeforeInsertBubbleEvent");
119                         row.DoOnBubbleEvent (row, com);
120                         Assert.AreEqual (true, dataInserting, "AfterInsertBubbleEvent");
121                         fv.ChangeMode (FormViewMode.Edit);
122                         com = new CommandEventArgs (new CommandEventArgs ("Update", null));
123                         fv.ItemUpdating += new FormViewUpdateEventHandler (dv_ItemUpdating);
124                         Assert.AreEqual (false, dataUpdating, "BeforeUpdateBubbleEvent");
125                         row.DoOnBubbleEvent (row, com);
126                         Assert.AreEqual (true, dataUpdating, "AfterUpdateBubbleEvent");
127                         fv.ItemUpdating += new FormViewUpdateEventHandler (dv_ItemUpdating);
128
129   
130                 }
131
132                 void dv_ItemUpdating (object sender, FormViewUpdateEventArgs e)
133                 {
134                         dataUpdating = true;
135                 }
136
137                 void dv_ItemInserting (object sender, FormViewInsertEventArgs e)
138                 {
139                         dataInserting = true;
140                 }
141
142                 public void R_DataBinding (object sender, EventArgs e)
143                 {
144                         dataDeleting = true;
145                 }
146
147                 //ViewState
148                 [Test]
149                 public void FormViewRow_ViewState ()
150                 {
151                         PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.Header, DataControlRowState.Selected);
152                         PokerFormViewRow copy = new PokerFormViewRow (3, DataControlRowType.Pager, DataControlRowState.Insert);
153                         row.CssClass = "style.css";
154                         row.BackColor = Color.Red;
155                         object state = row.SaveState ();
156                         copy.LoadState (state);
157                         Assert.AreEqual ("style.css", copy.CssClass, "ViewStateCssClass");
158                         Assert.AreEqual (Color.Red, copy.BackColor, "ViewStateHeaderText");
159                 }
160
161                 [Test]
162                 public void FormView_render ()
163                 {
164                         PokerFormViewRow row = new PokerFormViewRow (2, DataControlRowType.Header, DataControlRowState.Selected);
165                         row.ID = "TestingRow";
166                         row.BackColor = Color.Red;
167                         string originalHtml = @"<tr id=""TestingRow"" style=""background-color:Red;""></tr>";
168                         HtmlDiff.AssertAreEqual (row.Render (), originalHtml, "FormViewRowRender");
169
170                 }
171                 
172         }
173 }
174
175 #endif