|
|
@@ -1,11 +1,12 @@
|
|
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
+using Avalonia.Utilities;
|
|
|
+using Moq;
|
|
|
using System;
|
|
|
using System.Linq;
|
|
|
using System.Reactive.Linq;
|
|
|
using System.Reactive.Subjects;
|
|
|
-using Moq;
|
|
|
using Xunit;
|
|
|
|
|
|
namespace Avalonia.Base.UnitTests
|
|
|
@@ -21,7 +22,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Initial_Value_Should_Be_UnsetValue()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
Assert.Same(AvaloniaProperty.UnsetValue, target.Value);
|
|
|
}
|
|
|
@@ -29,7 +30,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void First_Binding_Sets_Value()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
|
|
|
@@ -39,7 +40,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Changing_Binding_Should_Set_Value()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var subject = new BehaviorSubject<string>("foo");
|
|
|
|
|
|
target.Add(subject, 0);
|
|
|
@@ -51,7 +52,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Setting_Direct_Value_Should_Override_Binding()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
target.SetValue("bar", 0);
|
|
|
@@ -62,7 +63,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Binding_Firing_Should_Override_Direct_Value()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var source = new BehaviorSubject<object>("initial");
|
|
|
|
|
|
target.Add(source, 0);
|
|
|
@@ -76,7 +77,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Earlier_Binding_Firing_Should_Not_Override_Later()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var nonActive = new BehaviorSubject<object>("na");
|
|
|
var source = new BehaviorSubject<object>("initial");
|
|
|
|
|
|
@@ -92,7 +93,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Binding_Completing_Should_Revert_To_Direct_Value()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var source = new BehaviorSubject<object>("initial");
|
|
|
|
|
|
target.Add(source, 0);
|
|
|
@@ -108,7 +109,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Binding_With_Lower_Priority_Has_Precedence()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 1);
|
|
|
target.Add(Single("bar"), 0);
|
|
|
@@ -120,7 +121,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Later_Binding_With_Same_Priority_Should_Take_Precedence()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 1);
|
|
|
target.Add(Single("bar"), 0);
|
|
|
@@ -133,7 +134,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Changing_Binding_With_Lower_Priority_Should_Set_Not_Value()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var subject = new BehaviorSubject<string>("bar");
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
@@ -146,7 +147,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void UnsetValue_Should_Fall_Back_To_Next_Binding()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var subject = new BehaviorSubject<object>("bar");
|
|
|
|
|
|
target.Add(subject, 0);
|
|
|
@@ -162,7 +163,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Adding_Value_Should_Call_OnNext()
|
|
|
{
|
|
|
- var owner = new Mock<IPriorityValueOwner>();
|
|
|
+ var owner = GetMockOwner();
|
|
|
var target = new PriorityValue(owner.Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
@@ -173,7 +174,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Changing_Value_Should_Call_OnNext()
|
|
|
{
|
|
|
- var owner = new Mock<IPriorityValueOwner>();
|
|
|
+ var owner = GetMockOwner();
|
|
|
var target = new PriorityValue(owner.Object, TestProperty, typeof(string));
|
|
|
var subject = new BehaviorSubject<object>("foo");
|
|
|
|
|
|
@@ -186,7 +187,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Disposing_A_Binding_Should_Revert_To_Next_Value()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
var disposable = target.Add(Single("bar"), 0);
|
|
|
@@ -199,7 +200,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Disposing_A_Binding_Should_Remove_BindingEntry()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
var disposable = target.Add(Single("bar"), 0);
|
|
|
@@ -212,7 +213,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Completing_A_Binding_Should_Revert_To_Previous_Binding()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var source = new BehaviorSubject<object>("bar");
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
@@ -226,7 +227,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Completing_A_Binding_Should_Revert_To_Lower_Priority()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var source = new BehaviorSubject<object>("bar");
|
|
|
|
|
|
target.Add(Single("foo"), 1);
|
|
|
@@ -240,7 +241,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Completing_A_Binding_Should_Remove_BindingEntry()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(string));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(string));
|
|
|
var subject = new BehaviorSubject<object>("bar");
|
|
|
|
|
|
target.Add(Single("foo"), 0);
|
|
|
@@ -254,7 +255,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Direct_Value_Should_Be_Coerced()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(int), x => Math.Min((int)x, 10));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(int), x => Math.Min((int)x, 10));
|
|
|
|
|
|
target.SetValue(5, 0);
|
|
|
Assert.Equal(5, target.Value);
|
|
|
@@ -265,7 +266,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
[Fact]
|
|
|
public void Bound_Value_Should_Be_Coerced()
|
|
|
{
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(int), x => Math.Min((int)x, 10));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(int), x => Math.Min((int)x, 10));
|
|
|
var source = new Subject<object>();
|
|
|
|
|
|
target.Add(source, 0);
|
|
|
@@ -279,7 +280,7 @@ namespace Avalonia.Base.UnitTests
|
|
|
public void Revalidate_Should_ReCoerce_Value()
|
|
|
{
|
|
|
var max = 10;
|
|
|
- var target = new PriorityValue(null, TestProperty, typeof(int), x => Math.Min((int)x, max));
|
|
|
+ var target = new PriorityValue(GetMockOwner().Object, TestProperty, typeof(int), x => Math.Min((int)x, max));
|
|
|
var source = new Subject<object>();
|
|
|
|
|
|
target.Add(source, 0);
|
|
|
@@ -302,5 +303,12 @@ namespace Avalonia.Base.UnitTests
|
|
|
{
|
|
|
return Observable.Never<T>().StartWith(value);
|
|
|
}
|
|
|
+
|
|
|
+ private static Mock<IPriorityValueOwner> GetMockOwner()
|
|
|
+ {
|
|
|
+ var owner = new Mock<IPriorityValueOwner>();
|
|
|
+ owner.SetupGet(o => o.Setter).Returns(new DeferredSetter<object>());
|
|
|
+ return owner;
|
|
|
+ }
|
|
|
}
|
|
|
}
|