Ejemplo n.º 1
0
		public static bool KeepFirstHalfOfItemsFilter(DataItem o)
		{
			return o.Id < ItemCount / 2;
		}
Ejemplo n.º 2
0
		public static int SortItemsDescending(DataItem x, DataItem y)
		{
			return -SortItemsAscending(x, y);
		}
Ejemplo n.º 3
0
		public static bool KeepOddItemsFilter(DataItem o)
		{
			return o.Id % 2 == 1; // keep all odd items only.
		}
Ejemplo n.º 4
0
		public static int SortEvenItemsBeforeOdd(DataItem x, DataItem y)
		{
			var a = x.Id;
			var b = y.Id;
			return (a % 2 == b % 2) ? a - b : (a % 2 == 0 ? -1 : 1);
		}
Ejemplo n.º 5
0
		public static int SortItemsAscending(DataItem x, DataItem y)
		{
			var a = x.Id;
			var b = y.Id;
			return a - b;
		}
Ejemplo n.º 6
0
		public void InsertItemShouldBeInSameOrderInModel()
		{
			var model = GridViewUtils.CreateModel();
			var filtered = new FilterCollection<DataItem>(model);
			filtered.Filter = GridViewUtils.KeepOddItemsFilter;

			const int filterInsertIndex = 10;

			var item = new DataItem(1000);
			filtered.Insert(filterInsertIndex, item);
			Assert.AreEqual(filtered[filterInsertIndex].Id, 21, "#1 Item should NOT be inserted at the specified index, since it is an even number");
			Assert.AreEqual(filtered.IndexOf(item), -1, "#2 Item should NOT be in the filtered list");
			Assert.AreEqual(model.IndexOf(filtered[filterInsertIndex]) - 1, model.IndexOf(item), "#3 Item should be inserted right before item at filter location");


			item = new DataItem(1001);
			filtered.Insert(filterInsertIndex, item);
			Assert.AreEqual(filtered[filterInsertIndex].Id, 1001, "#4 Item with odd number should be inserted at the specified index");
			Assert.AreEqual(filtered.IndexOf(item), filterInsertIndex, "#5 Item should be in the filtered list at the insert location");
			Assert.AreEqual(model.IndexOf(filtered[filterInsertIndex + 1]) - 1, model.IndexOf(item), "#6 Item should be inserted right before item at filter location");

			// refresh the list
			filtered.Refresh();

			// re-test inserted item, it should be at the same index.
			Assert.AreEqual(filtered[filterInsertIndex].Id, 1001, "#7 Item with odd number should be inserted at the specified index");
			Assert.AreEqual(filtered.IndexOf(item), filterInsertIndex, "#8 Item should be in the filtered list at the insert location");
			Assert.AreEqual(model.IndexOf(filtered[filterInsertIndex + 1]) - 1, model.IndexOf(item), "#9 Item should be inserted right before item at filter location");
		}
Ejemplo n.º 7
0
		public void InsertItemShouldTriggerCorrectChange()
		{
			var model = GridViewUtils.CreateModel();
			var filtered = new FilterCollection<DataItem>(model);
			filtered.Sort = GridViewUtils.SortEvenItemsBeforeOdd;

			int newIndex = -1;
			filtered.CollectionChanged += (sender, e) =>
			{
				Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action, "Action should be add");
				newIndex = e.NewStartingIndex;
			};
			var item = new DataItem(1000);
			const int insertIndex = 50;
			filtered.Insert(insertIndex, item);

			var index = filtered.IndexOf(item);
			Assert.AreEqual(filtered[index].Id, item.Id, "Index reported does not have correct item");
			Assert.AreEqual(index, newIndex, "Triggered event should have correct index");
			Assert.AreEqual(insertIndex, index, "Index of item should be the inserted index");
		}
Ejemplo n.º 8
0
 public static bool KeepFirstHalfOfItemsFilter(DataItem o)
 {
     return(o.Id < ItemCount / 2);
 }
Ejemplo n.º 9
0
 public static bool KeepOddItemsFilter(DataItem o)
 {
     return(o.Id % 2 == 1);            // keep all odd items only.
 }
Ejemplo n.º 10
0
 public static int SortItemsDescending(DataItem x, DataItem y)
 {
     return(-SortItemsAscending(x, y));
 }