public void TestToXmlStringWithParentNotNullAndElementTypeNotReturnsChildXmlStrings(
            [Values] bool withXmlTag)
        {
            const string valueParent             = "Value_1";
            const string xmlTagParent            = "name_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTagParent, valueParent, NUnitElementType.Test);

            const string valueChild             = "Value_2";
            const string xmlTagChild            = "name_2";
            XmlSerializableElementForTest child =
                new XmlSerializableElementForTest(xmlTagChild, valueChild, NUnitElementType.Test);
            string expectedValueChild = NUnitFilterTestHelper.CreateXmlNode(xmlTagChild, valueChild);

            // With tag includes parent xml tag, without is just value
            string expected = withXmlTag
                ? NUnitFilterTestHelper.CreateXmlNode(NUnitFilterTestHelper.XmlNotTag, expectedValueChild)
                : expectedValueChild;

            NUnitFilterContainerElementForTest element =
                new NUnitFilterContainerElementForTest(parent, NUnitElementType.Not);

            element.SetChild(child);

            string actual = element.ToXmlString(withXmlTag);

            Assert.AreEqual(expected, actual);
        }
        /// <inheritdoc />
        public string ToXmlString(bool withXmlTag = true)
        {
            Dictionary <string, string> attributes = null;

            if (v_XmlValue != null)
            {
                attributes = new Dictionary <string, string> {
                    { "name", v_XmlValue }
                };
            }

            return(withXmlTag ? NUnitFilterTestHelper.CreateXmlNode(XmlTag, v_XmlName, false, attributes) : v_XmlName);
        }
示例#3
0
        public void TestToXmlStringWithCollectionOfMultipleItemsReturnsCollectionXmlString(
            [Values] bool withXmlTag)
        {
            // Create collection and expected string of xml nodes
            const int count = 3;
            ExpressionCollection <INUnitFilterBaseElement> collection =
                NUnitFilterTestHelper.CreateCollection(count, out string innerXml);
            // With tag includes parent xml tag, without is just value
            string expected = withXmlTag
                ? NUnitFilterTestHelper.CreateXmlNode(NUnitFilterTestHelper.XmlAndTag, innerXml)
                : innerXml;

            Assert.AreEqual(count, collection.Count);
            Assert.AreEqual(expected, collection.ToXmlString(withXmlTag));
        }
示例#4
0
        public void TestToXmlStringWithCollectionOfOneItemReturnsItemXmlString(
            [Values] bool withXmlTag)
        {
            // Create expected string of xml nodes
            const string value  = "Value_1";
            const string xmlTag = "name_1";
            // With tag includes parent xml tag, without is just value
            string expected = withXmlTag ? NUnitFilterTestHelper.CreateXmlNode(xmlTag, value) : value;

            ExpressionCollection <INUnitFilterBaseElement> collection =
                // ReSharper disable once UseObjectOrCollectionInitializer
                new ExpressionCollection <INUnitFilterBaseElement>(NUnitFilterTestHelper.XmlAndTag);

            // Add expression to collection
            collection.Add(new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.And));

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(expected, collection.ToXmlString(withXmlTag));
        }
        public void TestToXmlString(
            [ValueSource(typeof(NUnitFilterTestHelper), nameof(NUnitFilterTestHelper.GetFilterElements))]
            NUnitElementType elementType, [Values] bool isRegularExpression, [Values] bool withXmlTag)
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            string expectedXmlTag = null;

            switch (elementType)
            {
            case NUnitElementType.Id:
                expectedXmlTag = "id";
                break;

            case NUnitElementType.Test:
                expectedXmlTag = "test";
                break;

            case NUnitElementType.Category:
                expectedXmlTag = "cat";
                break;

            case NUnitElementType.Class:
                expectedXmlTag = "class";
                break;

            case NUnitElementType.Method:
                expectedXmlTag = "method";
                break;

            case NUnitElementType.Namespace:
                expectedXmlTag = "namespace";
                break;

            case NUnitElementType.Property:
                expectedXmlTag = "prop";
                break;

            case NUnitElementType.NUnitName:
                expectedXmlTag = "name";
                break;

            default:
                Assert.Fail($"The type {elementType} is not supported for this test.");
                break;
            }

            string expected;

            if (elementType == NUnitElementType.Property)
            {
                expected = withXmlTag
                    ? NUnitFilterTestHelper.CreateXmlNode(expectedXmlTag, value, isRegularExpression,
                                                          new Dictionary <string, string> {
                    { "name", name }
                })
                    : value;
            }
            else
            {
                expected = withXmlTag
                    ? NUnitFilterTestHelper.CreateXmlNode(expectedXmlTag, name, isRegularExpression)
                    : name;
            }

            INUnitFilterElementInternal element =
                new NUnitFilterElement(parent, elementType, name, isRegularExpression, value);

            string actual = element.ToXmlString(withXmlTag);

            Assert.AreEqual(expected, actual);
        }