kgrzybek / modular-monolith-with-ddd

Full Modular Monolith application with Domain-Driven Design approach.
MIT License
10.89k stars 1.71k forks source link

TypedIdValueBase Equals Method #235

Open dsteindd opened 2 years ago

dsteindd commented 2 years ago

Hi there,

I noticed that it is possible to have equality of two different implementations of the TypedIdValueBase, if the underlying Guid is the same. I think, this shouldn't be the case, should it?

For example, I would expect this test to turn green:

public class DifferentTypedIdWithSameGuidTests
{
     [Test]
     public void Test()
     {
         var commonId = Guid.NewGuid();

         var firstId = new FirstEntityId(commonId);
         var secondId = new SecondEntityId(commonId);

         Assert.False(firstId.Equals(secondId));
     }
 }

public class FirstEntityId : TypedIdValueBase
{
     public FirstEntityId(Guid value)
         : base(value)
     {
     }
 }

 public class SecondEntityId : TypedIdValueBase
 {
     public SecondEntityId(Guid value)
         : base(value)
     {
     }
 }

Best regards, David