2006-11-21 Igor Zelmanovich <igorz@mainsoft.com>
[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                 public void DataSourceControl_DefaultPropertyNotWorking ()
88                 {
89                         PokerDataSource ds = new PokerDataSource ();
90                         Assert.AreEqual (false, ds.EnableTheming, "EnableTheming");
91                 }
92
93                 [Test]
94                 public void DataSourceControl_ApplyStyleSheetSkin ()
95                 {
96                         // DataSourceControl EnableTheme property always set to false 
97                         // and have no render issue - this method would do nothing
98                 }
99
100                 [Test]
101                 public void DataSourceControl_FindControl ()
102                 {
103                         // DataSourceControl cannot have child controls on ControlCollection
104                         // this method cannot be applyed
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (NotSupportedException))]
109                 public void DataSourceControl_Focus ()
110                 {
111                         PokerDataSource ds = new PokerDataSource ();
112                         ds.Focus ();
113                 }
114
115                 [Test]
116                 public void DataSourceControl_HasControls ()
117                 {
118                         //Always return false
119                         PokerDataSource ds = new PokerDataSource ();
120                         Assert.AreEqual (false, ds.HasControls (), "HasControls");
121                 }
122
123                 [Test]
124                 public void DataSourceControl_CreateControlCollection ()
125                 {
126                         PokerDataSource ds = new PokerDataSource ();
127                         ControlCollection collection = ds.DoCreateControlCollection ();
128                         Assert.IsNotNull (collection, "CreateControlCollection#1");
129                         Assert.AreEqual (0, collection.Count ,"CreateControlCollection#2");
130                 }
131
132                 [Test]
133                 public void DataSourceControl_GetViewNames ()
134                 {
135                         PokerDataSource ds = new PokerDataSource ();
136                         ICollection viewnames = ds.DoGetViewNames ();
137                         Assert.IsNull (viewnames, "GetViewNames#1");
138                 }
139                 
140
141                 [Test]
142                 [ExpectedException (typeof (HttpException))]
143                 public void DataSourceControl_Controls ()
144                 {
145                         Button bt = new Button ();
146                         bt.ID = "bt";
147                         PokerDataSource ds = new PokerDataSource ();
148                         ds.Controls.Add (bt);
149                 }
150
151
152                 [Test]
153                 [ExpectedException (typeof (NotSupportedException))]
154                 public void DataSourceControl_EnableThemingException ()
155                 {
156                         PokerDataSource ds = new PokerDataSource ();
157                         ds.EnableTheming = true;
158                 }
159
160                 [Test]
161                 [ExpectedException (typeof (NotSupportedException))]
162                 public void DataSourceControl_VisibleException ()
163                 {
164                         PokerDataSource ds = new PokerDataSource ();
165                         ds.Visible = true;
166                 }
167
168                 //Events
169                 [Test]
170                 public void DataSourceControl_Events ()
171                 {
172                         PokerDataSource ds = new PokerDataSource ();
173                         ((IDataSource) ds).DataSourceChanged += new EventHandler (Eventchecker);
174                         ds.DoRaiseDataSourceChangedEvent (new EventArgs ());
175                         Eventassert("RaiseDataSourceChangedEventFail");
176                 }
177                 
178                 
179                 // Helper for event checking
180                 private bool event_checker;
181
182                 private void Eventchecker (object o, EventArgs e)
183                 {
184                         event_checker = true;
185                 }
186
187                 private void Eventassert (string message)
188                 {
189                         Assert.IsTrue (event_checker, message);
190                         event_checker = false;
191                 }
192         }
193 }
194 #endif