Browse Source

Merge pull request #448 from dlemstra/ImageProperty

Changes to ImageProperty

Former-commit-id: 8d835531d3fa0e75831894649d8588cb510089d2
Former-commit-id: bb3bfe919696f309fa0c71f2abc538874db64c99
Former-commit-id: 4a778f352bbd5acd8d66f0e0959385f289c0ef17
af/merge-core
James Jackson-South 10 years ago
committed by GitHub
parent
commit
fb45225681
  1. 35
      src/ImageProcessorCore/Image/ImageProperty.cs
  2. 78
      tests/ImageProcessorCore.Tests/Image/ImagePropertyTests.cs

35
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.
@ -21,6 +21,8 @@ namespace ImageProcessorCore
/// <param name="value">The value of the property.</param>
public ImageProperty(string name, string value)
{
Guard.NotNullOrEmpty(name, nameof(name));
this.Name = name;
this.Value = value;
}
@ -56,7 +58,7 @@ namespace ImageProcessorCore
/// </returns>
public static bool operator ==(ImageProperty left, ImageProperty right)
{
return left.Equals(right);
return Equals(left, right);
}
/// <summary>
@ -75,7 +77,7 @@ namespace ImageProcessorCore
/// </returns>
public static bool operator !=(ImageProperty left, ImageProperty right)
{
return !left.Equals(right);
return !Equals(left, right);
}
/// <summary>
@ -90,14 +92,9 @@ namespace ImageProcessorCore
/// </returns>
public override bool Equals(object obj)
{
if (!(obj is ImageProperty))
{
return false;
}
ImageProperty other = obj as ImageProperty;
ImageProperty other = (ImageProperty)obj;
return other.Name == this.Name && other.Value == this.Value;
return Equals(other);
}
/// <summary>
@ -111,7 +108,11 @@ namespace ImageProcessorCore
unchecked
{
int hashCode = this.Name.GetHashCode();
hashCode = (hashCode * 397) ^ this.Value.GetHashCode();
if (this.Value != null)
{
hashCode = (hashCode * 397) ^ this.Value.GetHashCode();
}
return hashCode;
}
}
@ -136,7 +137,17 @@ namespace ImageProcessorCore
/// <param name="other">An object to compare with this object.</param>
public bool Equals(ImageProperty other)
{
return this.Name.Equals(other.Name) && this.Value.Equals(other.Value);
if (ReferenceEquals(other, null))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return this.Name.Equals(other.Name) && Equals(this.Value, other.Value);
}
}
}

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

@ -0,0 +1,78 @@
// <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 System;
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");
ImageProperty property4 = new ImageProperty("Foo", null);
Assert.False(property1.Equals("Foo"));
Assert.NotEqual(property1, null);
Assert.NotEqual(property1, property2);
Assert.True(property1 != property2);
Assert.NotEqual(property1, property3);
Assert.NotEqual(property1, property4);
}
/// <summary>
/// Tests whether the constructor throws an exception when the property name is null or empty.
/// </summary>
[Fact]
public void ConstructorThrowsWhenNameIsNullOrEmpty()
{
Assert.Throws<ArgumentNullException>(() => new ImageProperty(null, "Foo"));
Assert.Throws<ArgumentException>(() => new ImageProperty(string.Empty, "Foo"));
}
/// <summary>
/// Tests whether the constructor correctly assigns properties.
/// </summary>
[Fact]
public void ConstructorAssignsProperties()
{
ImageProperty property = new ImageProperty("Foo", null);
Assert.Equal("Foo", property.Name);
Assert.Equal(null, property.Value);
property = new ImageProperty("Foo", string.Empty);
Assert.Equal(string.Empty, property.Value);
}
}
}
Loading…
Cancel
Save