/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Id != null) { hashCode = hashCode * 59 + Id.GetHashCode(); } if (Brand != null) { hashCode = hashCode * 59 + Brand.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (Horsepower != null) { hashCode = hashCode * 59 + Horsepower.GetHashCode(); } if (Consumption != null) { hashCode = hashCode * 59 + Consumption.GetHashCode(); } if (Priceperday != null) { hashCode = hashCode * 59 + Priceperday.GetHashCode(); } return(hashCode); } }
public void ConsumptionsWithEqualValueShouldHaveEqualHashCode(int value) { Consumption first = Consumption.Create(value); Consumption second = Consumption.Create(value); Assert.That(first.GetHashCode(), Is.EqualTo( second.GetHashCode())); }
public void ConsumptionsWithDifferentValueShouldHaveDifferentHashCode( int firstValue, int secondValue) { Consumption first = Consumption.Create(firstValue); Consumption second = Consumption.Create(secondValue); Assert.That(first.GetHashCode(), Is.Not.EqualTo( second.GetHashCode())); }