예제 #1
0
        public void When_an_assertion_on_two_objects_fails_it_should_show_the_properties_of_the_class()
        {
            // Arrange
            var subject = new SomeDto
            {
                Age       = 37,
                Birthdate = 20.September(1973),
                Name      = "Dennis"
            };

            var other = new SomeDto
            {
                Age       = 2,
                Birthdate = 22.February(2009),
                Name      = "Teddie"
            };

            // Act
            Action act = () => subject.Should().Be(other);

            // Assert
            act.Should().Throw <XunitException>().WithMessage(
                "Expected subject to be*FluentAssertions.Specs.SomeDto*{*Age = 2*Birthdate = <2009-02-22>*" +
                "   Name = \"Teddie\"*}, but found*FluentAssertions.Specs.SomeDto*{*Age = 37*" +
                "   Birthdate = <1973-09-20>*Name = \"Dennis\"*}.");
        }
        public void When_an_assertion_on_two_objects_fails_it_should_show_the_properties_of_the_class()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new SomeDto
            {
                Age       = 37,
                Birthdate = 20.September(1973),
                Name      = "Dennis"
            };

            var other = new SomeDto
            {
                Age       = 2,
                Birthdate = 22.February(2009),
                Name      = "Teddie"
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().Be(other);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow <AssertFailedException>().WithMessage(
                "Expected object to be \r\n\r\nFluentAssertions.Specs.SomeDto\r\n{\r\n   Age = 2\r\n   Birthdate = <2009-02-22>\r\n" +
                "   Name = \"Teddie\"\r\n}, but found \r\n\r\nFluentAssertions.Specs.SomeDto\r\n{\r\n   Age = 37\r\n" +
                "   Birthdate = <1973-09-20>\r\n   Name = \"Dennis\"\r\n}.");
        }
        public void When_an_assertion_on_two_objects_fails_it_should_show_the_properties_of_the_class()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var subject = new SomeDto
            {
                Age = 37,
                Birthdate = 20.September(1973),
                Name = "Dennis"
            };

            var other = new SomeDto
            {
                Age = 2,
                Birthdate = 22.February(2009),
                Name = "Teddie"
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => subject.Should().Be(other);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected object to be \r\n\r\nFluentAssertions.Specs.SomeDto\r\n{\r\n   Age = 2\r\n   Birthdate = <2009-02-22>\r\n" +
                    "   Name = \"Teddie\"\r\n}, but found \r\n\r\nFluentAssertions.Specs.SomeDto\r\n{\r\n   Age = 37\r\n" +
                        "   Birthdate = <1973-09-20>\r\n   Name = \"Dennis\"\r\n}.");
        }
예제 #4
0
        public void When_typed_object_satisfies_predicate_it_should_not_throw()
        {
            // Arrange
            var someObject = new SomeDto
            {
                Name      = "Dennis Doomen",
                Age       = 36,
                Birthdate = new DateTime(1973, 9, 20)
            };

            // Act / Assert
            someObject.Should().Match <SomeDto>(o => o.Age > 0);
        }
예제 #5
0
        public void When_a_typed_object_does_not_match_the_predicate_it_should_throw()
        {
            // Arrange
            var someObject = new SomeDto
            {
                Name      = "Dennis Doomen",
                Age       = 36,
                Birthdate = new DateTime(1973, 9, 20)
            };

            // Act
            Action act = () => someObject.Should().Match((SomeDto d) => d.Name.Length == 0, "it is not initialized yet");

            // Assert
            act.Should().Throw <XunitException>().WithMessage(
                "Expected someObject to match (d.Name.Length == 0) because it is not initialized yet*");
        }
        public void When_typed_object_satisfies_predicate_it_should_not_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var someObject = new SomeDto
            {
                Name = "Dennis Doomen",
                Age = 36,
                Birthdate = new DateTime(1973, 9, 20)
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-----------------------------------------------------------------------------------------------------------
            someObject.Should().Match<SomeDto>(o => o.Age > 0);
        }
        public void When_a_typed_object_does_not_match_the_predicate_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var someObject = new SomeDto
            {
                Name      = "Dennis Doomen",
                Age       = 36,
                Birthdate = new DateTime(1973, 9, 20)
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => someObject.Should().Match((SomeDto d) => d.Name.Length == 0, "it is not initialized yet");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow <AssertFailedException>().WithMessage(
                "Expected " + Formatter.ToString(someObject) + " to match (d.Name.Length == 0) because it is not initialized yet.");
        }
        public void When_a_typed_object_does_not_match_the_predicate_it_should_throw()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var someObject = new SomeDto
            {
                Name = "Dennis Doomen",
                Age = 36,
                Birthdate = new DateTime(1973, 9, 20)
            };

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => someObject.Should().Match((SomeDto d) => d.Name.Length == 0, "it is not initialized yet");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>().WithMessage(
                "Expected " + Formatter.ToString(someObject) + " to match (d.Name.Length == 0) because it is not initialized yet.");
        }