mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
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:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ namespace mRemoteNG.Connection.Protocol
|
||||
|
||||
public new void Clear()
|
||||
{
|
||||
if (Count == 0) return;
|
||||
List.Clear();
|
||||
RaiseCollectionChangedEvent(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user