csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
87 lines
2.5 KiB
// Copyright (c) The Perspex Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System;
|
|
using Perspex.Data;
|
|
using Xunit;
|
|
|
|
namespace Perspex.Base.UnitTests
|
|
{
|
|
public class DirectPropertyTests
|
|
{
|
|
[Fact]
|
|
public void Initialized_Observable_Fired()
|
|
{
|
|
bool invoked = false;
|
|
|
|
Class1.FooProperty.Initialized.Subscribe(x =>
|
|
{
|
|
Assert.Equal(PerspexProperty.UnsetValue, x.OldValue);
|
|
Assert.Equal("foo", x.NewValue);
|
|
Assert.Equal(BindingPriority.Unset, x.Priority);
|
|
invoked = true;
|
|
});
|
|
|
|
var target = new Class1();
|
|
|
|
Assert.True(invoked);
|
|
}
|
|
|
|
[Fact]
|
|
public void IsDirect_Property_Returns_True()
|
|
{
|
|
var target = new DirectProperty<Class1, string>("test", o => null);
|
|
|
|
Assert.True(target.IsDirect);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddOwnered_Property_Should_Equal_Original()
|
|
{
|
|
var p1 = Class1.FooProperty;
|
|
var p2 = p1.AddOwner<Class2>(o => null, (o, v) => { });
|
|
|
|
Assert.NotSame(p1, p2);
|
|
Assert.True(p1.Equals(p2));
|
|
Assert.Equal(p1.GetHashCode(), p2.GetHashCode());
|
|
Assert.True(p1 == p2);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddOwnered_Property_Should_Have_OwnerType_Set()
|
|
{
|
|
var p1 = Class1.FooProperty;
|
|
var p2 = p1.AddOwner<Class2>(o => null, (o, v) => { });
|
|
|
|
Assert.Equal(typeof(Class2), p2.OwnerType);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddOwnered_Properties_Should_Share_Observables()
|
|
{
|
|
var p1 = Class1.FooProperty;
|
|
var p2 = p1.AddOwner<Class2>(o => null, (o, v) => { });
|
|
|
|
Assert.Same(p1.Changed, p2.Changed);
|
|
Assert.Same(p1.Initialized, p2.Initialized);
|
|
}
|
|
|
|
private class Class1 : PerspexObject
|
|
{
|
|
public static readonly DirectProperty<Class1, string> FooProperty =
|
|
PerspexProperty.RegisterDirect<Class1, string>("Foo", o => o.Foo, (o, v) => o.Foo = v);
|
|
|
|
private string _foo = "foo";
|
|
|
|
public string Foo
|
|
{
|
|
get { return _foo; }
|
|
set { SetAndRaise(FooProperty, ref _foo, value); }
|
|
}
|
|
}
|
|
|
|
private class Class2 : PerspexObject
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|