コード例 #1
0
        public void BaseSingleValueObject_ShouldBeNotEqualToDerived()
        {
            var baseId    = new UserId(1);
            var derivedId = new DerivedUserId(1, "1");

            Assert.AreNotEqual(baseId, derivedId, "base equals derived");
            Assert.AreNotEqual(derivedId, baseId, "derived equals base");
        }
コード例 #2
0
        public void DerivedSingleValueObjectsWithSameValues_ShouldBeEqual()
        {
            var derivedId1 = new DerivedUserId(1, "1");
            var derivedId2 = new DerivedUserId(1, "1");

            Assert.AreEqual(derivedId1, derivedId2, "derived1 not equals derived2");
            Assert.AreEqual(derivedId2, derivedId1, "derived2 not equals derived1");
            Assert.IsTrue(EqualsAsBase(derivedId1, derivedId2), "not equals as base");

            bool EqualsAsBase(UserId x, UserId y) => x.Equals(y) && y.Equals(x);
        }
コード例 #3
0
        public void DerivedSingleValueObjectsWithDifferentValues_ShouldBeNotEqual()
        {
            var derivedId1 = new DerivedUserId(1, "1");
            var derivedId2 = new DerivedUserId(1, "222");

            Assert.AreNotEqual(derivedId1, derivedId2, "derived1 equals derived2");
            Assert.AreNotEqual(derivedId2, derivedId1, "derived2 equals derived1");
            Assert.IsFalse(EqualsAsBase(derivedId1, derivedId2), "equals as base");

            bool EqualsAsBase(UserId x, UserId y) => x.Equals(y) || y.Equals(x);
        }