Browse Source

Added failing tests for #3545.

`PropertyChanged` is not being fired when binding is disposed. Also change some other unit tests to ensure that priority passed in event args is correct.
pull/3556/head
Steven Kirk 6 years ago
parent
commit
11a8c01ef1
  1. 105
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs
  2. 1
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs
  3. 1
      tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_SetValue.cs

105
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs

@ -132,6 +132,111 @@ namespace Avalonia.Base.UnitTests
Assert.Equal("foo", target.GetValue(property));
}
[Fact]
public void Completing_LocalValue_Binding_Raises_PropertyChanged()
{
var target = new Class1();
var source = new BehaviorSubject<BindingValue<string>>("foo");
var property = Class1.FooProperty;
var raised = 0;
target.Bind(property, source);
Assert.Equal("foo", target.GetValue(property));
target.PropertyChanged += (s, e) =>
{
Assert.Equal(BindingPriority.Unset, e.Priority);
Assert.Equal(property, e.Property);
Assert.Equal("foo", e.OldValue as string);
Assert.Equal("foodefault", e.NewValue as string);
++raised;
};
source.OnCompleted();
Assert.Equal("foodefault", target.GetValue(property));
Assert.Equal(1, raised);
}
[Fact]
public void Completing_Style_Binding_Raises_PropertyChanged()
{
var target = new Class1();
var source = new BehaviorSubject<BindingValue<string>>("foo");
var property = Class1.FooProperty;
var raised = 0;
target.Bind(property, source, BindingPriority.Style);
Assert.Equal("foo", target.GetValue(property));
target.PropertyChanged += (s, e) =>
{
Assert.Equal(BindingPriority.Unset, e.Priority);
Assert.Equal(property, e.Property);
Assert.Equal("foo", e.OldValue as string);
Assert.Equal("foodefault", e.NewValue as string);
++raised;
};
source.OnCompleted();
Assert.Equal("foodefault", target.GetValue(property));
Assert.Equal(1, raised);
}
[Fact]
public void Completing_LocalValue_Binding_With_Style_Binding_Raises_PropertyChanged()
{
var target = new Class1();
var source = new BehaviorSubject<BindingValue<string>>("foo");
var property = Class1.FooProperty;
var raised = 0;
target.Bind(property, new BehaviorSubject<string>("bar"), BindingPriority.Style);
target.Bind(property, source);
Assert.Equal("foo", target.GetValue(property));
target.PropertyChanged += (s, e) =>
{
Assert.Equal(BindingPriority.Style, e.Priority);
Assert.Equal(property, e.Property);
Assert.Equal("foo", e.OldValue as string);
Assert.Equal("bar", e.NewValue as string);
++raised;
};
source.OnCompleted();
Assert.Equal("bar", target.GetValue(property));
Assert.Equal(1, raised);
}
[Fact]
public void Disposing_LocalValue_Binding_Raises_PropertyChanged()
{
var target = new Class1();
var source = new BehaviorSubject<BindingValue<string>>("foo");
var property = Class1.FooProperty;
var raised = 0;
var sub = target.Bind(property, source);
Assert.Equal("foo", target.GetValue(property));
target.PropertyChanged += (s, e) =>
{
Assert.Equal(BindingPriority.Unset, e.Priority);
Assert.Equal(property, e.Property);
Assert.Equal("foo", e.OldValue as string);
Assert.Equal("foodefault", e.NewValue as string);
++raised;
};
sub.Dispose();
Assert.Equal("foodefault", target.GetValue(property));
Assert.Equal(1, raised);
}
[Fact]
public void Setting_Style_Value_Overrides_Binding_Permanently()
{

1
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Direct.cs

@ -188,6 +188,7 @@ namespace Avalonia.Base.UnitTests
target.PropertyChanged += (s, e) =>
{
Assert.Same(target, s);
Assert.Equal(BindingPriority.LocalValue, e.Priority);
Assert.Equal(Class1.FooProperty, e.Property);
Assert.Equal("newvalue", (string)e.OldValue);
Assert.Equal("unset", (string)e.NewValue);

1
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_SetValue.cs

@ -30,6 +30,7 @@ namespace Avalonia.Base.UnitTests
target.PropertyChanged += (s, e) =>
{
Assert.Same(target, s);
Assert.Equal(BindingPriority.Unset, e.Priority);
Assert.Equal(Class1.FooProperty, e.Property);
Assert.Equal("newvalue", (string)e.OldValue);
Assert.Equal("foodefault", (string)e.NewValue);

Loading…
Cancel
Save