2 // Tests for System.Web.UI.WebControls.FormView.cs
5 // Merav Sudri (meravs@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.
32 using NUnit.Framework;
34 using System.Threading;
36 using System.Data.Common;
39 using System.Collections;
40 using System.Globalization;
43 using System.Web.UI.WebControls;
44 using MonoTests.SystemWeb.Framework;
45 using MonoTests.stand_alone.WebHarness;
48 namespace MonoTests.System.Web.UI.WebControls
50 public class ObjectDataSourcePoker : ObjectDataSource
52 public ObjectDataSourcePoker () // constructor
58 public object SaveState ()
60 return SaveViewState ();
63 public void LoadState (object o)
69 public StateBag StateBag
71 get { return base.ViewState; }
74 public string Render ()
76 StringWriter sw = new StringWriter ();
77 HtmlTextWriter tw = new HtmlTextWriter (sw);
79 return sw.ToString ();
82 public void DoOnBubbleEvent (Object source, EventArgs e)
84 base.OnBubbleEvent (source, e);
87 public object DoSaveControlState ()
89 return base.SaveControlState ();
92 public void DoLoadControlState (object savedState)
94 base.LoadControlState (savedState);
100 public class ObjectDataSourceTest
110 [TestFixtureTearDown]
111 public void TearDown ()
116 public static void InitObjectDataSource (ObjectDataSourcePoker ds, string action)
118 Parameter p1, p2, p3;
121 case "insert": p1 = new Parameter ("ID", TypeCode.String, "1004");
122 p2 = new Parameter ("FName", TypeCode.String, "David");
123 p3 = new Parameter ("LName", TypeCode.String, "Eli");
126 case "update": p1 = new Parameter ("ID", TypeCode.String, "1001");
127 p2 = new Parameter ("FName", TypeCode.String, "David");
128 p3 = new Parameter ("LName", TypeCode.String, "Eli");
130 case "DBNull": p1 = new Parameter ("ID");
131 p2 = new Parameter ("FName");
132 p3 = new Parameter ("LName");
135 default: p1 = new Parameter ("ID", TypeCode.String, "1001");
136 p2 = new Parameter ("FName", TypeCode.String, "Mahesh");
137 p3 = new Parameter ("LName", TypeCode.String, "chand");
141 ds.SelectMethod = "GetMyData";
142 ds.DeleteMethod = "Delete";
143 ds.InsertMethod = "Insert";
144 ds.UpdateMethod = "Update";
145 ds.SelectCountMethod = "SelectCount";
146 ds.DeleteParameters.Add (p1);
147 ds.DeleteParameters.Add (p2);
148 ds.DeleteParameters.Add (p3);
149 ds.InsertParameters.Add (p1);
150 ds.InsertParameters.Add (p2);
151 ds.InsertParameters.Add (p3);
152 ds.UpdateParameters.Add (p1);
153 ds.UpdateParameters.Add (p2);
154 ds.UpdateParameters.Add (p3);
156 ds.TypeName = "MonoTests.System.Web.UI.WebControls.MyTableObject";
162 public void ObjectDataSource_DefaultProperties ()
164 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
166 Assert.AreEqual (ConflictOptions.OverwriteChanges, ods.ConflictDetection, "ConflictDetection");
167 Assert.AreEqual ("",ods.DataObjectTypeName ,"DataObjectTypeName ");
168 Assert.AreEqual ("", ods.DeleteMethod, "DeleteMethod");
169 Assert.AreEqual (typeof(ParameterCollection),ods.DeleteParameters.GetType (),"DeleteParameters");
170 Assert.AreEqual (false, ods.EnablePaging, "EnablePaging ");
171 Assert.AreEqual ("", ods.FilterExpression, "FilterExpression ");
172 Assert.AreEqual (typeof (ParameterCollection), ods.FilterParameters.GetType (), "FilterParameters");
173 Assert.AreEqual ("", ods.InsertMethod, "InsertMethod ");
174 Assert.AreEqual (typeof (ParameterCollection), ods.InsertParameters.GetType (), "InsertParameters ");
175 Assert.AreEqual ("maximumRows", ods.MaximumRowsParameterName, "MaximumRowsParameterName");
176 Assert.AreEqual ("{0}", ods.OldValuesParameterFormatString, "OldValuesParameterFormatString");
177 Assert.AreEqual ("", ods.SelectCountMethod, "SelectCountMethod");
178 Assert.AreEqual ("", ods.SelectMethod, "SelectMethod ");
179 Assert.AreEqual (typeof (ParameterCollection), ods.SelectParameters.GetType (), "SelectParameters");
180 Assert.AreEqual ("", ods.SortParameterName, "SortParameterName");
181 Assert.AreEqual ("startRowIndex", ods.StartRowIndexParameterName, "StartRowIndexParameterName");
182 Assert.AreEqual ("", ods.TypeName, "TypeName");
183 Assert.AreEqual ("", ods.UpdateMethod, "UpdateMethod ");
184 Assert.AreEqual (typeof (ParameterCollection), ods.UpdateParameters.GetType (), "UpdateParameters");
189 [Category ("NotWorking")]
190 public void ObjectDataSource_NotWorkingDefaultProperties ()
192 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
193 Assert.AreEqual (0, ods.CacheDuration, "CacheDuration");
194 Assert.AreEqual (DataSourceCacheExpiry.Absolute, ods.CacheExpirationPolicy, "CacheExpirationPolicy");
195 Assert.AreEqual ("", ods.CacheKeyDependency, "CacheKeyDependency");
196 Assert.AreEqual (false, ods.ConvertNullToDBNull, "ConvertNullToDBNull ");
197 Assert.AreEqual (false, ods.EnableCaching, "EnableCaching ");
198 Assert.AreEqual ("", ods.SqlCacheDependency, "SqlCacheDependency");
201 //Non default properties values
204 public void ObjectDataSource_AssignToDefaultProperties ()
206 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
207 InitObjectDataSource (ods,"");
208 ods.ConflictDetection = ConflictOptions.CompareAllValues;
209 Assert.AreEqual (ConflictOptions.CompareAllValues, ods.ConflictDetection, "ConflictDetection");
210 ods.DataObjectTypeName = "MyData";
211 Assert.AreEqual ("MyData", ods.DataObjectTypeName, "DataObjectTypeName ");
212 Assert.AreEqual ("Delete", ods.DeleteMethod, "DeleteMethod");
213 Assert.AreEqual (3, ods.DeleteParameters.Count, "DeleteParameters");
214 ods.EnablePaging = true;
215 Assert.AreEqual (true, ods.EnablePaging, "EnablePaging ");
216 ods.FilterExpression = "ID='{0}'";
217 Assert.AreEqual ("ID='{0}'", ods.FilterExpression, "FilterExpression ");
218 TextBox TextBox1=new TextBox ();
219 TextBox1.Text ="1001";
220 FormParameter p=new FormParameter ("ID","TextBox1");
221 p.DefaultValue = "1002";
222 ods.FilterParameters.Add (p);
223 Assert.AreEqual ("ID", ods.FilterParameters[0].Name, "FilterParameters1");
224 Assert.AreEqual ("1002", ods.FilterParameters[0].DefaultValue , "FilterParameters2");
225 Assert.AreEqual ("TextBox1", ((FormParameter )ods.FilterParameters[0]).FormField, "FilterParameters3");
226 Assert.AreEqual ("Insert", ods.InsertMethod, "InsertMethod ");
227 Assert.AreEqual ("ID", ods.InsertParameters[0].Name , "InsertParameters ");
228 ods.MaximumRowsParameterName = "SelectCount";
229 Assert.AreEqual ("SelectCount", ods.MaximumRowsParameterName, "MaximumRowsParameterName");
230 ods.OldValuesParameterFormatString = "ID";
231 Assert.AreEqual ("ID", ods.OldValuesParameterFormatString, "OldValuesParameterFormatString");
232 Assert.AreEqual ("SelectCount", ods.SelectCountMethod, "SelectCountMethod");
233 Assert.AreEqual ("GetMyData", ods.SelectMethod, "SelectMethod ");
234 Parameter dummy = new Parameter ();
236 ods.SelectParameters.Add (dummy);
237 Assert.AreEqual ("Test", ods.SelectParameters[0].Name , "SelectParameters");
238 ods.SortParameterName = "sortExpression";
239 Assert.AreEqual ("sortExpression", ods.SortParameterName, "SortParameterName");
240 ods.StartRowIndexParameterName = "ID";
241 Assert.AreEqual ("ID", ods.StartRowIndexParameterName, "StartRowIndexParameterName");
242 Assert.AreEqual ("MonoTests.System.Web.UI.WebControls.MyTableObject", ods.TypeName, "TypeName");
243 Assert.AreEqual ("Update", ods.UpdateMethod, "UpdateMethod ");
244 Assert.AreEqual ("FName", ods.UpdateParameters[1].Name, "UpdateParameters");
249 [Category ("NotWorking")]
250 public void ObjectDataSource_NotWorkingAssignToDefaultProperties ()
252 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
253 ods.CacheDuration = 1000;
254 Assert.AreEqual (1000, ods.CacheDuration, "CacheDuration");
255 ods.CacheExpirationPolicy = DataSourceCacheExpiry.Sliding;
256 Assert.AreEqual (DataSourceCacheExpiry.Sliding, ods.CacheExpirationPolicy, "CacheExpirationPolicy");
257 ods.CacheKeyDependency = "ID";
258 Assert.AreEqual ("ID", ods.CacheKeyDependency, "CacheKeyDependency");
259 ods.ConvertNullToDBNull = true;
260 Assert.AreEqual (true, ods.ConvertNullToDBNull, "ConvertNullToDBNull ");
261 ods.EnableCaching = true;
262 Assert.AreEqual (true, ods.EnableCaching, "EnableCaching ");
263 ods.SqlCacheDependency = "Northwind:Employees";
264 Assert.AreEqual ("Northwind:Employees", ods.SqlCacheDependency, "SqlCacheDependency");
270 [Category ("NotWorking")]
271 public void ObjectDataSource_ViewState ()
273 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
274 InitObjectDataSource (ods,"");
275 ObjectDataSourcePoker copy = new ObjectDataSourcePoker ();
276 FormParameter p = new FormParameter ("ID", "TextBox1");
277 p.DefaultValue = "1002";
278 ods.FilterParameters.Add (p);
279 Parameter p1 = new Parameter ("ID", TypeCode.String, "1001");
280 Parameter p2 = new Parameter ("FName", TypeCode.String, "Mahesh");
281 ods.SelectParameters.Add (p1);
282 ods.SelectParameters.Add (p2);
283 object state = ods.SaveState ();
284 copy.LoadState (state);
285 Assert.AreEqual ("ID", copy.FilterParameters [0].Name, "ViewStateFilterParameters1");
286 Assert.AreEqual ("1002", copy.FilterParameters [0].DefaultValue, "ViewStateFilterParameters2");
287 Assert.AreEqual ("1001", copy.SelectParameters[0].DefaultValue, "ViewStateSelectParameters1");
288 Assert.AreEqual (2, copy.SelectParameters.Count , "ViewStateSelectParameters2");
291 //Properties functionality
293 public void ObjectDataSource_ConflictDetection ()
299 [Category ("NotWorking")]
300 [Category ("NunitWeb")]
301 public void ObjectDataSource_ConvertNullToDBNull ()
303 string html = new WebTest (PageInvoker.CreateOnLoad (
304 new PageDelegate (ConvertNullToDBNull))).Run ();
308 public static void ConvertNullToDBNull (Page p)
310 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
311 InitObjectDataSource (ods,"DBNull");
313 ods.ConvertNullToDBNull = true;
317 catch (Exception ex) {
318 Assert.AreEqual (true,ex.Message.Contains ("type 'System.DBNull' cannot be converted to type 'System.String'"), "ConvertNullToDBNull");
321 Assert.AreEqual (true, dbnull, "ConvertNullToDBNull2");
325 [Category ("NotWorking")]
326 [Category ("NunitWeb")]
327 public void ObjectDataSource_FilterExpression ()
329 string html = new WebTest (PageInvoker.CreateOnLoad (
330 new PageDelegate (FilterExpression))).Run ();
331 string newHtml= HtmlDiff.GetControlFromPageHtml (html);
332 string origHtml = @"<table cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"">
334 <td>ID</td><td>FName</td><td>LName</td>
336 <td>1002</td><td>Melanie</td><td>Talmadge</td>
339 HtmlDiff.AssertAreEqual (origHtml, newHtml, "FilterExpression");
343 public static void FilterExpression (Page p)
345 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
346 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
347 DataGrid dg = new DataGrid ();
348 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
349 InitObjectDataSource (ods, "");
350 ods.FilterExpression = "ID='1002'";
351 p.Controls.Add (lcb);
353 p.Controls.Add (ods);
354 p.Controls.Add (lce);
355 dg.DataSourceID = "MyObject";
361 [Category ("NotWorking")]
362 [Category ("NunitWeb")]
363 public void ObjectDataSource_FilterParameter ()
365 string html = new WebTest (PageInvoker.CreateOnLoad (
366 new PageDelegate (FilterParameter))).Run ();
367 string newHtml = HtmlDiff.GetControlFromPageHtml (html);
368 string origHtml = @"<table cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"">
370 <td>ID</td><td>FName</td><td>LName</td>
372 <td>1003</td><td>Vinay</td><td>Bansal</td>
375 HtmlDiff.AssertAreEqual (origHtml, newHtml, "FilterExpression");
379 public static void FilterParameter (Page p)
381 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
382 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
383 DataGrid dg = new DataGrid ();
384 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
385 InitObjectDataSource (ods, "");
386 ods.FilterExpression = "{0}";
387 Parameter p1 = new Parameter ("ID", TypeCode.String, "ID=1003");
388 ods.FilterParameters.Add (p1);
389 p.Controls.Add (lcb);
391 p.Controls.Add (ods);
392 p.Controls.Add (lce);
393 dg.DataSourceID = "MyObject";
400 [Category ("NotWorking")]
401 [Category ("NunitWeb")]
402 public void ObjectDataSource_EnablePaging ()
404 string html = new WebTest (PageInvoker.CreateOnLoad (
405 new PageDelegate (EnablePaging))).Run ();
406 string newHtml = HtmlDiff.GetControlFromPageHtml (html);
407 string origHtml = @"<div>
408 <table cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"">
410 <th scope=""col"">Name</th><th scope=""col"">Number</th>
412 <td>Number0</td><td>0</td>
414 <td>Number1</td><td>1</td>
416 <td>Number2</td><td>2</td>
418 <td>Number3</td><td>3</td>
420 <td>Number4</td><td>4</td>
422 <td colspan=""2""><table border=""0"">
424 <td><span>1</span></td><td><a href=""javascript:__doPostBack('ctl01','Page$2')"">2</a></td><td><a href=""javascript:__doPostBack('ctl01','Page$3')"">3</a></td><td><a href=""javascript:__doPostBack('ctl01','Page$4')"">4</a></td>
430 HtmlDiff.AssertAreEqual (origHtml, newHtml, "EnablePaging");
434 public static void EnablePaging (Page p)
436 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
437 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
438 GridView gv = new GridView ();
439 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
440 ods.ID = "ObjectDataSource1";
441 ods.TypeName = "MonoTests.System.Web.UI.WebControls.MyTableObject";
442 ods.SelectMethod = "SelectForPaging";
443 ods.EnablePaging = true;
444 ods.SelectCountMethod = "SelectCount";
445 ods.MaximumRowsParameterName = "maxRows";
446 ods.StartRowIndexParameterName = "startIndex";
447 gv.AllowPaging = true;
449 p.Controls.Add (lcb);
451 p.Controls.Add (ods);
452 p.Controls.Add (lce);
453 gv.DataSourceID = "ObjectDataSource1";
461 [Category ("NotWorking")]
462 [Category ("NunitWeb")]
463 public void ObjectDataSource_Delete ()
465 string html = new WebTest (PageInvoker.CreateOnLoad (
466 new PageDelegate (DeleteMethod))).Run ();
467 string newHtml = HtmlDiff.GetControlFromPageHtml (html);
468 string origHtml = @"<div>
469 <table cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"">
471 <td>ID</td><td>1002</td>
473 <td>FName</td><td>Melanie</td>
475 <td>LName</td><td>Talmadge</td>
479 HtmlDiff.AssertAreEqual (origHtml, newHtml, "DeleteRender");
483 public static void DeleteMethod (Page p)
485 LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
486 LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
487 MyTableObject.ds = MyTableObject.CreateDataTable ();
488 DetailsView dv = new DetailsView ();
489 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
490 ods.Deleted += new ObjectDataSourceStatusEventHandler (odc_Deleted);
491 ods.Deleting += new ObjectDataSourceMethodEventHandler (odc_Deleting);
492 InitObjectDataSource (ods,"");
495 dv.DataKeyNames = new string[] { "ID" };
497 p.Controls.Add (lcb);
498 p.Controls.Add (ods);
500 p.Controls.Add (lce);
502 Assert.AreEqual (3, dv.DataItemCount, "BeforeDelete1");
503 Assert.AreEqual (1001, dv.SelectedValue, "BeforeDelete2");
504 Assert.AreEqual (false, deleting, "BeforeDeletingEvent");
505 Assert.AreEqual (false, deleted, "BeforeDeletedEvent");
508 Assert.AreEqual (true, deleting, "AfterDeletingEvent");
509 Assert.AreEqual (true, deleted, "AfterDeletedEvent");
510 Assert.AreEqual (2, dv.DataItemCount, "BeforeDelete1");
511 Assert.AreEqual (1002, dv.SelectedValue, "BeforeDelete2");
515 [Category ("NotWorking")]
516 [Category ("NunitWeb")]
517 public void ObjectDataSource_Select ()
519 string html = new WebTest (PageInvoker.CreateOnLoad (
520 new PageDelegate (SelectMethod))).Run ();
524 public static void SelectMethod (Page p)
526 MyTableObject.ds = MyTableObject.CreateDataTable ();
527 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
528 InitObjectDataSource (ods,"");
529 ods.Selected += new ObjectDataSourceStatusEventHandler (odc_Selected);
530 ods.Selecting += new ObjectDataSourceSelectingEventHandler (odc_Selecting);
531 p.Controls.Add (ods);
532 Assert.AreEqual (false, selecting, "BeforeSelectingEvent");
533 Assert.AreEqual (false, selected, "BeforeSelectedEvent");
534 IEnumerable table = (IEnumerable) ods.Select ();
535 Assert.AreEqual (3,((DataView) table).Count, "ItemsCount");
536 Assert.AreEqual ("Mahesh", ((DataView) table)[0].Row.ItemArray[1], "FirstItemData");
537 Assert.AreEqual (1002, ((DataView) table)[1].Row.ItemArray[0], "SecondItemData");
538 Assert.AreEqual ("Bansal", ((DataView) table)[2].Row.ItemArray[2], "ThirdItemData");
539 Assert.AreEqual (true, selecting, "AfterSelectingEvent");
540 Assert.AreEqual (true, selected, "AfterSelectedEvent");
544 [Category ("NotWorking")]
545 [Category ("NunitWeb")]
546 public void ObjectDataSource_Insert ()
548 string html = new WebTest (PageInvoker.CreateOnLoad (
549 new PageDelegate (InsertMethod))).Run ();
552 public static void InsertMethod (Page p)
554 MyTableObject.ds = MyTableObject.CreateDataTable ();
555 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
556 InitObjectDataSource (ods,"insert");
557 ods.Inserted += new ObjectDataSourceStatusEventHandler (odc_Inserted);
558 ods.Inserting += new ObjectDataSourceMethodEventHandler (odc_Inserting);
559 p.Controls.Add (ods);
560 Assert.AreEqual (3, ((DataView) ods.Select ()).Count, "BeforeInsert");
561 Assert.AreEqual (false, inserted , "BeforeInsertedEvent");
562 Assert.AreEqual (false, inserting , "BeforeInsertingEvent");
564 Assert.AreEqual (4, ((DataView) ods.Select ()).Count , "AfterInsert1");
565 Assert.AreEqual (1004,((DataView) ods.Select ())[3].Row.ItemArray[0], "AfterInsert2");
566 Assert.AreEqual ("David", ((DataView) ods.Select ())[3].Row.ItemArray[1], "AfterInsert3");
567 Assert.AreEqual (true, inserted, "AfterInsertedEvent");
568 Assert.AreEqual (true, inserting, "AfterInsertingEvent");
573 [Category ("NotWorking")]
574 [Category ("NunitWeb")]
575 public void ObjectDataSource_Update ()
577 string html = new WebTest (PageInvoker.CreateOnLoad (
578 new PageDelegate (UpdateMethod))).Run ();
581 public static void UpdateMethod (Page p)
583 MyTableObject.ds = MyTableObject.CreateDataTable ();
584 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
585 InitObjectDataSource (ods, "update");
586 ods.Updated += new ObjectDataSourceStatusEventHandler (odc_Updated);
587 ods.Updating += new ObjectDataSourceMethodEventHandler (odc_Updating);
588 p.Controls.Add (ods);
589 Assert.AreEqual (3, ((DataView) ods.Select ()).Count, "BeforeUpdate1");
590 Assert.AreEqual (1001, ((DataView) ods.Select ())[0].Row.ItemArray[0], "BeforeUpdate2");
591 Assert.AreEqual ("Mahesh", ((DataView) ods.Select ())[0].Row.ItemArray[1], "BeforeUpdate3");
592 Assert.AreEqual ("Chand", ((DataView) ods.Select ())[0].Row.ItemArray[2], "BeforeUpdate4");
593 Assert.AreEqual (false, updated, "BeforeUpdateEvent");
594 Assert.AreEqual (false, updating, "BeforeUpdatingEvent");
596 Assert.AreEqual (3, ((DataView) ods.Select ()).Count, "AfterUpdate1");
597 Assert.AreEqual (1001, ((DataView) ods.Select ())[0].Row.ItemArray[0], "AfterUpdate2");
598 Assert.AreEqual ("David", ((DataView) ods.Select ())[0].Row.ItemArray[1], "AfterUpdate3");
599 Assert.AreEqual ("Eli", ((DataView) ods.Select ())[0].Row.ItemArray[2], "AfterUpdate4");
600 Assert.AreEqual (true, updated, "AfterUpdateEvent");
601 Assert.AreEqual (true, updating, "AfterUpdatingEvent");
608 private static bool deleted = false;
609 private static bool deleting = false;
610 private static bool filtering = false;
611 private static bool inserted = false;
612 private static bool inserting = false;
613 private static bool objectCreated = false;
614 private static bool objectCreating = false;
615 private static bool objectDisposing = false;
616 private static bool selected = false;
617 private static bool selecting = false;
618 private static bool updated = false;
619 private static bool updating = false;
621 // Tests for events Select,Update,Delete and Insert include in Select,Update,Delete and Insert methods tests.
624 [Category ("NotWorking")]
625 [Category ("NunitWeb")]
626 public void ObjectDataSource_Events ()
628 string html = new WebTest (PageInvoker.CreateOnLoad (
629 new PageDelegate (EventsTest))).Run ();
633 public static void EventsTest (Page p)
636 MyTableObject.ds = MyTableObject.CreateDataTable ();
637 DetailsView dv = new DetailsView ();
638 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
639 ods.ObjectCreated += new ObjectDataSourceObjectEventHandler (odc_ObjectCreated);
640 ods.ObjectCreating += new ObjectDataSourceObjectEventHandler (odc_ObjectCreating);
641 InitObjectDataSource (ods,"");
642 ods.FilterExpression = "ID='1001'";
645 dv.DataKeyNames = new string[] { "ID" };
647 p.Controls.Add (ods);
650 ods.Filtering += new ObjectDataSourceFilteringEventHandler (odc_Filtering);
651 Assert.AreEqual (false, filtering, "BeforeFilteringEvent");
653 Assert.AreEqual (true, filtering, "AfterFilteringEvent");
654 ods.ObjectDisposing += new ObjectDataSourceDisposingEventHandler (odc_ObjectDisposing);
655 //ToDo: Dispose, ObjectCreated and ObjectCreating should be tested.
659 static void odc_Updating (object sender, ObjectDataSourceMethodEventArgs e)
664 static void odc_Updated (object sender, ObjectDataSourceStatusEventArgs e)
669 static void odc_Selecting (object sender, ObjectDataSourceSelectingEventArgs e)
674 static void odc_Selected (object sender, ObjectDataSourceStatusEventArgs e)
679 static void odc_ObjectDisposing (object sender, ObjectDataSourceDisposingEventArgs e)
681 objectDisposing = true;
684 static void odc_ObjectCreating (object sender, ObjectDataSourceEventArgs e)
686 objectCreating = true;
689 static void odc_ObjectCreated (object sender, ObjectDataSourceEventArgs e)
691 objectCreated = true;
694 static void odc_Inserting (object sender, ObjectDataSourceMethodEventArgs e)
699 static void odc_Inserted (object sender, ObjectDataSourceStatusEventArgs e)
704 static void odc_Filtering (object sender, ObjectDataSourceFilteringEventArgs e)
709 static void odc_Deleting (object sender, ObjectDataSourceMethodEventArgs e)
714 static void odc_Deleted (object sender, ObjectDataSourceStatusEventArgs e)
722 [Category ("NotWorking")]
723 [ExpectedException (typeof (NotSupportedException))]
724 [Category ("NunitWeb")]
725 public void ObjectDataSource_EnableCachingException ()
727 string html = new WebTest (PageInvoker.CreateOnLoad (
728 new PageDelegate (EnableCachingException))).Run ();
732 public static void EnableCachingException (Page p)
734 MyTableObject.ds = MyTableObject.CreateDataTable ();
735 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
736 InitObjectDataSource (ods, "");
737 ods.SelectMethod = "SelectException";
738 ods.EnableCaching = true;
739 p.Controls.Add (ods);
740 IEnumerable table = (IEnumerable) ods.Select ();
745 [Category ("NotWorking")]
746 [ExpectedException (typeof (NotSupportedException))]
747 [Category ("NunitWeb")]
748 public void ObjectDataSource_FilterExpressionException ()
750 string html = new WebTest (PageInvoker.CreateOnLoad (
751 new PageDelegate (FilterExpressionException))).Run ();
755 public static void FilterExpressionException (Page p)
757 MyTableObject.ds = MyTableObject.CreateDataTable ();
758 ObjectDataSourcePoker ods = new ObjectDataSourcePoker ();
759 InitObjectDataSource (ods, "");
760 ods.SelectMethod = "SelectException";
761 ods.FilterExpression = "ID='1001'";
762 p.Controls.Add (ods);
763 IEnumerable table = (IEnumerable) ods.Select ();
768 public class MyTableObject
770 public static DataTable ds = CreateDataTable ();
771 public static DataTable GetMyData ()
776 public static DbDataReader SelectException ()
778 return new DataTableReader (new DataTable ());
781 public static int SelectCount ()
787 public static DataTable Delete (string ID, string FName, string LName)
789 DataRow dr = ds.Rows.Find (ID);
795 public static DataTable Update (string ID, string FName, string LName)
797 DataRow dr = ds.Rows.Find (ID);
799 Label lbl = new Label ();
800 lbl.Text = "ID doesn't exist. update only FName and LName";
809 public static DataTable Insert (string ID, string FName, string LName)
811 DataRow dr = ds.NewRow ();
820 public static DataTable CreateDataTable ()
823 DataTable aTable = new DataTable ("A");
827 // Create ID column and add to the DataTable.
829 dtCol = new DataColumn ();
830 dtCol.DataType = Type.GetType ("System.Int32");
831 dtCol.ColumnName = "ID";
832 dtCol.AutoIncrement = true;
833 dtCol.Caption = "ID";
834 dtCol.ReadOnly = true;
837 // Add the column to the DataColumnCollection.
839 aTable.Columns.Add (dtCol);
841 // Create Name column and add to the table
843 dtCol = new DataColumn ();
844 dtCol.DataType = Type.GetType ("System.String");
845 dtCol.ColumnName = "FName";
846 dtCol.AutoIncrement = false;
847 dtCol.Caption = "First Name";
848 dtCol.ReadOnly = false;
849 dtCol.Unique = false;
850 aTable.Columns.Add (dtCol);
853 // Create Last Name column and add to the table.
855 dtCol = new DataColumn ();
856 dtCol.DataType = Type.GetType ("System.String");
857 dtCol.ColumnName = "LName";
858 dtCol.AutoIncrement = false;
859 dtCol.Caption = "Last Name";
860 dtCol.ReadOnly = false;
861 dtCol.Unique = false;
862 aTable.Columns.Add (dtCol);
865 // Create three rows to the table
866 dtRow = aTable.NewRow ();
868 dtRow["FName"] = "Mahesh";
869 dtRow["LName"] = "Chand";
870 aTable.Rows.Add (dtRow);
873 dtRow = aTable.NewRow ();
875 dtRow["FName"] = "Melanie";
876 dtRow["LName"] = "Talmadge";
877 aTable.Rows.Add (dtRow);
879 dtRow = aTable.NewRow ();
881 dtRow["FName"] = "Vinay";
882 dtRow["LName"] = "Bansal";
883 aTable.Rows.Add (dtRow);
885 aTable.PrimaryKey = new DataColumn[] { aTable.Columns["ID"] };
890 public static DataTable SelectForPaging (int startIndex, int maxRows)
892 DataTable table = new DataTable ();
893 table.Columns.Add ("Name", typeof (string));
894 table.Columns.Add ("Number", typeof (int));
896 for (int i = 0; i < maxRows; i++) {
897 current = i + startIndex;
898 table.Rows.Add (new object[] { "Number" + current.ToString (), current });