Example #1
0
        public void IdenticalReplacementIsNotChange()
        {
            var container = new XElement("C",
                new XElement("b", new XAttribute("SomeProp", DateTime.Today), "Hi there!", new XElement("Deep", "Content")),
                new XElement("c"),
                new XElement("d")
            );

            MergeElements(container,
                new XElement("b", new XAttribute("SomeProp", DateTime.Today), "Hi there!", new XElement("Deep", "Content"))
            ).Should().BeFalse();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("b", new XAttribute("SomeProp", DateTime.Today), "Hi there!", new XElement("Deep", "Content")),
                new XElement("c"),
                new XElement("d")
            ));
        }
        public void When_asserting_an_xml_element_is_not_equal_to_a_different_xml_element_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");
            var otherElement = new XElement("other");

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().NotBe(otherElement);

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
Example #3
0
        public void ElementsAreCaseSensitive()
        {
            var container = new XElement("C",
                new XElement("A"),
                new XElement("b")
            );

            MergeElements(container,
                new XElement("a"),
                new XElement("B")
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("A"),
                new XElement("B"),
                new XElement("a"),
                new XElement("b")
            ));
        }
        public void When_asserting_an_xml_element_is_equal_to_the_same_xml_element_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");
            var sameElement = new XElement("element");

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().Be(sameElement);

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_an_xml_element_is_equal_to_a_different_xml_element_it_should_fail_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");
            var otherElement = new XElement("other");

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().Be(otherElement, "because we want to test the failure {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected XML element to be*other*because we want to test the failure message, but found *element*");
        }
Example #6
0
        public void DontStopReorderingAfterLastInsertion()
        {
            var container = new XElement("C",
                new XElement("a"),
                new XElement("c"),
                new XElement("e"),
                new XElement("d")
            );

            MergeElements(container,
                new XElement("c", new XElement("child", "Hi there!")),
                new XElement("b")
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("a"),
                new XElement("b"),
                new XElement("c", new XElement("child", "Hi there!")),
                new XElement("d"),
                new XElement("e")
            ), "the merger should not stop checking for ordering after it finishes merging all new elements");
        }
        public void When_asserting_an_xml_element_is_equal_to_an_xml_element_with_a_deep_difference_it_should_fail()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var expected =
                new XElement("parent"
                    , new XElement("child"
                        , new XElement("grandChild")));
            var actual =
                new XElement("parent"
                    , new XElement("child"
                        , new XElement("grandChild2")));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () => actual.Should().Be(expected);

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
        public void When_asserting_an_xml_element_is_not_equal_to_the_same_xml_element_it_should_fail()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");
            var sameElement = element;

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().NotBe(sameElement);

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
Example #9
0
        public void ReorderExistingElements()
        {
            var container = new XElement("C",
                new XElement("c"),
                new XElement("d"),
                new XElement("b")
            );

            MergeElements(container,
                new XElement("a"),
                new XElement("e")
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("a"),
                new XElement("b"),
                new XElement("c"),
                new XElement("d"),
                new XElement("e")
            ));
        }
Example #10
0
        public void ReorderCountsAsChange()
        {
            var container = new XElement("C",
                new XElement("c"),
                new XElement("d"),
                new XElement("b")
            );

            MergeElements(container,
                new XElement("b")
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("b"),
                new XElement("c"),
                new XElement("d")
            ));
        }
Example #11
0
        public void PopulateEmptyElement()
        {
            var container = new XElement("C");

            MergeElements(container,
                new XElement("c"),
                new XElement("a"),
                new XElement("b")
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("a"),
                new XElement("b"),
                new XElement("c")
            ));
        }
Example #12
0
        public void OverwriteExistingOutOfOrderElement()
        {
            var container = new XElement("C",
                new XElement("c"),
                new XElement("b"),
                new XElement("a")
            );

            MergeElements(container,
                new XElement("a", 42)
            );

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("a", 42),
                new XElement("b"),
                new XElement("c")
            ));
        }
Example #13
0
        public void OverwriteExistingElements()
        {
            var container = new XElement("C",
                new XElement("a"),
                new XElement("b"),
                new XElement("c")
            );

            MergeElements(container,
                new XElement("a", 42),
                new XElement("c", new XAttribute("Value", 67))
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("a", 42),
                new XElement("b"),
                new XElement("c", new XAttribute("Value", 67))
            ));
        }
        public void When_asserting_a_non_null_xml_element_is_not_null_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().NotBeNull();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_asserting_an_xml_element_is_null_but_it_is_not_it_should_fail_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().BeNull("because we want to test the failure {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected XML element to be <null> because we want to test the failure message," +
                    " but found <element />.");
        }
        public void When_asserting_an_xml_element_is_null_but_it_is_not_it_should_fail()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().BeNull();

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>();
        }
        public void When_asserting_an_xml_element_is_not_equal_to_the_same_xml_element_it_should_fail_with_descriptive_message()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var element = new XElement("element");
            var sameElement = element;

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () =>
                element.Should().NotBe(sameElement, "because we want to test the failure {0}", "message");

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage("Expected XML element not to be <element />" +
                    " because we want to test the failure message.");
        }
Example #18
0
        public void MergeIntoElement()
        {
            var container = new XElement("C",
                new XElement("b"),
                new XElement("d"),
                new XElement("f")
            );

            MergeElements(container,
                new XElement("g"),
                new XElement("e"),
                new XElement("b"),
                new XElement("c"),
                new XElement("a")
            ).Should().BeTrue();

            container.Should().BeEquivalentTo(new XElement("C",
                new XElement("a"),
                new XElement("b"),
                new XElement("c"),
                new XElement("d"),
                new XElement("e"),
                new XElement("f"),
                new XElement("g")
            ));
        }
        public void When_asserting_a_deep_xml_element_is_not_equal_to_a_different_xml_element_it_should_succeed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            var differentElement =
                new XElement("parent"
                    , new XElement("child"
                        , new XElement("grandChild")));
            var element =
                new XElement("parent"
                    , new XElement("child"
                        , new XElement("grandChild2")));

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action act = () => element.Should().NotBe(differentElement);

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }