Browse Source

Fixing object boxing by using dynamic. Adding tests for equality operator and not equality operator.

af/merge-core
Olivia 10 years ago
parent
commit
4f85227bb1
  1. 44
      tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs

44
tests/ImageSharp.Tests/Colors/ColorEqualityTests.cs

@ -148,8 +148,8 @@ namespace ImageSharp.Tests.Colors
// Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the
// default "object" one :)
var firstObject = Convert.ChangeType(first, type);
var secondObject = Convert.ChangeType(second, type);
dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type);
// Act
var equal = firstObject.Equals(secondObject);
@ -166,8 +166,8 @@ namespace ImageSharp.Tests.Colors
// Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the
// default "object" one :)
var firstObject = Convert.ChangeType(first, type);
var secondObject = Convert.ChangeType(second, type);
dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type);
// Act
var equal = firstObject.Equals(secondObject);
@ -175,5 +175,41 @@ namespace ImageSharp.Tests.Colors
// Assert
Assert.False(equal);
}
[Theory]
[MemberData(nameof(EqualityData))]
public void EqualityOperator(object first, object second, Type type)
{
// Arrange
// Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the
// default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type);
// Act
var equal = firstObject == secondObject;
// Assert
Assert.True(equal);
}
[Theory]
[MemberData(nameof(NotEqualityData))]
public void NotEqualityOperator(object first, object second, Type type)
{
// Arrange
// Cast to the known object types, this is so that we can hit the
// equality operator on the concrete type, otherwise it goes to the
// default "object" one :)
dynamic firstObject = Convert.ChangeType(first, type);
dynamic secondObject = Convert.ChangeType(second, type);
// Act
var notEqual = firstObject != secondObject;
// Assert
Assert.True(notEqual);
}
}
}

Loading…
Cancel
Save