Browse Source

2007-06-20 yonik <[email protected]>
DropDownListTest.cs; FormViewTest.cs; DetailViewTest.cs; GridViewTest.cs;
Add new tests for DataSourceChanged event

svn path=/trunk/mcs/; revision=80311

Yoni Klain 18 years ago
parent
commit
697a47ba9f

+ 8 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,11 @@
+2007-06-20  yonik <[email protected]>
+
+     * DropDownListTest.cs;
+	 * FormViewTest.cs;	
+	 * DetailViewTest.cs;
+	 * GridViewTest.cs;    
+      Add new tests for DataSourceChanged event 
+
 2007-05-27 Igor Zelmanovich <[email protected]>
 
 	* ObjectDataSourceViewTest.cs:

+ 82 - 8
mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs

@@ -116,6 +116,26 @@ namespace MonoTests.System.Web.UI.WebControls
 			}
 		}
 
+		public class DS : ObjectDataSource
+		{
+			public static List<string> GetList ()
+			{
+				List<string> list = new List<string> ();
+				list.Add ("Norway");
+				list.Add ("Sweden");
+				list.Add ("France");
+				list.Add ("Italy");
+				list.Add ("Israel");
+				list.Add ("Russia");
+				return list;
+			}
+
+			public void DoRaiseDataSourceChangedEvent (EventArgs e)
+			{
+				RaiseDataSourceChangedEvent (e);
+			}
+		}
+
 		public class PokerDetailsView: DetailsView 
 		{
 			public bool ensureDataBound=false;
@@ -402,14 +422,14 @@ namespace MonoTests.System.Web.UI.WebControls
 			myds.Add ("Item6");
 
 #if VISUAL_STUDIO
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FooterTemplateTest.aspx",
-				"FooterTemplateTest.aspx");
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DetailsViewTemplates.aspx",
-				"DetailsViewTemplates.aspx");
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DetailsViewDataActions.aspx",
-				"DetailsViewDataActions.aspx");
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DetailsViewProperties1.aspx",
-				"DetailsViewProperties1.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FooterTemplateTest.aspx",
+                                "FooterTemplateTest.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DetailsViewTemplates.aspx",
+                                "DetailsViewTemplates.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DetailsViewDataActions.aspx",
+                                "DetailsViewDataActions.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DetailsViewProperties1.aspx",
+                                "DetailsViewProperties1.aspx");
 #else
 			WebTest.CopyResource (GetType (), "FooterTemplateTest.aspx", "FooterTemplateTest.aspx");
 			WebTest.CopyResource (GetType (), "DetailsViewTemplates.aspx", "DetailsViewTemplates.aspx");
@@ -2377,6 +2397,60 @@ namespace MonoTests.System.Web.UI.WebControls
 
 		}
 
