| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // 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
- {
- }
- }
- }
|