boujnah5207 / sharp-architecture

Automatically exported from code.google.com/p/sharp-architecture
Other
0 stars 0 forks source link

Overload == and != for ValueObject #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The test:
        [Test]
        public void Equality_DifferentReferences_SameValues_True() {
            var vo1 = new DummyValueType { Id = 1, Name = "Luis" };
            var vo2 = new DummyValueType { Id = 1, Name = "Luis" };
            Assert.That(vo1, Is.Not.SameAs(vo2));
            Assert.That(vo1, Is.EqualTo(vo2));
            Assert.That(vo1.Equals(vo2));
            //Assert.That(vo1 == vo2);  --------------> FAIL, NOT
IMPLEMENTED
        } 

The fix:

        /// <summary>op==</summary>
        public static bool operator ==(ValueObject lhs, ValueObject
rhs) {
            if ((object) lhs == null) return (object) rhs == null;
            return lhs.Equals(rhs);
        }

        /// <summary>op!=</summary>
        public static bool operator !=(ValueObject lhs, ValueObject
rhs) { return !(lhs == rhs); } 

Original issue reported on code.google.com by wmccaffe...@gmail.com on 17 Feb 2009 at 4:11

GoogleCodeExporter commented 9 years ago
Completed and checked in.

Original comment by wmccaffe...@gmail.com on 7 Mar 2009 at 10:47