Browse Source

ImageProperty is no longer a struct and added unit tests for equality.

Former-commit-id: e140d562a45ef0dc7fa3e1e5dfc3ec330040b696
Former-commit-id: 9256abfb4eca778a2051d32edc198979bd359de2
Former-commit-id: 0076f821040d894bb10e923c4a5a370932eae48b
af/merge-core
dirk 10 years ago
parent
commit
06e2f0eb8f
  1. 22
      src/ImageProcessorCore/Image/ImageProperty.cs
  2. 52
      tests/ImageProcessorCore.Tests/Image/ImagePropertyTests.cs

22
src/ImageProcessorCore/Image/ImageProperty.cs

@ -12,7 +12,7 @@ namespace ImageProcessorCore
/// the copyright information, the date, where the image was created
/// or some other information.
/// </summary>
public struct ImageProperty : IEquatable<ImageProperty>
public class ImageProperty : IEquatable<ImageProperty>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageProperty"/> struct.
@ -56,7 +56,7 @@ namespace ImageProcessorCore
/// </returns>
public static bool operator ==(ImageProperty left, ImageProperty right)
{
return left.Equals(right);
return Equals(left, right);
}
/// <summary>
@ -75,7 +75,7 @@ namespace ImageProcessorCore
/// </returns>
public static bool operator !=(ImageProperty left, ImageProperty right)
{
return !left.Equals(right);
return !Equals(left, right);
}
/// <summary>
@ -90,13 +90,13 @@ namespace ImageProcessorCore
/// </returns>
public override bool Equals(object obj)
{
if (!(obj is ImageProperty))
ImageProperty other = obj as ImageProperty;
if (other == null)
{
return false;
}
ImageProperty other = (ImageProperty)obj;
return other.Name == this.Name && other.Value == this.Value;
}
@ -136,6 +136,16 @@ namespace ImageProcessorCore
/// <param name="other">An object to compare with this object.</param>
public bool Equals(ImageProperty other)
{
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return this.Name.Equals(other.Name) && this.Value.Equals(other.Value);
}
}

52
tests/ImageProcessorCore.Tests/Image/ImagePropertyTests.cs

@ -0,0 +1,52 @@
// <copyright file="ColorConversionTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Tests
{
using Xunit;
/// <summary>
/// Tests the <see cref="ImageProperty"/> class.
/// </summary>
public class ImagePropertyTests
{
/// <summary>
/// Tests the equality operators for inequality.
/// </summary>
[Fact]
public void AreEqual()
{
ImageProperty property1 = new ImageProperty("Foo", "Bar");
ImageProperty property2 = new ImageProperty("Foo", "Bar");
ImageProperty property3 = null;
Assert.Equal(property1, property2);
Assert.True(property1 == property2);
Assert.Equal(property3, null);
}
/// <summary>
/// Tests the equality operators for equality.
/// </summary>
[Fact]
public void AreNotEqual()
{
ImageProperty property1 = new ImageProperty("Foo", "Bar");
ImageProperty property2 = new ImageProperty("Foo", "Foo");
ImageProperty property3 = new ImageProperty("Bar", "Bar");
Assert.False(property1.Equals("Foo"));
Assert.NotEqual(property1, null);
Assert.NotEqual(property1, property2);
Assert.True(property1 != property2);
Assert.NotEqual(property1, property3);
Assert.True(property1 != property3);
}
}
}
Loading…
Cancel
Save