Browse Source

Added failing test.

feature/typed-binding-2
Steven Kirk 4 years ago
parent
commit
30814ccde7
  1. 26
      tests/Avalonia.Base.UnitTests/Data/Core/TypedBindingExpressionTests_Property.cs
  2. 9
      tests/Avalonia.UnitTests/NotifyingBase.cs

26
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<object>();
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()
{

9
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)
{

Loading…
Cancel
Save