|
|
@ -4,13 +4,13 @@ using System.Reactive.Linq; |
|
|
using System.Reactive.Subjects; |
|
|
using System.Reactive.Subjects; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Avalonia.Base.UnitTests.Styling; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Data; |
|
|
using Avalonia.Data; |
|
|
using Avalonia.Logging; |
|
|
using Avalonia.Logging; |
|
|
using Avalonia.Platform; |
|
|
using Avalonia.Platform; |
|
|
using Avalonia.Threading; |
|
|
using Avalonia.Threading; |
|
|
using Avalonia.UnitTests; |
|
|
using Avalonia.UnitTests; |
|
|
using Microsoft.Reactive.Testing; |
|
|
|
|
|
using Moq; |
|
|
using Moq; |
|
|
using Xunit; |
|
|
using Xunit; |
|
|
|
|
|
|
|
|
@ -489,17 +489,14 @@ namespace Avalonia.Base.UnitTests |
|
|
[Fact] |
|
|
[Fact] |
|
|
public void Observable_Is_Unsubscribed_When_Subscription_Disposed() |
|
|
public void Observable_Is_Unsubscribed_When_Subscription_Disposed() |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
var subscription = target.Bind(Class1.FooProperty, source); |
|
|
var subscription = target.Bind(Class1.FooProperty, source); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(1, source.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
subscription.Dispose(); |
|
|
subscription.Dispose(); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(0, source.SubscriberCount); |
|
|
Assert.Equal(0, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
@ -508,40 +505,32 @@ namespace Avalonia.Base.UnitTests |
|
|
[InlineData(BindingPriority.Animation)] |
|
|
[InlineData(BindingPriority.Animation)] |
|
|
public void Observable_Is_Unsubscribed_When_New_Binding_Of_Same_Priority_Is_Added(BindingPriority priority) |
|
|
public void Observable_Is_Unsubscribed_When_New_Binding_Of_Same_Priority_Is_Added(BindingPriority priority) |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source1 = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source1 = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
var source2 = new TestSubject<BindingValue<string>>("bar"); |
|
|
var source2 = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source1, priority); |
|
|
target.Bind(Class1.FooProperty, source1, priority); |
|
|
Assert.Equal(1, source1.Subscriptions.Count); |
|
|
Assert.Equal(1, source1.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source1.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source2, priority); |
|
|
target.Bind(Class1.FooProperty, source2, priority); |
|
|
Assert.Equal(1, source2.Subscriptions.Count); |
|
|
Assert.Equal(1, source2.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source2.Subscriptions[0].Unsubscribe); |
|
|
Assert.Equal(0, source1.SubscriberCount); |
|
|
Assert.Equal(1, source1.Subscriptions.Count); |
|
|
|
|
|
Assert.Equal(0, source1.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
[InlineData(BindingPriority.Style)] |
|
|
[InlineData(BindingPriority.Style)] |
|
|
public void Observable_Is_Unsubscribed_When_New_Binding_Of_Higher_Priority_Is_Added(BindingPriority priority) |
|
|
public void Observable_Is_Unsubscribed_When_New_Binding_Of_Higher_Priority_Is_Added(BindingPriority priority) |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source1 = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source1 = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
var source2 = new TestSubject<BindingValue<string>>("bar"); |
|
|
var source2 = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source1, priority); |
|
|
target.Bind(Class1.FooProperty, source1, priority); |
|
|
Assert.Equal(1, source1.Subscriptions.Count); |
|
|
Assert.Equal(1, source1.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source1.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source2, priority - 1); |
|
|
target.Bind(Class1.FooProperty, source2, priority - 1); |
|
|
Assert.Equal(1, source2.Subscriptions.Count); |
|
|
Assert.Equal(1, source2.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source2.Subscriptions[0].Unsubscribe); |
|
|
Assert.Equal(0, source1.SubscriberCount); |
|
|
Assert.Equal(1, source1.Subscriptions.Count); |
|
|
|
|
|
Assert.Equal(0, source1.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
@ -549,34 +538,28 @@ namespace Avalonia.Base.UnitTests |
|
|
[InlineData(BindingPriority.Animation)] |
|
|
[InlineData(BindingPriority.Animation)] |
|
|
public void Observable_Is_Unsubscribed_When_New_Value_Of_Same_Priority_Is_Added(BindingPriority priority) |
|
|
public void Observable_Is_Unsubscribed_When_New_Value_Of_Same_Priority_Is_Added(BindingPriority priority) |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source, priority); |
|
|
target.Bind(Class1.FooProperty, source, priority); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(1, source.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
target.SetValue(Class1.FooProperty, "foo", priority); |
|
|
target.SetValue(Class1.FooProperty, "foo", priority); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(0, source.SubscriberCount); |
|
|
Assert.Equal(0, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
[InlineData(BindingPriority.Style)] |
|
|
[InlineData(BindingPriority.Style)] |
|
|
public void Observable_Is_Unsubscribed_When_New_Value_Of_Higher_Priority_Is_Added(BindingPriority priority) |
|
|
public void Observable_Is_Unsubscribed_When_New_Value_Of_Higher_Priority_Is_Added(BindingPriority priority) |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source, priority); |
|
|
target.Bind(Class1.FooProperty, source, priority); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(1, source.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
target.SetValue(Class1.FooProperty, "foo", priority - 1); |
|
|
target.SetValue(Class1.FooProperty, "foo", priority - 1); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(0, source.SubscriberCount); |
|
|
Assert.Equal(0, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
@ -584,36 +567,29 @@ namespace Avalonia.Base.UnitTests |
|
|
[InlineData(BindingPriority.Style)] |
|
|
[InlineData(BindingPriority.Style)] |
|
|
public void Observable_Is_Not_Unsubscribed_When_Animation_Binding_Is_Added(BindingPriority priority) |
|
|
public void Observable_Is_Not_Unsubscribed_When_Animation_Binding_Is_Added(BindingPriority priority) |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source1 = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source1 = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
var source2 = new TestSubject<BindingValue<string>>("bar"); |
|
|
var source2 = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source1, priority); |
|
|
target.Bind(Class1.FooProperty, source1, priority); |
|
|
Assert.Equal(1, source1.Subscriptions.Count); |
|
|
Assert.Equal(1, source1.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source1.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source2, BindingPriority.Animation); |
|
|
target.Bind(Class1.FooProperty, source2, BindingPriority.Animation); |
|
|
Assert.Equal(1, source2.Subscriptions.Count); |
|
|
Assert.Equal(1, source1.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source2.Subscriptions[0].Unsubscribe); |
|
|
Assert.Equal(1, source2.SubscriberCount); |
|
|
Assert.Equal(1, source1.Subscriptions.Count); |
|
|
|
|
|
Assert.Equal(Subscription.Infinite, source1.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public void LocalValue_Binding_Is_Not_Unsubscribed_When_LocalValue_Is_Set() |
|
|
public void LocalValue_Binding_Is_Not_Unsubscribed_When_LocalValue_Is_Set() |
|
|
{ |
|
|
{ |
|
|
var scheduler = new TestScheduler(); |
|
|
var source = new TestSubject<BindingValue<string>>("foo"); |
|
|
var source = scheduler.CreateColdObservable<BindingValue<string>>(); |
|
|
|
|
|
var target = new Class1(); |
|
|
var target = new Class1(); |
|
|
|
|
|
|
|
|
target.Bind(Class1.FooProperty, source); |
|
|
target.Bind(Class1.FooProperty, source); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(1, source.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
|
|
|
|
|
|
target.SetValue(Class1.FooProperty, "foo"); |
|
|
target.SetValue(Class1.FooProperty, "foo"); |
|
|
Assert.Equal(1, source.Subscriptions.Count); |
|
|
Assert.Equal(1, source.SubscriberCount); |
|
|
Assert.Equal(Subscription.Infinite, source.Subscriptions[0].Unsubscribe); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
|