Browse Source

2009-12-15 Marek Habersack <[email protected]>

	* System.Web.Extensions_test.dll.sources: added
	System.Web.UI.WebControls/ListViewPagedDataSourceTest.cs

2009-12-15  Marek Habersack  <[email protected]>

	* NextPreviousPagerField.cs: HandleEvent doesn't call
	DataPager.SetPageProperties with negative start index. Also, if
	_totalRowCount is <= 0, new start index is not calculated using
	it. Fixes bug #545417

	* ListViewPagedDataSource.cs: when server paging is on, data items
	are counted from index 0 instead of from the value stored in
	StartRowIndex. Fixes bug #545417

	* ListView.cs: CreateChildControls doesn't create empty data item
	if called with fake data.
	When a view reports it can page data, ListViewPagedDataSource
	passed to item creation methods has AllowServerPaging set to
	true. Fixes bug #545417
	When CreateChildControls is called with fake data,
	ListViewPagedDataSource has its TotalRowCount property set to the
	actual total row count, not zero. Fixes bug #545417

svn path=/trunk/mcs/; revision=148498
Marek Habersack 16 years ago
parent
commit
779b8668ea

+ 5 - 0
mcs/class/System.Web.Extensions/ChangeLog

@@ -1,3 +1,8 @@
+2009-12-15  Marek Habersack  <[email protected]>
+
+	* System.Web.Extensions_test.dll.sources: added
+	System.Web.UI.WebControls/ListViewPagedDataSourceTest.cs
+
 2009-10-08  Atsushi Enomoto  <[email protected]>
 
 	* Makefile : add -r:System.ServiceModel.

+ 1 - 0
mcs/class/System.Web.Extensions/System.Web.Extensions_test.dll.sources

@@ -45,4 +45,5 @@ System.Web.UI/ScriptReferenceBaseTest.cs
 System.Web.UI/UpdateProgressTest.cs
 System.Web.UI.WebControls/EventRecorder.cs
 System.Web.UI.WebControls/ListViewTest.cs
+System.Web.UI.WebControls/ListViewPagedDataSourceTest.cs
 System.Web.UI.WebControls/DataPagerFieldCollectionTest.cs

+ 20 - 0
mcs/class/System.Web.Extensions/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,23 @@
+2009-12-15  Marek Habersack  <[email protected]>
+
+	* NextPreviousPagerField.cs: HandleEvent doesn't call
+	DataPager.SetPageProperties with negative start index. Also, if
+	_totalRowCount is <= 0, new start index is not calculated using
+	it. Fixes bug #545417
+
+	* ListViewPagedDataSource.cs: when server paging is on, data items
+	are counted from index 0 instead of from the value stored in
+	StartRowIndex. Fixes bug #545417
+
+	* ListView.cs: CreateChildControls doesn't create empty data item
+	if called with fake data.
+	When a view reports it can page data, ListViewPagedDataSource
+	passed to item creation methods has AllowServerPaging set to
+	true. Fixes bug #545417
+	When CreateChildControls is called with fake data,
+	ListViewPagedDataSource has its TotalRowCount property set to the
+	actual total row count, not zero. Fixes bug #545417
+
 2009-09-15  Marek Habersack  <[email protected]>
 
 	* ListView.cs: CreateChildControls calls EnsureDataBound only if

+ 12 - 5
mcs/class/System.Web.Extensions/System.Web.UI.WebControls/ListView.cs

@@ -102,7 +102,8 @@ namespace System.Web.UI.WebControls
 		IOrderedDictionary _currentDeletingItemValues;
 		
 		int _firstIdAfterLayoutTemplate = 0;
-		
+
+		bool usingFakeData;
 #region Events
 		// Event keys
 		static readonly object ItemCancellingEvent = new object ();
@@ -774,7 +775,12 @@ namespace System.Web.UI.WebControls
 					// OnTotalRowCountAvailable is called now - so that any
 					// pagers can create child controls.
 					object[] data = new object [c];
-					CreateChildControls (data, false);
+					usingFakeData = true;
+					try {
+						CreateChildControls (data, false);
+					} finally {
+						usingFakeData = false;
+					}
 				}
 			} else if (RequiresDataBinding)
 				EnsureDataBound ();
