diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs index 8d7f5f37b1..ff6fef3def 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Values/ValueObject.cs @@ -16,21 +16,29 @@ public abstract class ValueObject return false; } - ValueObject other = (ValueObject)obj; + var other = (ValueObject)obj; - IEnumerator thisValues = GetAtomicValues().GetEnumerator(); - IEnumerator otherValues = other.GetAtomicValues().GetEnumerator(); + var thisValues = GetAtomicValues().GetEnumerator(); + var otherValues = other.GetAtomicValues().GetEnumerator(); - while (thisValues.MoveNext() && otherValues.MoveNext()) + var thisMoveNext = thisValues.MoveNext(); + var otherMoveNext = otherValues.MoveNext(); + while (thisMoveNext && otherMoveNext) { - if (ReferenceEquals(thisValues.Current, null) ^ - ReferenceEquals(otherValues.Current, null)) + if (ReferenceEquals(thisValues.Current, null) ^ ReferenceEquals(otherValues.Current, null)) { return false; } - if (thisValues.Current != null && - !thisValues.Current.Equals(otherValues.Current)) + if (thisValues.Current != null && !thisValues.Current.Equals(otherValues.Current)) + { + return false; + } + + thisMoveNext = thisValues.MoveNext(); + otherMoveNext = otherValues.MoveNext(); + + if (thisMoveNext != otherMoveNext) { return false; } diff --git a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/Address.cs b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/Address.cs index 7ec96848a4..cee2c8c379 100644 --- a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/Address.cs +++ b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/Address.cs @@ -11,6 +11,8 @@ public class Address : ValueObject public int Number { get; } + public string[] Tags { get; } + private Address() { } @@ -18,11 +20,13 @@ public class Address : ValueObject public Address( Guid cityId, string street, - int number) + int number, + params string[] tags) { CityId = cityId; Street = street; Number = number; + Tags = tags; } //Requires to implement this method to return properties. @@ -31,5 +35,9 @@ public class Address : ValueObject yield return Street; yield return CityId; yield return Number; + foreach (var tag in Tags) + { + yield return tag; + } } } diff --git a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/ValueObject_Tests.cs b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/ValueObject_Tests.cs index a4a0f9c44f..144d4350d3 100644 --- a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/ValueObject_Tests.cs +++ b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Values/ValueObject_Tests.cs @@ -10,8 +10,9 @@ public class ValueObject_Tests public void ValueObjects_With_Same_Properties_Should_Be_Equals() { var cityId = Guid.NewGuid(); - var address1 = new Address(cityId, "Baris Manco", 42); - var address2 = new Address(cityId, "Baris Manco", 42); + + var address1 = new Address(cityId, "Baris Manco", 42, "home", "office"); + var address2 = new Address(cityId, "Baris Manco", 42, "home", "office"); address1.ValueEquals(address2).ShouldBeTrue(); } @@ -25,5 +26,10 @@ public class ValueObject_Tests var address2 = new Address(cityId, "Baris Manco", 43); address1.ValueEquals(address2).ShouldBeFalse(); + + address1 = new Address(cityId, "Baris Manco", 42, "home", "office"); + address2 = new Address(cityId, "Baris Manco", 42, "home"); + + address1.ValueEquals(address2).ShouldBeFalse(); } }