diff --git a/src/Domain.Abstractions/Entity.cs b/src/Domain.Abstractions/Entity.cs index 3ffbc22f..dcaf4592 100644 --- a/src/Domain.Abstractions/Entity.cs +++ b/src/Domain.Abstractions/Entity.cs @@ -79,7 +79,9 @@ public override int GetHashCode() } else { +#pragma warning disable S3249 return base.GetHashCode(); +#pragma warning restore S3249 } } diff --git a/test/NetCorePal.Extensions.Domain.Abstractions.UnitTests/EntityTests.cs b/test/NetCorePal.Extensions.Domain.Abstractions.UnitTests/EntityTests.cs index f19e6efc..385e75d1 100644 --- a/test/NetCorePal.Extensions.Domain.Abstractions.UnitTests/EntityTests.cs +++ b/test/NetCorePal.Extensions.Domain.Abstractions.UnitTests/EntityTests.cs @@ -98,6 +98,21 @@ public void GetHashCode_Should_Not_Equal_With_Different_With_Id_And_No_Id() Assert.NotEqual(order1.GetHashCode(), order2.GetHashCode()); } + + [Fact] + public void GetHashCode_Should_Equal_Get_Two_Times_With_Id() + { + var order1 = new Order1(1); + Assert.Equal(order1.GetHashCode(), order1.GetHashCode()); + } + + [Fact] + public void GetHashCode_Should_Equal_Get_Two_Times_With_No_Id() + { + var order1 = new Order1(); + Assert.Equal(order1.GetHashCode(), order1.GetHashCode()); + } + public class Order1 : Entity { public Order1()