diff --git a/tests/Avalonia.Base.UnitTests/Data/Core/TypedBindingExpressionTests_Property.cs b/tests/Avalonia.Base.UnitTests/Data/Core/TypedBindingExpressionTests_Property.cs index 8488fec2f5..671453945e 100644 --- a/tests/Avalonia.Base.UnitTests/Data/Core/TypedBindingExpressionTests_Property.cs +++ b/tests/Avalonia.Base.UnitTests/Data/Core/TypedBindingExpressionTests_Property.cs @@ -267,6 +267,32 @@ namespace Avalonia.Base.UnitTests.Data.Core GC.KeepAlive(data); } + [Fact] + public void Should_Ignore_Unrelated_Property_Changes() + { + var data = new Class1 { Next = new Class2 { Bar = "bar" } }; + var binding = TypedBindingExpression.OneWay(data, o => (o.Next as Class2).Bar); + var result = new List(); + + binding.Subscribe(x => result.Add(x.Value)); + + Assert.Equal(1, data.PropertyChangedSubscriptionCount); + Assert.Equal(1, data.Next.PropertyChangedSubscriptionCount); + Assert.Equal(1, data.PropertyChangedGeneration); + Assert.Equal(1, ((Class2)data.Next).PropertyChangedGeneration); + Assert.Equal(new[] { "bar" }, result); + + data.Foo = "unrelated"; + + Assert.Equal(1, data.PropertyChangedSubscriptionCount); + Assert.Equal(1, data.Next.PropertyChangedSubscriptionCount); + Assert.Equal(1, data.PropertyChangedGeneration); + Assert.Equal(1, ((Class2)data.Next).PropertyChangedGeneration); + Assert.Equal(new[] { "bar" }, result); + + GC.KeepAlive(data); + } + [Fact] public void Empty_Expression_Should_Track_Root() { diff --git a/tests/Avalonia.UnitTests/NotifyingBase.cs b/tests/Avalonia.UnitTests/NotifyingBase.cs index 9542e023d5..7353bb303c 100644 --- a/tests/Avalonia.UnitTests/NotifyingBase.cs +++ b/tests/Avalonia.UnitTests/NotifyingBase.cs @@ -14,6 +14,7 @@ namespace Avalonia.UnitTests { _propertyChanged += value; ++PropertyChangedSubscriptionCount; + ++PropertyChangedGeneration; } remove @@ -22,15 +23,13 @@ namespace Avalonia.UnitTests { _propertyChanged -= value; --PropertyChangedSubscriptionCount; + ++PropertyChangedGeneration; } } } - public int PropertyChangedSubscriptionCount - { - get; - private set; - } + public int PropertyChangedGeneration { get; private set; } + public int PropertyChangedSubscriptionCount { get; private set; } public void RaisePropertyChanged([CallerMemberName] string propertyName = null) {