Exemple #1
0
        public void GetHashCode_Should_ReturnSameValues()
        {
            // Arrange
            var value1 = new MyValueObject(10, "Unit Tests");
            var value2 = new MyValueObject(10, "Unit Tests");

            // Act & Assert
            Assert.Equal(value1.GetHashCode(), value2.GetHashCode());
        }
Exemple #2
0
        public void GetHashCode_Should_ReturnValue_WhenItContainsNullProperties()
        {
            // Arrange
            const int expected = 512;
            var       value1   = new MyValueObject(512, null);

            // Act
            var actual = value1.GetHashCode();

            // Assert
            Assert.Equal(expected, actual);
        }
Exemple #3
0
        public void TwoValueObjectsWithSameValuesButDifferentTypesAreNotEqual()
        {
            MyValueObject object1 = new MyValueObject("string", 100);
            MySimilarValueObject object2 = new MySimilarValueObject("string", 100);
            MyInheritedValueObject object3 = new MyInheritedValueObject("string", 100);
            MyExtendedValueObject object4 = new MyExtendedValueObject("string", 100, 102);

            Assert.AreNotSame(object1, object2);
            Assert.AreNotSame(object1, object3);
            Assert.AreNotSame(object1, object4);

            Assert.AreEqual(object1, object1);

            Assert.AreNotEqual(object1, object2);
            Assert.AreNotEqual(object2, object1);

            Assert.AreNotEqual(object1, object3);
            Assert.AreNotEqual(object3, object1);

            Assert.AreNotEqual(object1, object4);
            Assert.AreNotEqual(object4, object1);

            Assert.AreNotEqual(object1.GetHashCode(), object2.GetHashCode());
            Assert.AreNotEqual(object2.GetHashCode(), object1.GetHashCode());

            Assert.AreNotEqual(object1.GetHashCode(), object3.GetHashCode());
            Assert.AreNotEqual(object3.GetHashCode(), object1.GetHashCode());

            Assert.AreNotEqual(object1.GetHashCode(), object4.GetHashCode());
            Assert.AreNotEqual(object4.GetHashCode(), object1.GetHashCode());
        }
Exemple #4
0
        public void TwoValueObjectsWithSameValuesAreEqual()
        {
            MyValueObject object1 = new MyValueObject("string", 100);
            MyValueObject object2 = new MyValueObject("string", 100);

            Assert.AreNotSame(object1, object2);
            Assert.AreEqual(object1, object1);
            Assert.AreEqual(object1, object2);
            Assert.AreEqual(object2, object1);
            Assert.AreEqual(object1.GetHashCode(), object2.GetHashCode());
            Assert.AreEqual(object2.GetHashCode(), object1.GetHashCode());
        }