|
|
@ -11,19 +11,22 @@ using Avalonia.Data; |
|
|
using Avalonia.Markup.Data; |
|
|
using Avalonia.Markup.Data; |
|
|
using Avalonia.UnitTests; |
|
|
using Avalonia.UnitTests; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
namespace Avalonia.Markup.UnitTests.Data |
|
|
namespace Avalonia.Markup.UnitTests.Data |
|
|
{ |
|
|
{ |
|
|
public class ExpressionObserverTests_Property |
|
|
public class ExpressionObserverTests_Property |
|
|
{ |
|
|
{ |
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Get_Simple_Property_Value() |
|
|
public async Task Should_Get_Simple_Property_Value() |
|
|
{ |
|
|
{ |
|
|
var data = new { Foo = "foo" }; |
|
|
var data = new { Foo = "foo" }; |
|
|
var target = new ExpressionObserver(data, "Foo"); |
|
|
var target = new ExpressionObserver(data, "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal("foo", result); |
|
|
Assert.Equal("foo", result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -35,76 +38,92 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
target.Subscribe(_ => { }); |
|
|
target.Subscribe(_ => { }); |
|
|
|
|
|
|
|
|
Assert.Equal(typeof(string), target.ResultType); |
|
|
Assert.Equal(typeof(string), target.ResultType); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Get_Simple_Property_Value_Null() |
|
|
public async Task Should_Get_Simple_Property_Value_Null() |
|
|
{ |
|
|
{ |
|
|
var data = new { Foo = (string)null }; |
|
|
var data = new { Foo = (string)null }; |
|
|
var target = new ExpressionObserver(data, "Foo"); |
|
|
var target = new ExpressionObserver(data, "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Null(result); |
|
|
Assert.Null(result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Get_Simple_Property_From_Base_Class() |
|
|
public async Task Should_Get_Simple_Property_From_Base_Class() |
|
|
{ |
|
|
{ |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var target = new ExpressionObserver(data, "Foo"); |
|
|
var target = new ExpressionObserver(data, "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal("foo", result); |
|
|
Assert.Equal("foo", result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Return_UnsetValue_For_Root_Null() |
|
|
public async Task Should_Return_UnsetValue_For_Root_Null() |
|
|
{ |
|
|
{ |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var target = new ExpressionObserver(default(object), "Foo"); |
|
|
var target = new ExpressionObserver(default(object), "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Return_UnsetValue_For_Root_UnsetValue() |
|
|
public async Task Should_Return_UnsetValue_For_Root_UnsetValue() |
|
|
{ |
|
|
{ |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var target = new ExpressionObserver(AvaloniaProperty.UnsetValue, "Foo"); |
|
|
var target = new ExpressionObserver(AvaloniaProperty.UnsetValue, "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Return_UnsetValue_For_Observable_Root_Null() |
|
|
public async Task Should_Return_UnsetValue_For_Observable_Root_Null() |
|
|
{ |
|
|
{ |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var target = new ExpressionObserver(Observable.Return(default(object)), "Foo"); |
|
|
var target = new ExpressionObserver(Observable.Return(default(object)), "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Return_UnsetValue_For_Observable_Root_UnsetValue() |
|
|
public async Task Should_Return_UnsetValue_For_Observable_Root_UnsetValue() |
|
|
{ |
|
|
{ |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var data = new Class3 { Foo = "foo" }; |
|
|
var target = new ExpressionObserver(Observable.Return(AvaloniaProperty.UnsetValue), "Foo"); |
|
|
var target = new ExpressionObserver(Observable.Return(AvaloniaProperty.UnsetValue), "Foo"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
Assert.Equal(AvaloniaProperty.UnsetValue, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Get_Simple_Property_Chain() |
|
|
public async Task Should_Get_Simple_Property_Chain() |
|
|
{ |
|
|
{ |
|
|
var data = new { Foo = new { Bar = new { Baz = "baz" } } }; |
|
|
var data = new { Foo = new { Bar = new { Baz = "baz" } } }; |
|
|
var target = new ExpressionObserver(data, "Foo.Bar.Baz"); |
|
|
var target = new ExpressionObserver(data, "Foo.Bar.Baz"); |
|
|
var result = await target.Take(1); |
|
|
var result = await target.Take(1); |
|
|
|
|
|
|
|
|
Assert.Equal("baz", result); |
|
|
Assert.Equal("baz", result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -116,10 +135,12 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
target.Subscribe(_ => { }); |
|
|
target.Subscribe(_ => { }); |
|
|
|
|
|
|
|
|
Assert.Equal(typeof(string), target.ResultType); |
|
|
Assert.Equal(typeof(string), target.ResultType); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async void Should_Return_BindingNotification_Error_For_Broken_Chain() |
|
|
public async Task Should_Return_BindingNotification_Error_For_Broken_Chain() |
|
|
{ |
|
|
{ |
|
|
var data = new { Foo = new { Bar = 1 } }; |
|
|
var data = new { Foo = new { Bar = 1 } }; |
|
|
var target = new ExpressionObserver(data, "Foo.Bar.Baz"); |
|
|
var target = new ExpressionObserver(data, "Foo.Bar.Baz"); |
|
|
@ -131,6 +152,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
new BindingNotification( |
|
|
new BindingNotification( |
|
|
new MissingMemberException("Could not find CLR property 'Baz' on '1'"), BindingErrorType.Error), |
|
|
new MissingMemberException("Could not find CLR property 'Baz' on '1'"), BindingErrorType.Error), |
|
|
result); |
|
|
result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -151,6 +174,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
AvaloniaProperty.UnsetValue), |
|
|
AvaloniaProperty.UnsetValue), |
|
|
}, |
|
|
}, |
|
|
result); |
|
|
result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -160,6 +185,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
var target = new ExpressionObserver(data, "Foo.Bar.Baz"); |
|
|
var target = new ExpressionObserver(data, "Foo.Bar.Baz"); |
|
|
|
|
|
|
|
|
Assert.Null(target.ResultType); |
|
|
Assert.Null(target.ResultType); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -177,6 +204,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
sub.Dispose(); |
|
|
sub.Dispose(); |
|
|
|
|
|
|
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -205,6 +234,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
sub.Dispose(); |
|
|
sub.Dispose(); |
|
|
|
|
|
|
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -224,6 +255,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
|
|
|
|
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -245,6 +278,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, old.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, old.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -286,6 +321,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, old.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, old.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -318,6 +355,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.Next.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, breaking.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, breaking.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, old.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, old.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -334,6 +373,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
update.OnNext(Unit.Default); |
|
|
update.OnNext(Unit.Default); |
|
|
|
|
|
|
|
|
Assert.Equal(new[] { "foo", "bar" }, result); |
|
|
Assert.Equal(new[] { "foo", "bar" }, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -374,6 +415,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
Assert.Equal(new[] { "foo", "bar" }, result1); |
|
|
Assert.Equal(new[] { "foo", "bar" }, result1); |
|
|
Assert.Equal(new[] { "foo", "bar" }, result2); |
|
|
Assert.Equal(new[] { "foo", "bar" }, result2); |
|
|
Assert.Equal(new[] { "bar" }, result3); |
|
|
Assert.Equal(new[] { "bar" }, result3); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -391,6 +434,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
sub2.Dispose(); |
|
|
sub2.Dispose(); |
|
|
|
|
|
|
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, data.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -405,6 +450,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Assert.Equal("bar", data.Foo); |
|
|
Assert.Equal("bar", data.Foo); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -419,6 +466,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Assert.Equal("baz", ((Class2)data.Next).Bar); |
|
|
Assert.Equal("baz", ((Class2)data.Next).Bar); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -431,6 +480,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
{ |
|
|
{ |
|
|
Assert.False(target.SetValue("baz")); |
|
|
Assert.False(target.SetValue("baz")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -444,6 +495,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
target.SetValue("bar"); |
|
|
target.SetValue("bar"); |
|
|
|
|
|
|
|
|
Assert.Equal(new[] { null, "bar" }, result); |
|
|
Assert.Equal(new[] { null, "bar" }, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -457,6 +510,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
target.SetValue("bar"); |
|
|
target.SetValue("bar"); |
|
|
|
|
|
|
|
|
Assert.Equal(new[] { null, "bar" }, result); |
|
|
Assert.Equal(new[] { null, "bar" }, result); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -469,6 +524,8 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
{ |
|
|
{ |
|
|
Assert.False(target.SetValue("baz")); |
|
|
Assert.False(target.SetValue("baz")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -498,6 +555,9 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
|
|
|
|
|
|
Assert.Equal(0, first.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, first.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, second.PropertyChangedSubscriptionCount); |
|
|
Assert.Equal(0, second.PropertyChangedSubscriptionCount); |
|
|
|
|
|
|
|
|
|
|
|
GC.KeepAlive(first); |
|
|
|
|
|
GC.KeepAlive(second); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
|