Esempio n. 1
0
        public void UseEqualityComparerWithoutEquivalence()
        {
            IEqualityComparer <HasNotEquivalence> ec = Equivalence.GetEqualityComparerOrFallback <HasNotEquivalence>();

            HasNotEquivalence one = new HasNotEquivalence {
                Value = 1
            };
            HasNotEquivalence oneClone = new HasNotEquivalence {
                Value = 1
            };
            HasNotEquivalence two = new HasNotEquivalence {
                Value = 2
            };

            Assert.AreEqual(ec.Equals(null, null), true);
            Assert.AreEqual(ec.Equals(one, null), false);
            Assert.AreEqual(ec.Equals(null, one), false);

            Assert.AreEqual(ec.Equals(one, one), true);
            Assert.AreEqual(ec.Equals(one, oneClone), false);
            Assert.AreEqual(ec.Equals(one, two), false);

            Assert.AreEqual(ec.Equals(oneClone, one), false);
            Assert.AreEqual(ec.Equals(oneClone, oneClone), true);
            Assert.AreEqual(ec.Equals(oneClone, two), false);

            Assert.AreEqual(ec.Equals(two, one), false);
            Assert.AreEqual(ec.Equals(two, oneClone), false);
            Assert.AreEqual(ec.Equals(two, two), true);
        }
        public void UseEqualityComparerWithFallback()
        {
            var ec = Equivalence.GetEqualityComparerOrFallback <HasEquivalence>();

            var one = new HasEquivalence {
                Value = 1
            };
            var oneClone = new HasEquivalence {
                Value = 1
            };
            var two = new HasEquivalence {
                Value = 2
            };

            Assert.AreEqual(ec.Equals(null !, null !), true);
            Assert.AreEqual(ec.Equals(one, null !), false);
            Assert.AreEqual(ec.Equals(null !, one), false);

            Assert.AreEqual(ec.Equals(one, one), true);
            Assert.AreEqual(ec.Equals(one, oneClone), true);
            Assert.AreEqual(ec.Equals(one, two), false);

            Assert.AreEqual(ec.Equals(oneClone, one), true);
            Assert.AreEqual(ec.Equals(oneClone, oneClone), true);
            Assert.AreEqual(ec.Equals(oneClone, two), false);

            Assert.AreEqual(ec.Equals(two, one), false);
            Assert.AreEqual(ec.Equals(two, oneClone), false);
            Assert.AreEqual(ec.Equals(two, two), true);
        }