Skip to content

Commit

Permalink
Add test if lists with elements of different types work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lhak committed Jun 16, 2023
1 parent dc47516 commit 2f14da1
Showing 1 changed file with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private class SampleClass : INotifyPropertyChanged

private int val;

public int Val
public virtual int Val
{
get
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<SampleClass> refList = new List<SampleClass>();
for (int e = 0; e < 100; e++)
{
if ((e % 2) == 1)
{
refList.Add(new SampleClass(e));
}
else
{
refList.Add(new DerivedClass(e));
}
}
ObservableCollection<SampleClass> col = new ObservableCollection<SampleClass>();

// 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));
}
}

0 comments on commit 2f14da1

Please sign in to comment.