2 // Tests for System.Web.UI.WebControls.DataSourceControlTest.cs
5 // Yoni Klein (yonik@mainsoft.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
34 using System.Web.UI.WebControls;
35 using System.Collections;
36 using System.ComponentModel;
37 using NUnit.Framework;
40 namespace MonoTests.System.Web.UI.WebControls
42 public class PokerDataSource : DataSourceControl
45 public PokerDataSource ()
51 public ICollection DoGetViewNames()
53 return base.GetViewNames();
56 public ControlCollection DoCreateControlCollection ()
58 return base.CreateControlCollection ();
60 public void DoRaiseDataSourceChangedEvent (EventArgs e)
62 base.RaiseDataSourceChangedEvent (e);
65 protected override DataSourceView GetView (string viewName)
67 throw new Exception ("The method or operation is not implemented.");
72 public class DataSourceControlTest
76 public void DataSourceControl_DefaultProperty ()
78 PokerDataSource ds = new PokerDataSource ();
79 Assert.AreEqual (String.Empty, ds.ClientID, "ClientID");
80 Assert.IsNotNull (ds.Controls, "Controls#1");
81 Assert.AreEqual ( 0 , ds.Controls.Count , "Controls#2");
82 Assert.AreEqual (false, ds.Visible, "Visible");
86 public void DataSourceControl_DefaultPropertyNotWorking ()
88 PokerDataSource ds = new PokerDataSource ();
89 Assert.AreEqual (false, ds.EnableTheming, "EnableTheming");
93 public void DataSourceControl_ApplyStyleSheetSkin ()
95 // DataSourceControl EnableTheme property always set to false
96 // and have no render issue - this method would do nothing
100 public void DataSourceControl_FindControl ()
102 // DataSourceControl cannot have child controls on ControlCollection
103 // this method cannot be applyed
107 [ExpectedException (typeof (NotSupportedException))]
108 public void DataSourceControl_Focus ()
110 PokerDataSource ds = new PokerDataSource ();
115 public void DataSourceControl_HasControls ()
117 //Always return false
118 PokerDataSource ds = new PokerDataSource ();
119 Assert.AreEqual (false, ds.HasControls (), "HasControls");
123 public void DataSourceControl_CreateControlCollection ()
125 PokerDataSource ds = new PokerDataSource ();
126 ControlCollection collection = ds.DoCreateControlCollection ();
127 Assert.IsNotNull (collection, "CreateControlCollection#1");
128 Assert.AreEqual (0, collection.Count ,"CreateControlCollection#2");
132 public void DataSourceControl_GetViewNames ()
134 PokerDataSource ds = new PokerDataSource ();
135 ICollection viewnames = ds.DoGetViewNames ();
136 Assert.IsNull (viewnames, "GetViewNames#1");
141 [ExpectedException (typeof (HttpException))]
142 public void DataSourceControl_Controls ()
144 Button bt = new Button ();
146 PokerDataSource ds = new PokerDataSource ();
147 ds.Controls.Add (bt);
152 [ExpectedException (typeof (NotSupportedException))]
153 public void DataSourceControl_EnableThemingException ()
155 PokerDataSource ds = new PokerDataSource ();
156 ds.EnableTheming = true;
160 [ExpectedException (typeof (NotSupportedException))]
161 public void DataSourceControl_VisibleException ()
163 PokerDataSource ds = new PokerDataSource ();
169 public void DataSourceControl_Events ()
171 PokerDataSource ds = new PokerDataSource ();
172 ((IDataSource) ds).DataSourceChanged += new EventHandler (Eventchecker);
173 ds.DoRaiseDataSourceChangedEvent (new EventArgs ());
174 Eventassert("RaiseDataSourceChangedEventFail");
178 // Helper for event checking
179 private bool event_checker;
181 private void Eventchecker (object o, EventArgs e)
183 event_checker = true;
186 private void Eventassert (string message)
188 Assert.IsTrue (event_checker, message);
189 event_checker = false;