Fixed minor bug where ProtocolList.Clear() would trigger a CollectionChanged event even when no items were removed (list already empty)

This commit is contained in:
David Sparer
2016-10-05 12:43:27 -06:00
parent c471f621b2
commit 3e47041820
2 changed files with 15 additions and 3 deletions

View File

@@ -159,12 +159,22 @@ namespace mRemoteNGTests.Connection.Protocol
}
[Test]
public void ClearRaisesCollectionChangedEventWithCorrectAction()
public void ClearRaisesCollectionChangedEvent()
{
var eventWasCalled = false;
_protocolList.Add(_protocol1);
_protocolList.CollectionChanged += (sender, args) => eventWasCalled = true;
_protocolList.Clear();
Assert.That(eventWasCalled);
}
[Test]
public void ClearDoesntRaiseCollectionChangedEventWhenNoObjectsRemoved()
{
var eventWasCalled = false;
_protocolList.CollectionChanged += (sender, args) => eventWasCalled = true;
_protocolList.Clear();
Assert.That(eventWasCalled);
Assert.That(eventWasCalled == false);
}
[Test]
@@ -199,9 +209,10 @@ namespace mRemoteNGTests.Connection.Protocol
public void ClearCollectionChangedEventHasCorrectAction()
{
NotifyCollectionChangedAction collectionChangedAction = NotifyCollectionChangedAction.Move;
_protocolList.Add(_protocol1);
_protocolList.CollectionChanged += (sender, args) => collectionChangedAction = args.Action;
_protocolList.Clear();
Assert.That(collectionChangedAction == NotifyCollectionChangedAction.Reset);
Assert.That(collectionChangedAction, Is.EqualTo(NotifyCollectionChangedAction.Reset));
}
}
}

View File

@@ -52,6 +52,7 @@ namespace mRemoteNG.Connection.Protocol
public new void Clear()
{
if (Count == 0) return;
List.Clear();
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}