From 2f14da12980da03a1fa885ad918130a4c1e4bef3 Mon Sep 17 00:00:00 2001 From: Arno Klenke Date: Fri, 16 Jun 2023 20:13:03 +0200 Subject: [PATCH] Add test if lists with elements of different types work correctly --- .../tests/Test_AdvancedCollectionView.cs | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/components/AdvancedCollectionView/tests/Test_AdvancedCollectionView.cs b/components/AdvancedCollectionView/tests/Test_AdvancedCollectionView.cs index 92131c3e..fdc61cc8 100644 --- a/components/AdvancedCollectionView/tests/Test_AdvancedCollectionView.cs +++ b/components/AdvancedCollectionView/tests/Test_AdvancedCollectionView.cs @@ -15,7 +15,7 @@ private class SampleClass : INotifyPropertyChanged private int val; - public int Val + public virtual int Val { get { @@ -45,6 +45,25 @@ private void OnPropertyChanged([CallerMemberName] string name = "") } } + private class DerivedClass : SampleClass + { + public DerivedClass(int val) : base(val) + { + } + + public override int Val + { + get + { + return 101; + } + + set + { + } + } + } + [TestCategory("Helpers")] [UITestMethod] public void Test_SourceNcc_CollectionChanged_Add() @@ -110,4 +129,34 @@ public void Test_SourceNcc_CollectionChanged_Remove() Assert.IsTrue(item.GetPropertyChangedEventHandlerSubscriberLength() == 0); } } + + [TestCategory("Helpers")] + [UITestMethod] + public void Test_DerivedTypesInList() + { + // Create ref list with elements of different types: + List refList = new List(); + for (int e = 0; e < 100; e++) + { + if ((e % 2) == 1) + { + refList.Add(new SampleClass(e)); + } + else + { + refList.Add(new DerivedClass(e)); + } + } + ObservableCollection col = new ObservableCollection(); + + // Add all items to collection: + foreach (var item in refList) + { + col.Add(item); + } + + // Sort elements using a property that is overriden in the derived class + AdvancedCollectionView acv = new AdvancedCollectionView(col, true); + acv.SortDescriptions.Add(new SortDescription("Val", SortDirection.Descending)); + } }