Browse Source

Fix PerspexProperty equality.

pull/223/head
Steven Kirk 11 years ago
parent
commit
559a8c951b
  1. 15
      src/Perspex.Base/PerspexProperty.cs
  2. 16
      tests/Perspex.Base.UnitTests/PerspexObjectTests_Direct.cs
  3. 13
      tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs

15
src/Perspex.Base/PerspexProperty.cs

@ -288,7 +288,18 @@ namespace Perspex
/// <returns>True if the properties are equal, otherwise false.</returns>
public static bool operator ==(PerspexProperty a, PerspexProperty b)
{
return a?.Equals(b) ?? false;
if (object.ReferenceEquals(a, b))
{
return true;
}
else if (((object)a == null) || ((object)b == null))
{
return false;
}
else
{
return a.Equals(b);
}
}
/// <summary>
@ -299,7 +310,7 @@ namespace Perspex
/// <returns>True if the properties are equal, otherwise false.</returns>
public static bool operator !=(PerspexProperty a, PerspexProperty b)
{
return !a?.Equals(b) ?? false;
return !(a == b);
}
/// <summary>

16
tests/Perspex.Base.UnitTests/PerspexObjectTests_Direct.cs

@ -26,6 +26,14 @@ namespace Perspex.Base.UnitTests
Assert.Equal("initial", target.GetValue((PerspexProperty)Class1.FooProperty));
}
[Fact]
public void GetValue_On_Unregistered_Property_Throws_Exception()
{
var target = new Class2();
Assert.Throws<ArgumentException>(() => target.GetValue(Class1.BarProperty));
}
[Fact]
public void SetValue_Sets_Value()
{
@ -80,6 +88,14 @@ namespace Perspex.Base.UnitTests
Assert.True(raised);
}
[Fact]
public void SetValue_On_Unregistered_Property_Throws_Exception()
{
var target = new Class2();
Assert.Throws<ArgumentException>(() => target.SetValue(Class1.BarProperty, "value"));
}
[Fact]
public void GetObservable_Returns_Values()
{

13
tests/Perspex.Base.UnitTests/PerspexPropertyTests.cs

@ -137,6 +137,19 @@ namespace Perspex.Base.UnitTests
Assert.True(target.IsDirect);
}
[Fact]
public void Property_Equals_Should_Handle_Null()
{
var p1 = new PerspexProperty<string>("p1", typeof(Class1));
Assert.NotEqual(p1, null);
Assert.NotEqual(null, p1);
Assert.False(p1 == null);
Assert.False(null == p1);
Assert.False(p1.Equals(null));
Assert.True((PerspexProperty)null == (PerspexProperty)null);
}
[Fact]
public void AddOwnered_Property_Should_Equal_Original()
{

Loading…
Cancel
Save