public void CompareExcludeTimestamp() { var comparer = new KeyComparer(false); var x = new Key(); Assert.IsFalse(comparer.Equals(x, null)); Assert.IsFalse(comparer.Equals(null, x)); var y = new Key(); Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.Row = "A"; y.Row = "B"; Assert.IsFalse(comparer.Equals(x, y)); x.Row = "AB"; y.Row = "AB"; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.ColumnFamily = "A"; y.ColumnFamily = "B"; Assert.IsFalse(comparer.Equals(x, y)); x.ColumnFamily = null; y.ColumnFamily = string.Empty; Assert.IsFalse(comparer.Equals(x, y)); x.ColumnFamily = "AB"; y.ColumnFamily = "AB"; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.ColumnQualifier = "A"; y.ColumnQualifier = "B"; Assert.IsFalse(comparer.Equals(x, y)); x.ColumnQualifier = null; y.ColumnQualifier = string.Empty; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.ColumnQualifier = "AB"; y.ColumnQualifier = "AB"; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc); y.DateTime = new DateTime(2011, 1, 1, 1, 2, 4, DateTimeKind.Utc); Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc); y.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc); Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); }
public override int GetHashCode() { unchecked { var hashCode = KeyComparer?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ (KeyPropertyName?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ IsExtensible.GetHashCode(); return(hashCode); } }
public void WhenDataGiven_ShouldReturnHashCodeOfProperty() { //Arrange var comparer = new KeyComparer<TestPoco, int>(f => f.Id) as IEqualityComparer<TestPoco>; var data = new TestPoco() { Id = 1 }; //Act var result = comparer.GetHashCode(data); //Assert Assert.AreEqual(data.Id.GetHashCode(), result); }
/// <summary> /// Initializes a new instance of the <see cref="EntitySpec" /> class. /// </summary> /// <param name="entityType"> /// The entity type. /// </param> /// <param name="ns"> /// The database namespace. /// </param> /// <param name="tableName"> /// The database table name. /// </param> /// <param name="key"> /// The entity key. /// </param> internal EntitySpec(Type entityType, string ns, string tableName, Key key) { this.entityType = entityType; this.ns = ns; this.tableName = tableName; this.key = key; unchecked { this.hashCode = 17; if (this.key != null) { this.hashCode = (29 * this.hashCode) + KeyComparer.GetHashCode(this.key); } this.hashCode = (31 * this.hashCode) + this.tableName.GetHashCode(); this.hashCode = (37 * this.hashCode) + (this.ns ?? string.Empty).GetHashCode(); } }
public override int GetHashCode() { return(KeyComparer.GetHashCode(this.Name) ^ this.PropertyType.GetHashCode()); }
public int GetHashCode(Tree <D> obj) { return(KeyComparer.GetHashCode(obj.key)); }
public void CompareIncludeTimestamp() { var comparer = new KeyComparer(true); var x = new Key(); Assert.IsFalse(comparer.Equals(x, null)); Assert.IsFalse(comparer.Equals(null, x)); var y = new Key(); Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.Row = "A"; y.Row = "B"; Assert.IsFalse(comparer.Equals(x, y)); x.Row = "AB"; y.Row = "AB"; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.ColumnFamily = "A"; y.ColumnFamily = "B"; Assert.IsFalse(comparer.Equals(x, y)); x.ColumnFamily = null; y.ColumnFamily = string.Empty; Assert.IsFalse(comparer.Equals(x, y)); x.ColumnFamily = "AB"; y.ColumnFamily = "AB"; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.ColumnQualifier = "A"; y.ColumnQualifier = "B"; Assert.IsFalse(comparer.Equals(x, y)); x.ColumnQualifier = null; y.ColumnQualifier = string.Empty; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.ColumnQualifier = "AB"; y.ColumnQualifier = "AB"; Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc); y.DateTime = new DateTime(2011, 1, 1, 1, 2, 4, DateTimeKind.Utc); Assert.IsFalse(comparer.Equals(x, y)); x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc); y.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc); Assert.IsTrue(comparer.Equals(x, y)); Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y)); }