[SRE] Improved token fixups processing.
[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
31 using System;
32 using System.Web;
33 using System.Web.UI;
34 using System.Web.UI.WebControls;
35 using System.Collections;
36 using System.ComponentModel;
37 using NUnit.Framework;
38
39
40 namespace MonoTests.System.Web.UI.WebControls
41 {
42         public class PokerDataSource : DataSourceControl
43         {
44                 // View state Stuff
45                 public PokerDataSource ()
46                         : base ()
47                 {
48                         TrackViewState ();
49                 }
50
51                 public ICollection  DoGetViewNames()
52                 {
53                          return base.GetViewNames();
54                 }
55                 
56                 public ControlCollection DoCreateControlCollection ()
57                 {
58                         return base.CreateControlCollection ();
59                 }
60                 public void DoRaiseDataSourceChangedEvent (EventArgs e)
61                 {
62                         base.RaiseDataSourceChangedEvent (e);
63                 }
64
65                 protected override DataSourceView GetView (string viewName)
66                 {
67                         throw new Exception ("The method or operation is not implemented.");
68                 }
69         }
70
71         [TestFixture]
72         public class DataSourceControlTest
73         {
74                 
75                 [Test]
76                 public void DataSourceControl_DefaultProperty ()
77                 {
78                         PokerDataSource ds = new PokerDataSource ();
79 #if NET_4_0
80                         Assert.AreEqual (String.Empty, ds.ClientID, "ClientID");
81 #else
82                         Assert.AreEqual (null, ds.ClientID, "ClientID");
83 #endif
84                         Assert.IsNotNull (ds.Controls, "Controls#1");
85                         Assert.AreEqual ( 0 , ds.Controls.Count , "Controls#2");
86                         Assert.AreEqual (false, ds.Visible, "Visible");
87                 }
88
89                 [Test]
90                 public void DataSourceControl_DefaultPropertyNotWorking ()
91                 {
92                         PokerDataSource ds = new PokerDataSource ();
93                         Assert.AreEqual (false, ds.EnableTheming, "EnableTheming");
94                 }
95
96                 [Test]
97                 public void DataSourceControl_ApplyStyleSheetSkin ()
98                 {
99                         // DataSourceControl EnableTheme property always set to false 
100                         // and have no render issue - this method would do nothing
101                 }
102
103                 [Test]
104                 public void DataSourceControl_FindControl ()
105                 {
106                         // DataSourceControl cannot have child controls on ControlCollection
107                         // this method cannot be applyed
108                 }
109
110                 [Test]
111                 [ExpectedException (typeof (NotSupportedException))]
112                 public void DataSourceControl_Focus ()
113                 {
114                         PokerDataSource ds = new PokerDataSource ();
115                         ds.Focus ();
116                 }
117
118                 [Test]
119                 public void DataSourceControl_HasControls ()
120                 {
121                         //Always return false
122                         PokerDataSource ds = new PokerDataSource ();
123                         Assert.AreEqual (false, ds.HasControls (), "HasControls");
124                 }
125
126                 [Test]
127                 public void DataSourceControl_CreateControlCollection ()
128                 {
129                         PokerDataSource ds = new PokerDataSource ();
130                         ControlCollection collection = ds.DoCreateControlCollection ();
131                         Assert.IsNotNull (collection, "CreateControlCollection#1");
132                         Assert.AreEqual (0, collection.Count ,"CreateControlCollection#2");
133                 }
134
135                 [Test]
136                 public void DataSourceControl_GetViewNames ()
137                 {
138                         PokerDataSource ds = new PokerDataSource ();
139                         ICollection viewnames = ds.DoGetViewNames ();
140                         Assert.IsNull (viewnames, "GetViewNames#1");
141                 }
142                 
143
144                 [Test]
145                 [ExpectedException (typeof (HttpException))]
146                 public void DataSourceControl_Controls ()
147                 {
148                         Button bt = new Button ();
149                         bt.ID = "bt";
150                         PokerDataSource ds = new PokerDataSource ();
151                         ds.Controls.Add (bt);
152                 }
153
154
155                 [Test]
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 }