@@ -801,6 +807,7 @@ namespace System.Web.UI.WebControls
 
 				int totalRowCount = 0;
 				if (haveDataToPage && view.CanPage) {
+					pagedDataSource.AllowServerPaging = true;
 					if (view.CanRetrieveTotalRowCount)
 						totalRowCount = SelectArguments.TotalRowCount;
 					else {
@@ -817,14 +824,14 @@ namespace System.Web.UI.WebControls
 			} else {
 				if (!(dataSource is ICollection))
 					throw new InvalidOperationException ("dataSource does not implement the ICollection interface and dataBinding is false.");
-				pagedDataSource.TotalRowCount = 0;
+				pagedDataSource.TotalRowCount = _totalRowCount;
 				_totalRowCount = -1;
 			}
 
 			pagedDataSource.StartRowIndex = StartRowIndex;
 			pagedDataSource.MaximumRows = MaximumRows;
 			pagedDataSource.DataSource = dataSource;
-			
+
 			bool emptySet = false;
 			if (dataSource != null) {
 				if (GroupItemCount <= 1 && GroupTemplate == null)
@@ -848,7 +855,7 @@ namespace System.Web.UI.WebControls
 			} else
 				emptySet = true;
 
-			if (emptySet) {
+			if (!usingFakeData && emptySet) {
 				Controls.Clear ();
 				CreateEmptyDataItem ();
 			}

+ 3 - 4
mcs/class/System.Web.Extensions/System.Web.UI.WebControls/ListViewPagedDataSource.cs

@@ -139,11 +139,11 @@ namespace System.Web.UI.WebControls
 
 			IList list = ds as IList;
 			if (list != null)
-				return new ListEnumerator (list, StartRowIndex, Count);
+				return new ListEnumerator (list, AllowServerPaging ? 0 : StartRowIndex, Count);
 
 			ICollection collection = ds as ICollection;
 			if (collection != null)
-				return new CollectionEnumerator (collection, StartRowIndex, Count);
+				return new CollectionEnumerator (collection, AllowServerPaging ? 0 : StartRowIndex, Count);
 			
 			return ds.GetEnumerator ();
 		}
@@ -180,8 +180,7 @@ namespace System.Web.UI.WebControls
 					return maxRows;
 
 				// LAMESPEC: MSDN says that DataSourceCount should be subtracted
-				// from StartRowIndex, but that would result in a negative number,
-				// which is not what we want.
+				// from StartRowIndex
 				return DataSourceCount - StartRowIndex;
 			}
 		}

+ 2 - 2
mcs/class/System.Web.Extensions/System.Web.UI.WebControls/NextPreviousPagerField.cs

@@ -277,7 +277,7 @@ namespace System.Web.UI.WebControls
 					newStartIndex = _totalRowCount - lastPageMod;
 			} else if (String.Compare (commandName, DataControlCommands.NextPageCommandArgument, StringComparison.OrdinalIgnoreCase) == 0) {
 				newStartIndex = _startRowIndex + pageSize;
-				if (newStartIndex > _totalRowCount)
+				if (_totalRowCount >= 0 && newStartIndex > _totalRowCount)
 					newStartIndex = _totalRowCount - pageSize;
 			} else if (String.Compare (commandName, DataControlCommands.PreviousPageCommandArgument, StringComparison.OrdinalIgnoreCase) == 0) {
 				newStartIndex = _startRowIndex - pageSize;
@@ -285,7 +285,7 @@ namespace System.Web.UI.WebControls
 					newStartIndex = 0;
 			}
 
-			if (newStartIndex != -1)
+			if (newStartIndex >= 0)
 				DataPager.SetPageProperties (newStartIndex, pageSize, true);
 		}
 

+ 1 - 1
mcs/class/System.Web.Extensions/Test/System.Web.UI.WebControls/DataPagerFieldCollectionTest.cs

@@ -37,7 +37,7 @@ using System.Web.UI.WebControls;
 
 using NUnit.Framework;
 
