Index: Core/Components/src/Core.Components.DotSpatial.Forms/WmtsConnectionInfo.cs
===================================================================
diff -u -rcfb8cddfe064c4aa4a1843846968554c918ba58f -r3f2252d8d17eed894f5f37fd7e8abfff6cdcbf74
--- Core/Components/src/Core.Components.DotSpatial.Forms/WmtsConnectionInfo.cs (.../WmtsConnectionInfo.cs) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f)
+++ Core/Components/src/Core.Components.DotSpatial.Forms/WmtsConnectionInfo.cs (.../WmtsConnectionInfo.cs) (revision 3f2252d8d17eed894f5f37fd7e8abfff6cdcbf74)
@@ -26,7 +26,7 @@
///
/// This class defines properties for a WMTS connection.
///
- public class WmtsConnectionInfo
+ public class WmtsConnectionInfo : IEquatable
{
///
/// Creates a new instance of .
@@ -60,5 +60,32 @@
/// Gets the URL.
///
public string Url { get; }
+
+ #region IEquatable members
+
+ public override int GetHashCode()
+ {
+ return GetType().GetHashCode() ^ Name.GetHashCode() ^ Url.GetHashCode();
+ }
+
+ public bool Equals(WmtsConnectionInfo other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Name.Equals(other.Name) && string.Equals(Url, other.Url);
+ }
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as WmtsConnectionInfo);
+ }
+
+ #endregion
}
}
\ No newline at end of file
Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoTest.cs
===================================================================
diff -u -rcfb8cddfe064c4aa4a1843846968554c918ba58f -r3f2252d8d17eed894f5f37fd7e8abfff6cdcbf74
--- Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoTest.cs (.../WmtsConnectionInfoTest.cs) (revision cfb8cddfe064c4aa4a1843846968554c918ba58f)
+++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/IO/WmtsConnectionInfoTest.cs (.../WmtsConnectionInfoTest.cs) (revision 3f2252d8d17eed894f5f37fd7e8abfff6cdcbf74)
@@ -63,5 +63,110 @@
Assert.AreEqual(name, connectionInfo.Name);
Assert.AreEqual(url, connectionInfo.Url);
}
+
+ [Test]
+ public void Equals_ToNull_ReturnFalse()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+
+ // Call
+ var isEqual = info.Equals(null);
+
+ // Assert
+ Assert.IsFalse(isEqual);
+ }
+
+ [Test]
+ public void Equals_ToOtherObject_ReturnFalse()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+
+ // Call
+ var isEqual = info.Equals(new object());
+
+ // Assert
+ Assert.IsFalse(isEqual);
+ }
+
+ [Test]
+ public void Equals_ToItself_ReturnTrue()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+
+ // Call
+ var isEqual = info.Equals(info);
+
+ // Assert
+ Assert.IsTrue(isEqual);
+ }
+
+ [Test]
+ public void Equals_ToOtherWithSameNameDifferentUrl_ReturnsFalse()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+ var other = new WmtsConnectionInfo("name", "otherUrl");
+
+ // Call
+ var isEqual = info.Equals(other);
+ var otherIsEqual = info.Equals(other);
+
+ // Assert
+ Assert.IsFalse(isEqual);
+ Assert.IsFalse(otherIsEqual);
+ }
+
+ [Test]
+ public void Equals_ToOtherWithDifferentNameSameUrl_ReturnsFalse()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+ var other = new WmtsConnectionInfo("otherName", "url");
+
+ // Call
+ var isEqual = info.Equals(other);
+ var otherIsEqual = info.Equals(other);
+
+ // Assert
+ Assert.IsFalse(isEqual);
+ Assert.IsFalse(otherIsEqual);
+ }
+
+ [Test]
+ public void Equals_ToOtherWithSameData_ReturnsTrue()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+ var other = new WmtsConnectionInfo("name", "url");
+
+ // Call
+ var isEqual = info.Equals(other);
+ var otherIsEqual = info.Equals(other);
+
+ // Assert
+ Assert.IsTrue(isEqual);
+ Assert.IsTrue(otherIsEqual);
+ }
+
+ [Test]
+ public void GetHashCode_EqualObjects_ReturnSameHashCode()
+ {
+ // Setup
+ var info = new WmtsConnectionInfo("name", "url");
+ var other = new WmtsConnectionInfo("name", "url");
+
+ // Precondition
+ Assert.AreEqual(info, other);
+
+ // Call
+ int hashCode = info.GetHashCode();
+ int otherHashCode = other.GetHashCode();
+
+ // Assert
+ Assert.AreEqual(hashCode, otherHashCode);
+ }
}
}
\ No newline at end of file