merge r67228-r67235, r67237, r67251 and r67256-67259 to trunk (they are
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / DataSourceControlTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.DataSourceControlTest.cs
3 //
4 // Author:
5 //      Yoni Klein (yonik@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 System;
33 using System.Web;
34 using System.Web.UI;
35 using System.Web.UI.WebControls;
36 using System.Collections;
37 using System.ComponentModel;
38 using NUnit.Framework;
39
40
41 namespace MonoTests.System.Web.UI.WebControls
42 {
43         public class PokerDataSource : DataSourceControl
44         {
45                 // View state Stuff
46                 public PokerDataSource ()
47                         : base ()
48                 {
49                         TrackViewState ();
50                 }
51
52                 public ICollection  DoGetViewNames()
53                 {
54                          return base.GetViewNames();
55                 }
56                 
57                 public ControlCollection DoCreateControlCollection ()
58                 {
59                         return base.CreateControlCollection ();
60                 }
61                 public void DoRaiseDataSourceChangedEvent (EventArgs e)
62                 {
63                         base.RaiseDataSourceChangedEvent (e);
64                 }
65
66                 protected override DataSourceView GetView (string viewName)
67                 {
68                         throw new Exception ("The method or operation is not implemented.");
69                 }
70         }
71
72         [TestFixture]
73         public class DataSourceControlTest
74         {
75                 
76                 [Test]
77                 public void DataSourceControl_DefaultProperty ()
78                 {
79                         PokerDataSource ds = new PokerDataSource ();
80                         Assert.AreEqual (null, ds.ClientID, "ClientID");
81                         Assert.IsNotNull (ds.Controls, "Controls#1");
82                         Assert.AreEqual ( 0 , ds.Controls.Count , "Controls#2");
83                         Assert.AreEqual (false, ds.Visible, "Visible");
84                 }
85
86                 [Test]
87                 [NUnit.Framework.Category ("NotWorking")]
88                 public void DataSourceControl_DefaultPropertyNotWorking ()
89                 {
90                         PokerDataSource ds = new PokerDataSource ();
91                         Assert.AreEqual (false, ds.EnableTheming, "EnableTheming");
92                 }
93
94                 [Test]
95                 public void DataSourceControl_ApplyStyleSheetSkin ()
96                 {
97                         // DataSourceControl EnableTheme property always set to false 
98                         // and have no render issue - this method would do nothing
99                 }
100
101                 [Test]
102                 public void DataSourceControl_FindControl ()
103                 {
104                         // DataSourceControl cannot have child controls on ControlCollection
105                         // this method cannot be applyed
106                 }
107
108                 [Test]
109                 [NUnit.Framework.Category ("NotWorking")]
110                 [ExpectedException (typeof (NotSupportedException))]
111                 public void DataSourceControl_Focus ()
112                 {
113                         PokerDataSource ds = new PokerDataSource ();
114                         ds.Focus ();
115                 }
116
117                 [Test]
118                 public void DataSourceControl_HasControls ()
119                 {
120                         //Always return false
121                         PokerDataSource ds = new PokerDataSource ();
122                         Assert.AreEqual (false, ds.HasControls (), "HasControls");
123                 }
124
125                 [Test]
126                 public void DataSourceControl_CreateControlCollection ()
127                 {
128                         PokerDataSource ds = new PokerDataSource ();
129                         ControlCollection collection = ds.DoCreateControlCollection ();
130                         Assert.IsNotNull (collection, "CreateControlCollection#1");
131                         Assert.AreEqual (0, collection.Count ,"CreateControlCollection#2");
132                 }
133
134                 [Test]
135                 public void DataSourceControl_GetViewNames ()
136                 {
137                         PokerDataSource ds = new PokerDataSource ();
138                         ICollection viewnames = ds.DoGetViewNames ();
139                         Assert.IsNull (viewnames, "GetViewNames#1");
140                 }
141                 
142
143                 [Test]
144                 [ExpectedException (typeof (HttpException))]
145                 public void DataSourceControl_Controls ()
146                 {
147                         Button bt = new Button ();
148                         bt.ID = "bt";
149                         PokerDataSource ds = new PokerDataSource ();
150                         ds.Controls.Add (bt);
151                 }
152
153
154                 [Test]
155                 [NUnit.Framework.Category ("NotWorking")]
156                 [ExpectedException (typeof (NotSupportedException))]
157                 public void DataSourceControl_EnableThemingException ()
158                 {
159                         PokerDataSource ds = new PokerDataSource ();
160                         ds.EnableTheming = true;
161                 }
162
163                 [Test]
164                 [ExpectedException (typeof (NotSupportedException))]
165                 public void DataSourceControl_VisibleException ()
166                 {
167                         PokerDataSource ds = new PokerDataSource ();
168                         ds.Visible = true;
169                 }
170
171                 //Events
172                 [Test]
173                 public void DataSourceControl_Events ()
174                 {
175                         PokerDataSource ds = new PokerDataSource ();
176                         ((IDataSource) ds).DataSourceChanged += new EventHandler (Eventchecker);
177                         ds.DoRaiseDataSourceChangedEvent (new EventArgs ());
178                         Eventassert("RaiseDataSourceChangedEventFail");
179                 }
180                 
181                 
182                 // Helper for event checking
183                 private bool event_checker;
184
185                 private void Eventchecker (object o, EventArgs e)
186                 {
187                         event_checker = true;
188                 }
189
190                 private void Eventassert (string message)
191                 {
192                         Assert.IsTrue (event_checker, message);
193                         event_checker = false;
194                 }
195         }
196 }
197 #endif