Esempio n. 1
0
        public void When_deeply_nested_properties_do_not_have_all_equal_values_it_should_throw()
        {
            // Arrange
            var root = new Root
            {
                Text  = "Root",
                Level = new Level1 {
                    Text = "Level1", Level = new Level2 {
                        Text = "Level2"
                    }
                }
            };

            var rootDto = new RootDto
            {
                Text  = "Root",
                Level = new Level1Dto {
                    Text = "Level1", Level = new Level2Dto {
                        Text = "A wrong text value"
                    }
                }
            };

            // Act
            Action act = () => root.Should().BeEquivalentTo(rootDto);

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage(
                "Expected*Level.Level.Text*to be *A wrong text value*but*\"Level2\"*length*");
        }
Esempio n. 2
0
        public void When_all_the_properties_of_the_nested_objects_are_equal_it_should_succeed()
        {
            // Arrange
            var subject = new Root
            {
                Text  = "Root",
                Level = new Level1 {
                    Text = "Level1", Level = new Level2 {
                        Text = "Level2"
                    }
                }
            };

            var expected = new RootDto
            {
                Text  = "Root",
                Level = new Level1Dto {
                    Text = "Level1", Level = new Level2Dto {
                        Text = "Level2"
                    }
                }
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected);

            // Assert
            act.Should().NotThrow();
        }
Esempio n. 3
0
        public void When_the_actual_nested_object_is_null_it_should_throw()
        {
            // Arrange
            var subject = new Root {
                Text = "Root", Level = new Level1 {
                    Text = "Level2"
                }
            };

            var expected = new RootDto {
                Text = "Root", Level = null
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected);

            // Assert
            act
            .Should().Throw <XunitException>()
            .WithMessage("Expected*Level*to be <null>*, but found*Level1*Level2*");
        }
Esempio n. 4
0
        public void When_the_expectation_contains_a_nested_null_it_should_properly_report_the_difference()
        {
            // Arrange
            var subject = new Root {
                Text = "Root", Level = new Level1 {
                    Text = "Level1", Level = new Level2()
                }
            };

            var expected = new RootDto {
                Text = "Root", Level = new Level1Dto {
                    Text = "Level1", Level = null
                }
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected);

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("*Expected*Level.Level*to be <null>, but found*Level2*Without automatic conversion*");
        }
Esempio n. 5
0
        public void When_not_all_the_properties_of_the_nested_objects_are_equal_it_should_throw()
        {
            // Arrange
            var subject = new Root {
                Text = "Root", Level = new Level1 {
                    Text = "Level1"
                }
            };

            var expected = new RootDto {
                Text = "Root", Level = new Level1Dto {
                    Text = "Level2"
                }
            };

            // Act
            Action act = () =>
                         subject.Should().BeEquivalentTo(expected);

            // Assert
            act.Should().Throw <XunitException>().Which.Message

            // Checking exception message exactly is against general guidelines
            // but in that case it was done on purpose, so that we have at least have a single
            // test confirming that whole mechanism of gathering description from
            // equivalency steps works.
            .Should().Match(
                @"Expected property subject.Level.Text to be ""Level2"", but ""Level1"" differs near ""1"" (index 5).*" +
                "With configuration:*" +
                "- Use declared types and members*" +
                "- Compare enums by value*" +
                "- Compare tuples by their properties*" +
                "- Compare anonymous types by their properties*" +
                "- Compare records by their members*" +
                "- Match member by name (or throw)*" +
                "- Be strict about the order of items in byte arrays*" +
                "- Without automatic conversion.*");
        }
Esempio n. 6
0
        public void When_a_property_with_a_value_mismatch_is_excluded_using_a_predicate_it_should_not_throw()
        {
            // Arrange
            var subject = new Root
            {
                Text  = "Root",
                Level = new Level1
                {
                    Text  = "Level1",
                    Level = new Level2
                    {
                        Text = "Mismatch"
                    }
                }
            };

            var expected = new RootDto
            {
                Text  = "Root",
                Level = new Level1Dto
                {
                    Text  = "Level1",
                    Level = new Level2Dto
                    {
                        Text = "Level2"
                    }
                }
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected, config =>
                                                               config.Excluding(ctx => ctx.Path == "Level.Level.Text"));

            // Assert
            act.Should().NotThrow();
        }
Esempio n. 7
0
        public void When_a_deeply_nested_property_with_a_value_mismatch_is_excluded_it_should_not_throw()
        {
            // Arrange
            var subject = new Root
            {
                Text  = "Root",
                Level = new Level1
                {
                    Text  = "Level1",
                    Level = new Level2
                    {
                        Text = "Mismatch"
                    }
                }
            };

            var expected = new RootDto
            {
                Text  = "Root",
                Level = new Level1Dto
                {
                    Text  = "Level1",
                    Level = new Level2Dto
                    {
                        Text = "Level2"
                    }
                }
            };

            // Act
            Action act = () => subject.Should().BeEquivalentTo(expected,
                                                               options => options.Excluding(r => r.Level.Level.Text));

            // Assert
            act.Should().NotThrow();
        }