Пример #1
0
		public static bool KeepFirstHalfOfItemsFilter(DataItem o)
		{
			return o.Id < ItemCount / 2;
		}
Пример #2
0
		public static int SortItemsDescending(DataItem x, DataItem y)
		{
			return -SortItemsAscending(x, y);
		}
Пример #3
0
		public static bool KeepOddItemsFilter(DataItem o)
		{
			return o.Id % 2 == 1; // keep all odd items only.
		}
Пример #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);
		}
Пример #5
0
		public static int SortItemsAscending(DataItem x, DataItem y)
		{
			var a = x.Id;
			var b = y.Id;
			return a - b;
		}
Пример #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");
		}
Пример #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");
		}
Пример #8
0
 public static bool KeepFirstHalfOfItemsFilter(DataItem o)
 {
     return(o.Id < ItemCount / 2);
 }
Пример #9
0
 public static bool KeepOddItemsFilter(DataItem o)
 {
     return(o.Id % 2 == 1);            // keep all odd items only.
 }
Пример #10
0
 public static int SortItemsDescending(DataItem x, DataItem y)
 {
     return(-SortItemsAscending(x, y));
 }