+		[Test]
+		[Category ("NunitWeb")]
+		[Category ("NotWorking")]
+		public void DetailsView_DataSourceChangedEvent ()
+		{
+			WebTest t = new WebTest ();
+			PageDelegates pd = new PageDelegates ();
+			pd.Load = DetailsView_Init;
+			pd.PreRenderComplete = DetailsView_Load;
+			t.Invoker = new PageInvoker (pd);
+			t.Run ();
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+			fr.Controls["__EVENTTARGET"].Value = "";
+			fr.Controls["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+			t.Run ();
+			if (t.UserData == null)
+				Assert.Fail ("DataSourceChangedEvent#1");
+			Assert.AreEqual ("Data_rebounded", t.UserData.ToString (), "DataSourceChangedEvent#2");
+		}
+
+		#region DetailsView_DataSourceChangedEvent
+		public static void DetailsView_Init (Page p)
+		{
+			PokerDetailsView dv = new PokerDetailsView ();
+			DS data = new DS ();
+			p.Controls.Add (dv);
+			p.Controls.Add (data);
+			data.TypeName = typeof (DS).AssemblyQualifiedName;
+			data.SelectMethod = "GetList";
+			data.ID = "Data";
+			dv.DataBinding += new EventHandler (data_DataBinding);
+			dv.DataSourceID = "Data";
+		}
+
+		public static void DetailsView_Load (Page p)
+		{
+			if (p.IsPostBack) {
+				DS data = (DS) p.FindControl ("Data");
+				if (data == null)
+					Assert.Fail ("Data soource control not created#1");
+				data.DoRaiseDataSourceChangedEvent (new EventArgs ());
+			}
+		}
+
+		public static void data_DataBinding (object sender, EventArgs e)
+		{
+			if (((WebControl) sender).Page.IsPostBack)
+				WebTest.CurrentTest.UserData = "Data_rebounded";
+		}
+		#endregion
+
 		[Test]
 		public void DetailsView_Events ()
 		{

+ 82 - 2
mcs/class/System.Web/Test/System.Web.UI.WebControls/DropDownListTest.cs

@@ -28,7 +28,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using NUnit.Framework;
+
 using System;
 using System.Collections;
 using System.Drawing;
@@ -38,8 +38,12 @@ using System.Globalization;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
+using NUnit.Framework;
 using MonoTests.stand_alone.WebHarness;
-
+#if NET_2_0
+using System.Collections.Generic;
+using MonoTests.SystemWeb.Framework;
+#endif
 
 namespace MonoTests.System.Web.UI.WebControls
 {
@@ -168,6 +172,82 @@ namespace MonoTests.System.Web.UI.WebControls
 			return matches == a1.Length;
 		}
 
+
+#if NET_2_0
+		public class DS : ObjectDataSource
+		{
+			public static List<string> GetList ()
+			{
+				List<string> list = new List<string> ();
+				list.Add ("Norway");
+				list.Add ("Sweden");
+				list.Add ("France");
+				list.Add ("Italy");
+				list.Add ("Israel");
+				list.Add ("Russia");
+				return list;
+			}
+
+			public void DoRaiseDataSourceChangedEvent (EventArgs e)
+			{
+				RaiseDataSourceChangedEvent (e);
+			}
+		}
+
+		[Test]
+		[Category ("NunitWeb")]
+		[Category ("NotWorking")]
+		public void DropDownList_DataSourceChangedEvent ()
+		{
+			WebTest t = new WebTest ();
+			PageDelegates pd = new PageDelegates ();
+			pd.Load = DropDownList_Init;
+			pd.PreRenderComplete = DropDownList_Load;
+			t.Invoker = new PageInvoker (pd);
+			t.Run ();
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+			fr.Controls["__EVENTTARGET"].Value = "";
+			fr.Controls["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+			t.Run ();
+			if (t.UserData == null)
+				Assert.Fail ("DataSourceChangedEvent#1");
+			Assert.AreEqual ("Data_rebounded", t.UserData.ToString (), "DataSourceChangedEvent#2");
+		}
+
+		#region DropDownList_DataSourceChangedEvent
+		public static void DropDownList_Init (Page p)
+		{
+			DropDownListTestClass dl = new DropDownListTestClass ();
+			DS data = new DS ();
+			p.Controls.Add (dl);
+			p.Controls.Add (data);
+			data.TypeName = typeof (DS).AssemblyQualifiedName;
+			data.SelectMethod = "GetList";
+			data.ID = "Data";
+			dl.DataBinding += new EventHandler (data_DataBinding);
+			dl.DataSourceID = "Data";
+		}
+
+		public static void DropDownList_Load (Page p)
+		{
+			if (p.IsPostBack) {
+				DS data = (DS) p.FindControl ("Data");
+				if (data == null)
+					Assert.Fail ("Data soource control not created#1");
+				data.DoRaiseDataSourceChangedEvent (new EventArgs ());
+			}
+		}
+
+		public static void data_DataBinding (object sender, EventArgs e)
+		{
+			if (((WebControl) sender).Page.IsPostBack)
+				WebTest.CurrentTest.UserData = "Data_rebounded";
+		}
+		#endregion
+#endif
 		[Test]
 		public void DropDownList_Defaults ()
 		{

+ 110 - 30
mcs/class/System.Web/Test/System.Web.UI.WebControls/FormViewTest.cs

@@ -47,7 +47,8 @@ using MonoTests.SystemWeb.Framework;
 using MonoTests.stand_alone.WebHarness;
 using System.Text.RegularExpressions;
 using System.Reflection;
-using System.Threading;
+using System.Threading;
+
 
 
 namespace MonoTests.System.Web.UI.WebControls
@@ -82,7 +83,27 @@ namespace MonoTests.System.Web.UI.WebControls
 
 			public static int GetCount () {
 				return GetList ().Count;
-			}
+			}
+		}
+
+		public class DS : ObjectDataSource
+		{
+			public static List<string> GetList ()
+			{
+				List<string> list = new List<string> ();
+				list.Add ("Norway");
+				list.Add ("Sweden");
+				list.Add ("France");
+				list.Add ("Italy");
+				list.Add ("Israel");
+				list.Add ("Russia");
+				return list;
+			}
+
+			public void DoRaiseDataSourceChangedEvent (EventArgs e)
+			{
+				RaiseDataSourceChangedEvent (e);
+			}
 		}
 		
 		public class Poker : FormView {
@@ -90,10 +111,10 @@ namespace MonoTests.System.Web.UI.WebControls
 			public bool ensureDataBound=false;
 			public bool controlHierarchy=false;
 			bool _onPageIndexChangingCalled = false;
-			bool _onPageIndexChangedCalled = false;
-			
+			bool _onPageIndexChangedCalled = false;
+						
 			public Poker () {								
-				TrackViewState ();
+				TrackViewState ();
 			}
 
 			public object SaveState () {
@@ -103,8 +124,8 @@ namespace MonoTests.System.Web.UI.WebControls
 			public void LoadState (object state) {
 				LoadViewState (state);
 				
-			}
-
+			}
+
 			public HtmlTextWriterTag PokerTagKey
 			{
 				get { return base.TagKey; }
@@ -151,6 +172,11 @@ namespace MonoTests.System.Web.UI.WebControls
 			{
 				base.ExtractRowValues (filedValues, includeKeys);
 				
+			}
+
+			public bool IsRequiresDataBinding ()
+			{
+				return base.RequiresDataBinding;
 			}
 
 			protected override void InitializePager (FormViewRow row, PagedDataSource pageData)
@@ -345,30 +371,31 @@ namespace MonoTests.System.Web.UI.WebControls
 		
 
 		ArrayList myds = new ArrayList ();	
-		[TestFixtureSetUp]
-		public void setup ()
-		{
-			TestMyData.InitData();  
-			myds.Add ("Item1");
-			myds.Add ("Item2");
-			myds.Add ("Item3");
-			myds.Add ("Item4");
-			myds.Add ("Item5");
-			myds.Add ("Item6");
+                [TestFixtureSetUp]
+                public void setup ()
+                {
+                        TestMyData.InitData();  
+                        myds.Add ("Item1");
+                        myds.Add ("Item2");
+                        myds.Add ("Item3");
+                        myds.Add ("Item4");
+                        myds.Add ("Item5");
+                        myds.Add ("Item6");
 #if VISUAL_STUDIO
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FormView.aspx",
-				"FormView.aspx");
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FormViewTest1.aspx",
-				"FormViewTest1.aspx");
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FormViewInsertEditDelete.aspx",
-				"FormViewInsertEditDelete.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FormView.aspx",
+                                "FormView.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FormViewTest1.aspx",
+                                "FormViewTest1.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.FormViewInsertEditDelete.aspx",
+                                "FormViewInsertEditDelete.aspx");
 #else
-			WebTest.CopyResource (GetType (), "FormView.aspx", "FormView.aspx");
-			WebTest.CopyResource (GetType (), "FormViewTest1.aspx", "FormViewTest1.aspx");
-			WebTest.CopyResource (GetType (), "FormViewInsertEditDelete.aspx", "FormViewInsertEditDelete.aspx");
+                        WebTest.CopyResource (GetType (), "FormView.aspx", "FormView.aspx");
+                        WebTest.CopyResource (GetType (), "FormViewTest1.aspx", "FormViewTest1.aspx");
+                        WebTest.CopyResource (GetType (), "FormViewInsertEditDelete.aspx", "FormViewInsertEditDelete.aspx");
 #endif
 
-		}
+               }
+		
 
 		[Test]
 		public void Defaults ()
@@ -1196,9 +1223,62 @@ namespace MonoTests.System.Web.UI.WebControls
 			Assert.AreEqual (true, pageIndexChanging, "AfterLastPageBubbleEvent");
 			Assert.AreEqual (5, newPageIndex, "FirstPageIndex");
 
-		}
-
-
+		}
+
+		[Test]
+		[Category("NunitWeb")]
+		[Category ("NotWorking")]
+		public void FormView_DataSourceChangedEvent ()
+		{
+			WebTest t = new WebTest();
+			PageDelegates pd = new PageDelegates ();
+			pd.Load = FormView_Init;
+			pd.PreRenderComplete = FormView_Load;
+			t.Invoker = new PageInvoker (pd);
+			t.Run ();
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+			fr.Controls["__EVENTTARGET"].Value = "";
+			fr.Controls["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+			t.Run ();
+			if (t.UserData == null)
+				Assert.Fail ("DataSourceChangedEvent#1");
+			Assert.AreEqual ("Data_rebounded", t.UserData.ToString (), "DataSourceChangedEvent#2");
+		}
+
+		#region FormView_DataSourceChangedEvent
+		public static void FormView_Init(Page p)
+		{
+			Poker fv = new Poker ();
+			DS data = new DS ();
+			p.Controls.Add (fv);
+			p.Controls.Add (data);
+			data.TypeName = typeof (DS).AssemblyQualifiedName;
+			data.SelectMethod = "GetList";
+			data.ID = "Data";
+			fv.DataBinding += new EventHandler (data_DataBinding);
+			fv.DataSourceID = "Data";
+		}
+
+		public static void FormView_Load (Page p)
+		{
+			if (p.IsPostBack) {
+				DS data = (DS) p.FindControl ("Data") ;
+				if (data == null)
+					Assert.Fail ("Data soource control not created#1");
+				data.DoRaiseDataSourceChangedEvent (new EventArgs ());
+			}
+		}
+
+		public static void data_DataBinding (object sender, EventArgs e)
+		{
+			if (((WebControl) sender).Page.IsPostBack) 
+				WebTest.CurrentTest.UserData = "Data_rebounded";
+		}
+		#endregion
+
 		[Test]
 		public void FormView_Events ()
 		{

+ 93 - 23
mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs

@@ -305,14 +305,30 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 	}
 
-	
-
-	
-
 	[Serializable]
 	[TestFixture]
 	public class GridViewTest
-	{
+	{
+		class DS : ObjectDataSource, IDataSource
+		{
+			public static List<string> GetList ()
+			{
+				List<string> list = new List<string> ();
+				list.Add ("Norway");
+				list.Add ("Sweden");
+				list.Add ("France");
+				list.Add ("Italy");
+				list.Add ("Israel");
+				list.Add ("Russia");
+				return list;
+			}
+
+			public void DoRaiseDataSourceChangedEvent (EventArgs e)
+			{
+				RaiseDataSourceChangedEvent (e);
+			}
+		}
+
 		public class DataSourceObject
 		{
 			public static List<string> GetList (string sortExpression, int startRowIndex, int maximumRows) {
@@ -392,25 +408,25 @@ namespace MonoTests.System.Web.UI.WebControls
 		public const string BOOLFIELD = "bool";
 		public const string STRINGFIELD = "str";
 		ArrayList myds = new ArrayList ();
-		public bool InitilizePager;
-
-		[TestFixtureSetUp]
-		public void GridViewInit ()
+		public bool InitilizePager;
+
+		[TestFixtureSetUp]
+		public void GridViewInit ()
 		{
-			
-			myds.Add ("Norway");
-			myds.Add ("Sweden");
-			myds.Add ("France");
-			myds.Add ("Italy");
-			myds.Add ("Israel");
-			myds.Add ("Russia");
+
+			myds.Add ("Norway");
+			myds.Add ("Sweden");
+			myds.Add ("France");
+			myds.Add ("Italy");
+			myds.Add ("Israel");
+			myds.Add ("Russia");
 #if VISUAL_STUDIO
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.GridViewUpdate.aspx", "GridViewUpdate.aspx");
-			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.NoEventValidation.aspx", "NoEventValidation.aspx");
-#else
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.GridViewUpdate.aspx", "GridViewUpdate.aspx");
+                        WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.NoEventValidation.aspx", "NoEventValidation.aspx");
+#else
 			WebTest.CopyResource (GetType (), "GridViewUpdate.aspx", "GridViewUpdate.aspx");
-			WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
-#endif
+			WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
+#endif
 		}
 
 		[Test]
@@ -1399,8 +1415,62 @@ namespace MonoTests.System.Web.UI.WebControls
 		private void gv_PageIndexChanged (object sender, EventArgs e)
 		{
 			pageIndexChanged = true;
-		}
-
+		}
+
+		[Test]
+		[Category ("NunitWeb")]
+		[Category ("NotWorking")]
+		public void GridView_DataSourceChangedEvent ()
+		{
+			WebTest t = new WebTest ();
+			PageDelegates pd = new PageDelegates ();
+			pd.Load = GridView_Init;
+			pd.PreRenderComplete = GridView_Load;
+			t.Invoker = new PageInvoker (pd);
+			t.Run ();
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+			fr.Controls["__EVENTTARGET"].Value = "";
+			fr.Controls["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+			t.Run ();
+			if (t.UserData == null)
+				Assert.Fail ("DataSourceChangedEvent#1");
+			Assert.AreEqual ("Data_rebounded", t.UserData.ToString (), "DataSourceChangedEvent#2");
+		}
+
+		#region GridView_DataSourceChangedEvent
+		public static void GridView_Init (Page p)
+		{
+			PokerGridView gv = new PokerGridView ();
+			DS data = new DS ();
+			p.Controls.Add (gv);
+			p.Controls.Add (data);
+			data.TypeName = typeof (DS).AssemblyQualifiedName;
+			data.SelectMethod = "GetList";
+			data.ID = "Data";
+			gv.DataBinding += new EventHandler (data_DataBinding);
+			gv.DataSourceID = "Data";
+		}
+
+		public static void GridView_Load (Page p)
+		{
+			if (p.IsPostBack) {
+				DS data = (DS) p.FindControl ("Data");
+				if (data == null)
+					Assert.Fail ("Data soource control not created#1");
+				data.DoRaiseDataSourceChangedEvent (new EventArgs ());
+			}
+		}
+
+		public static void data_DataBinding (object sender, EventArgs e)
+		{
+			if (((WebControl) sender).Page.IsPostBack)
+				WebTest.CurrentTest.UserData = "Data_rebounded";
+		}
+		#endregion
+
 		[Test]
 		public void GridView_PerformDataBiding ()
 		{