コード例 #1
0
        public void EqualsOperator_ShouldBeTrue_WhenBothObjectsAreNull()
        {
            StubValueObject a = null;
            StubValueObject b = null;

            (a == b).Should().BeTrue("both objects are null");
        }
コード例 #2
0
        public void NotEqualsOperator_ShouldBeTrue_WhenValuesAreDifferent()
        {
            var compare = new StubValueObject("Mike", "Walsh");

            (this.sut != compare).Should()
            .BeTrue("the objects do not match");
        }
コード例 #3
0
        public void Equals_ShouldBeFalse_WhenValuesAreDifferent()
        {
            var compare = new StubValueObject("Mike", "Walsh");

            this.sut.Equals(compare).Should()
            .BeFalse("both objects differ");
        }
コード例 #4
0
        public void Equals_ShouldBeFalse_WhenComparedWithNull()
        {
            StubValueObject empty = null;

            this.sut.Equals(empty).Should()
            .BeFalse("system under test is being compared with null");
        }
コード例 #5
0
        public void Equals_ShouldBeTrue_WhenValuesAreIdentical()
        {
            var compare = new StubValueObject("Chester", "Copperpot");

            this.sut.Equals(compare).Should()
            .BeTrue("both objects share the same value");
        }
コード例 #6
0
        public void EqualityTests()
        {
            var instance0 = new StubValueObject
            {
                StreetName  = "One Microsoft Way",
                HouseNumber = 1,
                City        = "Seattle"
            };

            var instance1 = new StubValueObject
            {
                StreetName  = "One Microsoft Way",
                HouseNumber = 1,
                City        = "Seattle"
            };

            var instance2 = new StubValueObject
            {
                StreetName  = "One Microsoft Way",
                HouseNumber = 1,
                City        = "New York"
            };

            instance0.ShouldBe(instance1);
            instance1.ShouldBe(instance1);
            instance1.ShouldNotBe(instance2);
        }
コード例 #7
0
        public void EqualityTests()
        {
            var instance0 = new StubValueObject
            {
                StreetName  = "One Microsoft Way",
                HouseNumber = 1,
                City        = "Seattle"
            };

            var instance1 = new StubValueObject
            {
                StreetName  = "One Microsoft Way",
                HouseNumber = 1,
                City        = "Seattle"
            };

            var instance2 = new StubValueObject
            {
                StreetName  = "One Microsoft Way",
                HouseNumber = 1,
                City        = "New York"
            };

            instance0.Equals(instance1).ShouldBeTrue();  //IEquatable (equals)
            instance0.ShouldBe(instance1);
            (instance0 == instance1).ShouldBeTrue();     // operator
            instance1.ShouldBe(instance1);
#pragma warning disable CS1718                           // Comparison made to same variable
            (instance1 == instance1).ShouldBeTrue();     // operator
#pragma warning restore CS1718                           // Comparison made to same variable
            instance1.ShouldNotBe(instance2);
            instance0.Equals(instance2).ShouldBeFalse(); // IEquatable
        }
コード例 #8
0
        public void GetHashCode_ShouldCreateValidHashCode()
        {
            var hashA = this.sut.GetHashCode();
            var hashB = new StubValueObject("Chester", "Copperpot").GetHashCode();

            hashA.Should()
            .Be(
                hashB,
                "both objects share the same value");
        }
コード例 #9
0
 public ValueObjectTests()
 {
     this.sut = new StubValueObject("Chester", "Copperpot");
 }