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

                (valueObject1 == sameReference).Should().BeTrue();
            }
Beispiel #2
0
            public void EqualityOperatorShouldBeFalseIfComparedWithNull()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = null;

                (valueObject1 == valueObject2).Should().BeFalse();
            }
Beispiel #3
0
            public void ObjectEqualsShouldBeTrueIfValueObjectsMatchByValue()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test", 123);

                valueObject1.Equals((object)valueObject2).Should().BeTrue();
            }
Beispiel #4
0
            public void EqualsShouldNotBeTrueIfValueObjectsDoNotMatchByValue()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test2", 1234);

                valueObject1.Equals(valueObject2).Should().BeFalse();
            }
Beispiel #5
0
            public void EqualityOperatorShouldBeTrueIfValueObjectsMatchByValue()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test", 123);

                (valueObject1 == valueObject2).Should().BeTrue();
            }
Beispiel #6
0
            public void ObjectEqualsShouldBeTrueIfValueObjectsAreTheSameReference()
            {
                TestValueObject valueObject1  = new TestValueObject("Test", 123);
                TestValueObject sameReference = valueObject1;

                valueObject1.Equals((object)sameReference).Should().BeTrue();
            }
        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_Be_False_If_Other_Checked_Against_Null()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = null;

                Assert.True(valueObject1 != valueObject2);
            }
            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());
            }
            public void Must_Be_False_If_Value_Objects_Are_Not_Equal_By_Value()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test2", 1234);

                Assert.True(valueObject1 != valueObject2);
            }
        public void ObjectEquals_OtherIsSame_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");

            // ReSharper disable once EqualExpressionComparison
            Assert.True(obj1.Equals(obj1));
        }
        public void ObjectEquals_OtherIsEqual_Equal()
        {
            TestValueObject obj1 = new TestValueObject(1, "hello");
            TestValueObject obj2 = new TestValueObject(1, "hello");

            Assert.True(obj1.Equals(obj2));
        }
Beispiel #13
0
            public void EqualsOperatorShouldNotBeTrueIfComparedWithNull()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = null;

                valueObject1.Equals(valueObject2).Should().BeFalse();
            }
Beispiel #14
0
            public void EqualityOperatorShouldBeFalseIfValueObjectsDoNotMatchByValue()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);
                TestValueObject valueObject2 = new TestValueObject("Test2", 1234);

                (valueObject1 == valueObject2).Should().BeFalse();
            }
        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));
        }
Beispiel #16
0
            public void ShouldNotBeEqualIfValueObjectsMatchByValueButDifferentType()
            {
                var valueObject1 = new TestValueObject("Test", 123);
                var valueObject2 = new TestValueObjectSecond("Test", 123);

                // Same value, should be equal.
                valueObject1.Should().NotBe(valueObject2);
            }
Beispiel #17
0
            public void ShouldBeSameForTheSameInstance()
            {
                TestValueObject valueObject1 = new TestValueObject("Test", 123);

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

                hashCode1.Should().Be(hashCode2);
            }
        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));
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public void ValueObjectsAreEqualWhenBothAreNull()
        {
            TestValueObject testValueObject1 = null;
            TestValueObject testValueObject2 = null;

            Assert.AreEqual(testValueObject1, testValueObject2);
            Assert.IsTrue(testValueObject1 == testValueObject2);
            Assert.IsFalse(testValueObject1 != testValueObject2);
        }
            public void WhenComparingUsingOperator_ItShouldCompareQuality(TestValueObject a,
                                                                          TestValueObject b,
                                                                          bool expected)
            {
                // Act
                var actual = a == b;

                // Assert
                Assert.Equal(expected, actual);
            }
            public void WhenComparingUsingEqualsMethod_ItShouldCompareEquality(TestValueObject a,
                                                                               TestValueObject b,
                                                                               bool expected)
            {
                // Act
                var actual = a.Equals(b);

                // Assert
                Assert.Equal(expected, actual);
            }
Beispiel #23
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 #25
0
        public void ComparingValueObjectWithNull_ObjectBeingNull_ReturnsTrue()
        {
            // Arrange
            TestValueObject nullObj = null;

            // Act
            var actualComparisonResult = nullObj == null;

            // Assert
            Assert.That(actualComparisonResult, Is.True);
        }
Beispiel #26
0
        public void ComparingValueObjectWithNull_ObjectBeingNotNull_ReturnsFalse()
        {
            // Arrange
            var notNullObj = new TestValueObject(string.Empty, 0, DateTime.Now);

            // Act
            var actualComparisonResult = notNullObj == null;

            // Assert
            Assert.That(actualComparisonResult, Is.False);
        }
Beispiel #27
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 #28
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();
        }
Beispiel #29
0
        public void Should_support_serialization()
        {
            //Arrange
            var sut = new TestValueObject(3, "sadasd asd asdsd p qwevndofgewrio qwrlhw eqhncqw ehtuwehgfqwlerg", Guid.NewGuid(), 2324.52m);

            //Act
            var serializedEntity   = JsonConvert.SerializeObject(sut);
            var deserializedEntity = JsonConvert.DeserializeObject <TestValueObject>(serializedEntity);

            //Assert
            deserializedEntity.Should().Be(sut);
        }
Beispiel #30
0
            private async Task ShouldNotThrowIfValueObjectDoesNotExist()
            {
                var valueRepository =
                    await _valueRepositoryFactory.Create <TestValueObject>(
                        _database,
                        _documentCollection,
                        "TestEntity");

                var valueObject = new TestValueObject(1);

                valueRepository.Awaiting(vof => vof.Delete(valueObject)).Should().NotThrow();
            }