From 75926b6dc3657fa537fd4be4c867ffd6046b4b24 Mon Sep 17 00:00:00 2001 From: witskeeper Date: Wed, 21 Feb 2024 12:30:58 +0800 Subject: [PATCH] add more test case ,disable S3249 --- src/Domain.Abstractions/Entity.cs | 2 ++ .../EntityTests.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) 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()