Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public void RemoveAt(int index)
/// </summary>
public IEnumerator GetEnumerator()
{
EnsureEventsOwned();

// We can only return an enumerator on the events we actually have.
if (_events.Length == Count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ public void CountTests()
Assert.Equal(2, ((ICollection)descriptors).Count);
}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void GetEnumerator_SortedCollection_ReturnsSortedEvents(bool spareCapacity, bool namedSort)
{
var zeta = new MockEventDescriptor("Zeta");
var alpha = new MockEventDescriptor("Alpha");
var extra = new MockEventDescriptor("Extra");
EventDescriptor[] descriptors = spareCapacity ? new EventDescriptor[] { zeta, alpha, extra } : new EventDescriptor[] { zeta, alpha };
var collection = new EventDescriptorCollection(descriptors);
if (spareCapacity)
{
collection.Remove(extra);
}

EventDescriptorCollection sorted = namedSort ? collection.Sort(new[] { "Zeta" }) : collection.Sort();

Assert.Equal(namedSort ? new[] { zeta, alpha } : new[] { alpha, zeta }, sorted.Cast<EventDescriptor>());
Assert.Equal(new[] { zeta, alpha }, collection.Cast<EventDescriptor>());
Assert.Same(zeta, descriptors[0]);
}

private class MockEventDescriptor : EventDescriptor
{
public MockEventDescriptor(string name)
Expand Down
Loading