Skip to content

Commit

Permalink
Add unit tests for CollectionViewSource ItemsPath support
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Mar 19, 2019
1 parent 9bf6de6 commit 8f7c7fc
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,72 @@ public void When_Source_Notify()
Assert.AreEqual(1, SUT.View.Count);
Assert.AreEqual(1, viewChanged);
}

[TestMethod]
public void When_Valid_ItemsPath()
{
var SUT = new CollectionViewSource() { IsSourceGrouped = true };
SUT.ItemsPath = "MyItems";

int viewChanged = 0;
SUT.RegisterPropertyChangedCallback(CollectionViewSource.ViewProperty, (s, e) => viewChanged++);

Assert.IsNull(SUT.View);

var items = new[] {
new {
Key = 42,
MyItems = new [] {
21,
21
}
}
};

SUT.Source = items;

Assert.IsNotNull(SUT.View);
Assert.AreEqual(2, SUT.View.Count);
Assert.AreEqual(1, viewChanged);

Assert.AreEqual(1, SUT.View.CollectionGroups.Count);

var firstGroup = SUT.View.CollectionGroups.First() as ICollectionViewGroup;
Assert.AreEqual(items.First(), firstGroup.Group);
Assert.AreEqual(2, firstGroup.GroupItems.Count);
}

[TestMethod]
public void When_Invalid_ItemsPath()
{
var SUT = new CollectionViewSource() { IsSourceGrouped = true };
SUT.ItemsPath = "Invalid";

int viewChanged = 0;
SUT.RegisterPropertyChangedCallback(CollectionViewSource.ViewProperty, (s, e) => viewChanged++);

Assert.IsNull(SUT.View);

var items = new[] {
new {
Key = 42,
MyItems = new [] {
21,
21
}
}
};

SUT.Source = items;

Assert.IsNotNull(SUT.View);
Assert.AreEqual(0, SUT.View.Count);
Assert.AreEqual(1, viewChanged);

Assert.AreEqual(1, SUT.View.CollectionGroups.Count);

var firstGroup = SUT.View.CollectionGroups.First() as ICollectionViewGroup;
Assert.AreEqual(0, firstGroup.GroupItems.Count);
}
}
}

0 comments on commit 8f7c7fc

Please sign in to comment.