コード例 #1
0
        public void ObjectEquals_OtherIsDifferent_NotEqual()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");
            TestValueObject obj2 = new TestValueObject(2, "hello");
            TestValueObject obj3 = new TestValueObject(1, "hello2");

            Assert.False(obj1.Equals(obj2));
            Assert.False(obj1.Equals(obj3));
        }
コード例 #2
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());
        }
コード例 #3
0
        public void NotEqualWhenTheOtherIsNull()
        {
            var             left  = new TestValueObject(1, "caseless", "Blah");
            TestValueObject?right = null;

            left.Equals(right as object).Should().BeFalse();
            left.Equals(right).Should().BeFalse();
            (left == right).Should().BeFalse();
            (left != right).Should().BeTrue();

            (right == left).Should().BeFalse();
            (right != left).Should().BeTrue();
        }
コード例 #4
0
        public void NotEqualWhenComponentsAreDifferent(
            int leftId, string leftCaseless, string leftCaseSensitive,
            int rightId, string rightCaseless, string rightCaseSensitive
            )
        {
            var left  = new TestValueObject(leftId, leftCaseless, leftCaseSensitive);
            var right = new TestValueObject(rightId, rightCaseless, rightCaseSensitive);

            left.Equals(right as object).Should().BeFalse();
            left.Equals(right).Should().BeFalse();
            (left == right).Should().BeFalse();
            (left != right).Should().BeTrue();
        }
コード例 #5
0
            public void ObjectEqualsShouldBeTrueIfValueObjectsMatchByValue()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test", 123);

                valueObject1.Equals((object)valueObject2).Should().BeTrue();
            }
コード例 #6
0
        public void ObjectEquals_OtherIsEqual_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");
            TestValueObject obj2 = new TestValueObject(1, "hello");

            Assert.True(obj1.Equals(obj2));
        }
コード例 #7
0
            public void ObjectEqualsShouldBeTrueIfValueObjectsAreTheSameReference()
            {
                TestValueObject valueObject1  = new TestValueObject("Test", 123);
                TestValueObject sameReference = valueObject1;

                valueObject1.Equals((object)sameReference).Should().BeTrue();
            }
コード例 #8
0
        public void ObjectEquals_OtherIsSame_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");

            // ReSharper disable once EqualExpressionComparison
            Assert.True(obj1.Equals(obj1));
        }
コード例 #9
0
            public void EqualsOperatorShouldNotBeTrueIfComparedWithNull()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = null;

                valueObject1.Equals(valueObject2).Should().BeFalse();
            }
コード例 #10
0
            public void EqualsShouldNotBeTrueIfValueObjectsDoNotMatchByValue()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test2", 1234);

                valueObject1.Equals(valueObject2).Should().BeFalse();
            }
コード例 #11
0
        public void ObjectEquals_OtherIsDerivedButEqual_NotEqual()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");
            TestValueObject obj2 = new DerivedTestValueObject(1, "hello");

            Assert.False(obj1.Equals(obj2));
            Assert.False(obj2.Equals(obj1));
        }
コード例 #12
0
ファイル: ValueObjectTests.cs プロジェクト: koskedk/Sante
        public void should_check_ValueObject_equlity()
        {
            TestValueObject regionA = new TestValueObject("Ke", "Kenya");
            TestValueObject regionC = new TestValueObject("Ke", "Kenya");
            TestValueObject regionB = new TestValueObject("Zm", "Zambia");

            Assert.True(regionA.Equals(regionC));
            Assert.True(regionB != regionA);
        }
コード例 #13
0
            public void WhenComparingUsingEqualsMethod_ItShouldCompareEquality(TestValueObject a,
                                                                               TestValueObject b,
                                                                               bool expected)
            {
                // Act
                var actual = a.Equals(b);

                // Assert
                Assert.Equal(expected, actual);
            }
コード例 #14
0
        public void Should_be_equal_to_another_instance_with_the_same_properties()
        {
            //Arrange
            var sut     = new TestValueObject(3, "sadasd asd asdsd p qwevndofgewrio qwrlhw eqhncqw ehtuwehgfqwlerg", Guid.NewGuid(), 2324.52m);
            var another = new TestValueObject(3, "sadasd asd asdsd p qwevndofgewrio qwrlhw eqhncqw ehtuwehgfqwlerg", sut.C, 2324.52m);

            //Act
            var areEqual = sut.Equals(another) && sut == another;

            //Assert
            areEqual.Should().BeTrue();
        }
コード例 #15
0
        public void ObjectEquals_OtherIsNull_NotEqual()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");

            Assert.False(obj1.Equals(null));
        }
コード例 #16
0
        public void ObjectEquals_OtherIsSame_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");

            Assert.True(obj1.Equals((object)obj1));
        }
コード例 #17
0
        public void IEquatable_OtherIsSame_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");

            Assert.True(obj1.Equals(obj1));
        }
コード例 #18
0
        public void IEquatable_OtherIsNull_NotEqual()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");

            Assert.False(obj1.Equals((ValueObject)null));
        }