public void TestBuildWithBothAndPlusOrPlusFilterElements()
        {
            NUnitFilter filter2 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).Or.Not
                                  .Id("id3", "id4", "id5").Build();
            const string expected2 =
                "<filter><or><and><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop></and><not><id>id3,id4,id5</id></not></or></filter>";

            Assert.IsNotNull(filter2);
            Assert.AreEqual(expected2, filter2.FilterXmlString);

            NUnitFilter filter3 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).Or.Not
                                  .Id("id3", "id4", "id5").And.Id("id6").Build();
            const string expected3 =
                "<filter><or><and><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop></and><and><not><id>id3,id4,id5</id></not><id>id6</id></and></or></filter>";

            Assert.IsNotNull(filter3);
            Assert.AreEqual(expected3, filter3.FilterXmlString);

            NUnitFilter filter4 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).Or.Not
                                  .Id("id3", "id4", "id5").And.Id("id6").And.Not.Class("class7", true).Build();
            const string expected4 =
                "<filter><or><and><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop></and><and><not><id>id3,id4,id5</id></not><id>id6</id><not><class re=\"1\">class7</class></not></and></or></filter>";

            Assert.IsNotNull(filter4);
            Assert.AreEqual(expected4, filter4.FilterXmlString);

            NUnitFilter filter5 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).Or.Not
                                  .Id("id3", "id4", "id5").And.Id("id6").And.Not.Class("class7", true).Or.Method("method8").Build();
            const string expected5 =
                "<filter><or><and><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop></and><and><not><id>id3,id4,id5</id></not><id>id6</id><not><class re=\"1\">class7</class></not></and><method>method8</method></or></filter>";

            Assert.IsNotNull(filter5);
            Assert.AreEqual(expected5, filter5.FilterXmlString);

            NUnitFilter filter6 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).Or.Not
                                  .Id("id3", "id4", "id5").And.Id("id6").And.Not.Class("class7", true).Or.Method("method8").Or
                                  .Name("name9").Build();
            const string expected6 =
                "<filter><or><and><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop></and><and><not><id>id3,id4,id5</id></not><id>id6</id><not><class re=\"1\">class7</class></not></and><method>method8</method><name>name9</name></or></filter>";

            Assert.IsNotNull(filter6);
            Assert.AreEqual(expected6, filter6.FilterXmlString);
        }
        public void TestBuildThrowsArgumentExceptionWhenLeafElementChildIsNotNull()
        {
            const string value  = "Value_";
            const string xmlTag = "name_";
            NUnitFilterContainerElementForTest root =
                new NUnitFilterContainerElementForTest(null, NUnitElementType.RootFilter);
            XmlSerializableElementForTest leafChild =
                new XmlSerializableElementForTest(xmlTag + 1, value + 1, NUnitElementType.Test);

            root.SetChild(leafChild);

            Assert.IsNotNull(root.Child);

            Assert.Throws(
                Is.TypeOf <ArgumentException>().And.Message
                .EqualTo(
                    "The leaf element's child is not null thus the provided leaf element is not the true leaf element." +
                    " This may indicate an error in the construction or parsing of the filter. (Parameter 'leafElement')"),
                () => NUnitFilter.Build(root));
        }
        public void TestBuildWithOnlyOneFilterElement(
            [ValueSource(typeof(NUnitFilterTestHelper), nameof(NUnitFilterTestHelper.GetFilterElements))]
            NUnitElementType elementType)
        {
            const string value = "Value_";
            NUnitFilterContainerElementForTest root =
                new NUnitFilterContainerElementForTest(null, NUnitElementType.RootFilter);
            XmlSerializableElementForTest child1 =
                new XmlSerializableElementForTest("name", value + 1, elementType);

            root.SetChild(child1);
            child1.Parent = root;

            const string expected = "<filter><name>Value_1</name></filter>";

            NUnitFilter filter = NUnitFilter.Build(child1);

            Assert.IsNotNull(filter);
            Assert.AreEqual(expected, filter.FilterXmlString);
            Assert.AreEqual(expected, GetXmlString(filter.Filter));
        }
        public void TestBuildWithOnlyAndPlusFilterElements()
        {
            NUnitFilter  filter1   = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).Build();
            const string expected1 = "<filter><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop></filter>";

            Assert.IsNotNull(filter1);
            Assert.AreEqual(expected1, filter1.FilterXmlString);

            NUnitFilter filter2 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).And.Not
                                  .Id("id3", "id4", "id5").Build();
            const string expected2 =
                "<filter><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop><not><id>id3,id4,id5</id></not></filter>";

            Assert.IsNotNull(filter2);
            Assert.AreEqual(expected2, filter2.FilterXmlString);

            NUnitFilter filter3 = NUnitFilter.Where.Category("cat1").And.Property("prop2", "value2", true).And.Not
                                  .Id("id3", "id4", "id5").And.Id("id6").Build();
            const string expected3 =
                "<filter><cat>cat1</cat><prop re=\"1\" name=\"prop2\">value2</prop><not><id>id3,id4,id5</id></not><id>id6</id></filter>";

            Assert.IsNotNull(filter3);
            Assert.AreEqual(expected3, filter3.FilterXmlString);
        }
        public void TestBuildThrowsInvalidOperationExceptionWhenAParentElementChildIsNull()
        {
            const string value  = "Value_";
            const string xmlTag = "name_";
            NUnitFilterContainerElementForTest root =
                new NUnitFilterContainerElementForTest(null, NUnitElementType.RootFilter);
            XmlSerializableElementForTest leafChild =
                new XmlSerializableElementForTest(xmlTag + 1, value + 1, NUnitElementType.Test);

            leafChild.Parent = root;

            Assert.AreSame(root, leafChild.Parent);
            Assert.IsNull(root.Child);

            const string parentString =
                "{NUnitFilterContainerElementForTest: {Type: RootFilter, Parent: Null, Child: Null}}";

            Assert.Throws(
                Is.TypeOf <InvalidOperationException>().And.Message
                .EqualTo($"The parent element's {parentString} child was null." +
                         " Forward traversal will not proceed properly." +
                         " This may indicate an error in the construction or parsing of the filter."),
                () => NUnitFilter.Build(leafChild));
        }