Beispiel #1
0
            public void ShouldBeSameForTheSameInstance()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);

                int hashCode1 = valueObject1.GetHashCode();
                int hashCode2 = valueObject1.GetHashCode();

                hashCode1.Should().Be(hashCode2);
            }
        public void GetHashCode_SameObjects_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");
            TestValueObject obj2 = new TestValueObject(1, "hello");

            Assert.Equal(obj1.GetHashCode(), obj2.GetHashCode());
        }
            public void Must_Not_Be_Equal_For_The_Different_Instances_With_Different_Values()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test2", 1234);

                Assert.True(valueObject1.GetHashCode() != valueObject2.GetHashCode());
            }
Beispiel #4
0
            public void ShouldNotBeSameForTheDifferentInstancesWithDifferentValues()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test2", 1234);

                int hashCode1 = valueObject1.GetHashCode();
                int hashCode2 = valueObject2.GetHashCode();

                hashCode1.Should().NotBe(hashCode2);
            }
            public void ItShouldGenerateConsistentHashCodes(TestValueObject a,
                                                            TestValueObject b,
                                                            bool expected)
            {
                // Act
                var actual = a.GetHashCode() == b.GetHashCode();

                // Assert
                Assert.Equal(expected, actual);
            }
Beispiel #6
0
        public void EqualWhenComponentsAreEqual()
        {
            var left  = new TestValueObject(1, "caseless", "ABcd");
            var right = new TestValueObject(1, "caseLESS", "ABcd");

            left.Equals(right as object).Should().BeTrue();
            left.Equals(right).Should().BeTrue();
            (left == right).Should().BeTrue();
            (left != right).Should().BeFalse();
            left.GetHashCode().Should().Be(right.GetHashCode());
        }
Beispiel #7
0
        public void ValueObjectsAreNotEqualWhenNotAllPropertiesHaveSameValue()
        {
            var testValueObject = new TestValueObject {
                Firstname = "Robin", Lastname = "van der Knaap"
            };
            var testValueObject2 = new TestValueObject {
                Firstname = "Daan", Lastname = "le Duc"
            };

            Assert.AreNotEqual(testValueObject, testValueObject2);
            Assert.IsFalse(testValueObject == testValueObject2);
            Assert.IsTrue(testValueObject != testValueObject2);
            Assert.AreNotEqual(testValueObject.GetHashCode(), testValueObject2.GetHashCode());

            var valueObjectSet = new HashSet <ValueObject> {
                testValueObject, testValueObject2
            };

            Assert.AreEqual(2, valueObjectSet.Count);
        }
            public void Must_Be_Equal_For_The_Same_Instance()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);

                Assert.True(valueObject1.GetHashCode() == valueObject1.GetHashCode());
            }