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.
104 lines
3.2 KiB
104 lines
3.2 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="PerspexObjectTests_Inheritance.cs" company="Steven Kirk">
|
|
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Base.UnitTests
|
|
{
|
|
using Xunit;
|
|
|
|
public class PerspexObjectTests_Inheritance
|
|
{
|
|
[Fact]
|
|
public void GetValue_Returns_Inherited_Value()
|
|
{
|
|
Class1 parent = new Class1();
|
|
Class2 child = new Class2 { Parent = parent };
|
|
|
|
parent.SetValue(Class1.BazProperty, "changed");
|
|
|
|
Assert.Equal("changed", child.GetValue(Class1.BazProperty));
|
|
}
|
|
|
|
[Fact]
|
|
public void Setting_InheritanceParent_Raises_PropertyChanged_When_Value_Changed_In_Parent()
|
|
{
|
|
bool raised = false;
|
|
|
|
Class1 parent = new Class1();
|
|
parent.SetValue(Class1.BazProperty, "changed");
|
|
|
|
Class2 child = new Class2();
|
|
child.PropertyChanged += (s, e) =>
|
|
raised = s == child &&
|
|
e.Property == Class1.BazProperty &&
|
|
(string)e.OldValue == "bazdefault" &&
|
|
(string)e.NewValue == "changed";
|
|
|
|
child.Parent = parent;
|
|
|
|
Assert.True(raised);
|
|
}
|
|
|
|
[Fact]
|
|
public void Setting_InheritanceParent_Doesnt_Raise_PropertyChanged_When_Local_Value_Set()
|
|
{
|
|
bool raised = false;
|
|
|
|
Class1 parent = new Class1();
|
|
parent.SetValue(Class1.BazProperty, "changed");
|
|
|
|
Class2 child = new Class2();
|
|
child.SetValue(Class1.BazProperty, "localvalue");
|
|
child.PropertyChanged += (s, e) => raised = true;
|
|
|
|
child.Parent = parent;
|
|
|
|
Assert.False(raised);
|
|
}
|
|
|
|
[Fact]
|
|
public void Setting_Value_In_InheritanceParent_Raises_PropertyChanged()
|
|
{
|
|
bool raised = false;
|
|
|
|
Class1 parent = new Class1();
|
|
|
|
Class2 child = new Class2();
|
|
child.PropertyChanged += (s, e) =>
|
|
raised = s == child &&
|
|
e.Property == Class1.BazProperty &&
|
|
(string)e.OldValue == "bazdefault" &&
|
|
(string)e.NewValue == "changed";
|
|
child.Parent = parent;
|
|
|
|
parent.SetValue(Class1.BazProperty, "changed");
|
|
|
|
Assert.True(raised);
|
|
}
|
|
|
|
private class Class1 : PerspexObject
|
|
{
|
|
public static readonly PerspexProperty<string> FooProperty =
|
|
PerspexProperty.Register<Class1, string>("Foo", "foodefault");
|
|
|
|
public static readonly PerspexProperty<string> BazProperty =
|
|
PerspexProperty.Register<Class1, string>("Baz", "bazdefault", true);
|
|
}
|
|
|
|
private class Class2 : Class1
|
|
{
|
|
static Class2()
|
|
{
|
|
FooProperty.OverrideDefaultValue(typeof(Class2), "foooverride");
|
|
}
|
|
|
|
public Class1 Parent
|
|
{
|
|
get { return (Class1)this.InheritanceParent; }
|
|
set { this.InheritanceParent = value; }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|