Browse Source

Merge pull request #7430 from AvaloniaUI/avaloniadictionary-remove-fix

Fix AvaloniaDictionary Remove method
pull/7431/head
Benedikt Stebner 4 years ago
committed by GitHub
parent
commit
46bdd2aca1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/Avalonia.Base/Collections/AvaloniaDictionary.cs
  2. 11
      tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs

1
src/Avalonia.Base/Collections/AvaloniaDictionary.cs

@ -146,6 +146,7 @@ namespace Avalonia.Collections
{
if (_inner.TryGetValue(key, out var value))
{
_inner.Remove(key);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs($"Item[{key}]"));

11
tests/Avalonia.Base.UnitTests/Collections/AvaloniaDictionaryTests.cs

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using Avalonia.Collections;
@ -104,6 +105,16 @@ namespace Avalonia.Base.UnitTests.Collections
Assert.Equal(new KeyValuePair<string, string>("foo", "bar"), tracker.Args.OldItems[0]);
}
[Fact]
public void Remove_Method_Should_Remove_Item_From_Collection()
{
var target = new AvaloniaDictionary<string, string>() { { "foo", "bar" } };
Assert.Equal(target.Count, 1);
target.Remove("foo");
Assert.Equal(target.Count, 0);
}
[Fact]
public void Removing_Item_Should_Raise_PropertyChanged()
{

Loading…
Cancel
Save