-namespace Tests.System.Web.UI.WebControls
+namespace MonoTests.System.Web.UI.WebControls
 {
 	class DataPagerFieldCollectionPoker : DataPagerFieldCollection
 	{

+ 1 - 1
mcs/class/System.Web.Extensions/Test/System.Web.UI.WebControls/EventRecorder.cs

@@ -33,7 +33,7 @@ using System.Collections.Generic;
 using System.Diagnostics;
 using System.Reflection;
 
-namespace Tests.System.Web.UI.WebControls
+namespace MonoTests.System.Web.UI.WebControls
 {
 	[Serializable]
 	public sealed class EventRecorder : List <string>

+ 232 - 0
mcs/class/System.Web.Extensions/Test/System.Web.UI.WebControls/ListViewPagedDataSourceTest.cs

@@ -0,0 +1,232 @@
+//
+// System.Web.UI.WebControls.ListView
+//
+// Authors:
+//   Marek Habersack ([email protected])
+//
+// (C) 2009 Novell, Inc
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+#if NET_3_5
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+using NUnit.Framework;
+using MonoTests.SystemWeb.Framework;
+using MonoTests.stand_alone.WebHarness;
+
+namespace MonoTests.System.Web.UI.WebControls
+{
+	[TestFixture]
+	public class ListViewPagedDataSourceTest
+	{
+		string EnumerableToString (IEnumerable data)
+		{
+			var sb = new StringBuilder ();
+
+			foreach (object d in data)
+				sb.Append (d.ToString ());
+
+			return sb.ToString ();
+		}
+		
+		List<string> GetData (int count)
+		{
+			var ret = new List<string> ();
+
+			for (int i = 0; i < count; i++)
+				ret.Add (i.ToString ());
+
+			return ret;
+		}
+
+		ListViewPagedDataSource GetDataSource (List<string> ds, int startRowIndex, int maximumRows, int totalRowCount, bool allowServerPaging)
+		{
+			var ret = new ListViewPagedDataSource ();
+
+			ret.DataSource = ds;
+			ret.StartRowIndex = startRowIndex;
+			ret.MaximumRows = maximumRows;
+			ret.TotalRowCount = totalRowCount;
+			ret.AllowServerPaging = allowServerPaging;
+
+			return ret;
+		}
+
+		[Test]
+		public void Counts ()
+		{
+			List<string> l = GetData (10);
+			ListViewPagedDataSource pds = GetDataSource (l, 0, 10, 25, false);
+
+			Assert.AreEqual (10, pds.Count, "#A1-1");
+			Assert.AreEqual (10, pds.DataSourceCount, "#A1-2");
+
+			pds = GetDataSource (l, 0, 10, 25, true);
+			Assert.AreEqual (10, pds.Count, "#A2-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#A2-2");
+
+			pds = GetDataSource (l, 10, 10, 25, false);
+			Assert.AreEqual (0, pds.Count, "#A3-1");
+			Assert.AreEqual (10, pds.DataSourceCount, "#A3-2");
+
+			pds = GetDataSource (l, 10, 10, 25, true);
+			Assert.AreEqual (10, pds.Count, "#A4-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#A4-2");
+
+			pds = GetDataSource (l, 15, 10, 25, false);
+			Assert.AreEqual (-5, pds.Count, "#A5-1");
+			Assert.AreEqual (10, pds.DataSourceCount, "#A5-2");
+
+			pds = GetDataSource (l, 15, 10, 25, true);
+			Assert.AreEqual (10, pds.Count, "#A6-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#A6-2");
+
+			pds = GetDataSource (l, 20, 10, 25, false);
+			Assert.AreEqual (-10, pds.Count, "#A7-1");
+			Assert.AreEqual (10, pds.DataSourceCount, "#A7-2");
+
+			pds = GetDataSource (l, 20, 10, 25, true);
+			Assert.AreEqual (5, pds.Count, "#A8-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#A8-2");
+
+			pds = GetDataSource (l, 25, 10, 25, false);
+			Assert.AreEqual (-15, pds.Count, "#A9-1");
+			Assert.AreEqual (10, pds.DataSourceCount, "#A9-2");
+
+			pds = GetDataSource (l, 25, 10, 25, true);
+			Assert.AreEqual (0, pds.Count, "#A10-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#A10-2");
+
+			pds = GetDataSource (l, 30, 10, 25, false);
+			Assert.AreEqual (-20, pds.Count, "#A11-1");
+			Assert.AreEqual (10, pds.DataSourceCount, "#A11-2");
+
+			pds = GetDataSource (l, 30, 10, 25, true);
+			Assert.AreEqual (-5, pds.Count, "#A12-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#A12-2");
+
+			l = GetData (11);
+			pds = GetDataSource (l, 0, 11, 25, false);
+
+			Assert.AreEqual (11, pds.Count, "#B1-1");
+			Assert.AreEqual (11, pds.DataSourceCount, "#B1-2");
+
+			pds = GetDataSource (l, 0, 11, 25, true);
+			Assert.AreEqual (11, pds.Count, "#B2-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#B2-2");
+
+			pds = GetDataSource (l, 10, 11, 25, false);
+			Assert.AreEqual (1, pds.Count, "#B3-1");
+			Assert.AreEqual (11, pds.DataSourceCount, "#B3-2");
+
+			pds = GetDataSource (l, 10, 11, 25, true);
+			Assert.AreEqual (11, pds.Count, "#B4-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#B4-2");
+
+			pds = GetDataSource (l, 15, 11, 25, false);
+			Assert.AreEqual (-4, pds.Count, "#B5-1");
+			Assert.AreEqual (11, pds.DataSourceCount, "#B5-2");
+
+			pds = GetDataSource (l, 15, 11, 25, true);
+			Assert.AreEqual (10, pds.Count, "#B6-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#B6-2");
+
+			pds = GetDataSource (l, 20, 11, 25, false);
+			Assert.AreEqual (-9, pds.Count, "#B7-1");
+			Assert.AreEqual (11, pds.DataSourceCount, "#B7-2");
+
+			pds = GetDataSource (l, 20, 11, 25, true);
+			Assert.AreEqual (5, pds.Count, "#B8-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#B8-2");
+
+			pds = GetDataSource (l, 25, 11, 25, false);
+			Assert.AreEqual (-14, pds.Count, "#B9-1");
+			Assert.AreEqual (11, pds.DataSourceCount, "#B9-2");
+
+			pds = GetDataSource (l, 25, 11, 25, true);
+			Assert.AreEqual (0, pds.Count, "#B10-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#B10-2");
+
+			pds = GetDataSource (l, 30, 11, 25, false);
+			Assert.AreEqual (-19, pds.Count, "#B11-1");
+			Assert.AreEqual (11, pds.DataSourceCount, "#B11-2");
+
+			pds = GetDataSource (l, 30, 11, 25, true);
+			Assert.AreEqual (-5, pds.Count, "#B12-1");
+			Assert.AreEqual (25, pds.DataSourceCount, "#B12-2");
+		}
+
+		[Test]
+		public void Enumerator ()
+		{
+			List<string> l = GetData (10);
+			ListViewPagedDataSource pds = GetDataSource (l, 0, 10, 25, false);
+			Assert.AreEqual ("0123456789", EnumerableToString (pds), "#A1");
+
+			pds = GetDataSource (l, 5, 10, 25, false);
+			Assert.AreEqual ("56789", EnumerableToString (pds), "#A2");
+
+			pds = GetDataSource (l, 9, 10, 25, false);
+			Assert.AreEqual ("9", EnumerableToString (pds), "#A3");
+
+			pds = GetDataSource (l, 10, 10, 25, false);
+			Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A4");
+
+			pds = GetDataSource (l, 20, 10, 25, false);
+			Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A5");
+
+			pds = GetDataSource (l, 25, 10, 25, false);
+			Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A6");
+
+			pds = GetDataSource (l, 30, 10, 25, false);
+			Assert.AreEqual (String.Empty, EnumerableToString (pds), "#A7");
+
+			pds = GetDataSource (l, 0, 10, 25, true);
+			Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B1");
+
+			pds = GetDataSource (l, 5, 10, 25, true);
+			Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B2");
+
+			pds = GetDataSource (l, 9, 10, 25, true);
+			Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B3");
+
+			pds = GetDataSource (l, 10, 10, 25, true);
+			Assert.AreEqual ("0123456789", EnumerableToString (pds), "#B4");
+
+			pds = GetDataSource (l, 20, 10, 25, true);
+			Assert.AreEqual ("01234", EnumerableToString (pds), "#B5");
+
+			pds = GetDataSource (l, 25, 10, 25, true);
+			Assert.AreEqual (String.Empty, EnumerableToString (pds), "#B6");
+
+			pds = GetDataSource (l, 30, 10, 25, true);
+			Assert.AreEqual (String.Empty, EnumerableToString (pds), "#B7");
+		}
+	}
+}
+#endif

+ 1 - 1
mcs/class/System.Web.Extensions/Test/System.Web.UI.WebControls/ListViewTest.cs

@@ -42,7 +42,7 @@ using NUnit.Framework;
 using MonoTests.SystemWeb.Framework;
 using MonoTests.stand_alone.WebHarness;
 
-namespace Tests.System.Web.UI.WebControls
+namespace MonoTests.System.Web.UI.WebControls
 {
 	public sealed class ListViewPoker : ListView
 	{

+ 1 - 1
mcs/class/System.Web.Extensions/Test/resources/ListViewTest.aspx

@@ -1,5 +1,5 @@
 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
-<%@ Register Assembly="System.Web.Extensions_test_net_2_0" Namespace="Tests.System.Web.UI.WebControls" TagPrefix="t" %>
+<%@ Register Assembly="System.Web.Extensions_test_net_2_0" Namespace="MonoTests.System.Web.UI.WebControls" TagPrefix="t" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 <html xmlns="http://www.w3.org/1999/xhtml">