Skip to content

Commit 688b17d

Browse files
lhakArlodotexe
authored andcommitted
Add test if lists with elements of different types work correctly
1 parent 72bf0b1 commit 688b17d

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

components/Collections/tests/Test_AdvancedCollectionView.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private class SampleClass : INotifyPropertyChanged
1515

1616
private int val;
1717

18-
public int Val
18+
public virtual int Val
1919
{
2020
get
2121
{
@@ -45,6 +45,25 @@ private void OnPropertyChanged([CallerMemberName] string name = "")
4545
}
4646
}
4747

48+
private class DerivedClass : SampleClass
49+
{
50+
public DerivedClass(int val) : base(val)
51+
{
52+
}
53+
54+
public override int Val
55+
{
56+
get
57+
{
58+
return 101;
59+
}
60+
61+
set
62+
{
63+
}
64+
}
65+
}
66+
4867
[TestCategory("Helpers")]
4968
[UITestMethod]
5069
public void Test_SourceNcc_CollectionChanged_Add()
@@ -110,4 +129,34 @@ public void Test_SourceNcc_CollectionChanged_Remove()
110129
Assert.IsTrue(item.GetPropertyChangedEventHandlerSubscriberLength() == 0);
111130
}
112131
}
132+
133+
[TestCategory("Helpers")]
134+
[UITestMethod]
135+
public void Test_DerivedTypesInList()
136+
{
137+
// Create ref list with elements of different types:
138+
List<SampleClass> refList = new List<SampleClass>();
139+
for (int e = 0; e < 100; e++)
140+
{
141+
if ((e % 2) == 1)
142+
{
143+
refList.Add(new SampleClass(e));
144+
}
145+
else
146+
{
147+
refList.Add(new DerivedClass(e));
148+
}
149+
}
150+
ObservableCollection<SampleClass> col = new ObservableCollection<SampleClass>();
151+
152+
// Add all items to collection:
153+
foreach (var item in refList)
154+
{
155+
col.Add(item);
156+
}
157+
158+
// Sort elements using a property that is overriden in the derived class
159+
AdvancedCollectionView acv = new AdvancedCollectionView(col, true);
160+
acv.SortDescriptions.Add(new SortDescription("Val", SortDirection.Descending));
161+
}
113162
}

0 commit comments

Comments
 (0)