Ejemplo n.º 1
0
        public void Non_equal_value_objects_have_different_hash_codes()
        {
            var a = new FakeValueObject(1, "a", true);
            var b = new FakeValueObject(2, "a", true);

            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Ejemplo n.º 2
0
        public void GetHashCode_SingleValue_ThisValueHashCodeReturned()
        {
            string          singleValue = "abcd";
            FakeValueObject obj         = new FakeValueObject(singleValue);

            Assert.AreEqual(singleValue.GetHashCode(), obj.GetHashCode());
        }
Ejemplo n.º 3
0
        public void Equal_value_objects_have_the_same_hash_code()
        {
            var first  = new FakeValueObject(1, "first", true);
            var second = new FakeValueObject(1, "first", true);

            first.GetHashCode().Should().Be(second.GetHashCode());
        }
Ejemplo n.º 4
0
        public void GetHashCode_should_return_same(string str, int number, DateTime datetime, bool boolean)
        {
            // arrange
            var obj1 = new FakeValueObject
            {
                StringValue   = str,
                IntValue      = number,
                DateTimeValue = datetime,
                BooleanValue  = boolean
            };

            var obj2 = new FakeValueObject
            {
                StringValue   = str,
                IntValue      = number,
                DateTimeValue = datetime,
                BooleanValue  = boolean
            };

            // Actions
            var hash1 = obj1.GetHashCode();
            var hash2 = obj2.GetHashCode();

            // Assertion
            hash1.Should().Be(hash2);
        }
Ejemplo n.º 5
0
        public void GetHashCode_SingleValue_ThisValueHashCodeReturned()
        {
            string singleValue = "abcd";
            FakeValueObject obj = new FakeValueObject(singleValue);

            Assert.Equal(singleValue.GetHashCode(), obj.GetHashCode());
        }
Ejemplo n.º 6
0
        public void GetHashCode_TwoValues_XorOfHashCodesReturned()
        {
            string          firstValue = "abcd";
            int             secodValue = 15;
            FakeValueObject obj        = new FakeValueObject(firstValue, secodValue);

            Assert.AreEqual(firstValue.GetHashCode() ^ secodValue.GetHashCode(), obj.GetHashCode());
        }
Ejemplo n.º 7
0
        public void GetHashCode_TwoValues_XorOfHashCodesReturned()
        {
            string firstValue = "abcd";
            int secodValue = 15;
            FakeValueObject obj = new FakeValueObject(firstValue, secodValue);

            Assert.Equal((firstValue.GetHashCode() * 1) ^ (secodValue.GetHashCode() * 2), obj.GetHashCode());
        }
Ejemplo n.º 8
0
        public void SimilarValueObjectsShouldNotHaveSameHashCode()
        {
            // Arrange
            var valueObject1 = new FakeValueObject()
            {
                A = 5, B = "Hello"
            };
            var valueObject2 = new FakeValueObject()
            {
                A = 6, B = "World"
            };

            // Act
            var sameHashCode = valueObject1.GetHashCode() == valueObject2.GetHashCode();

            // Assert
            sameHashCode.Should().BeFalse();
        }
Ejemplo n.º 9
0
        public void GetHashCode_NullValue_ZeroReturned()
        {
            var obj = new FakeValueObject(new object[] { null });

            Assert.AreEqual(0, obj.GetHashCode());
        }
Ejemplo n.º 10
0
        public void GetHashCode_TwoValues_XorOfHashCodesReturned()
        {
            const string firstValue = "abcd";
            const int secodValue = 15;
            var obj = new FakeValueObject(firstValue, secodValue);

            Assert.AreEqual(firstValue.GetHashCode() ^ secodValue.GetHashCode(), obj.GetHashCode());
        }
Ejemplo n.º 11
0
        public void GetHashCode_NullValue_ZeroReturned()
        {
            FakeValueObject obj = new FakeValueObject(new object[] { null });

            Assert.AreEqual(0, obj.GetHashCode());
        }