コード例 #1
0
        public void TestIdWithTestIdArraySetsChildAndReturnsNewAndElementWithParent()
        {
            const string name1 = "name_1";
            const string name2 = "name_2";
            const string name3 = "name_3";

            string[]     names  = { name1, null, name2, string.Empty, name3 };
            const string value  = "Value_1";
            const string xmlTag = "parent_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);
            const string expectedName = name1 + "," + name2 + "," + name3;

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            INUnitFilterElementInternal id = (INUnitFilterElementInternal)element.Id(names);

            Assert.IsNotNull(id);
            Assert.AreEqual(NUnitElementType.Id, id.ElementType);
            Assert.AreSame(element, id.Parent);
            Assert.AreSame(id, element.Child);
            Assert.AreEqual(expectedName, id.ElementName);
            Assert.IsNull(id.ElementValue);
            Assert.IsFalse(id.IsRegularExpression);
        }
コード例 #2
0
        public void TestToStringReturnsStringRepresentation([Values] bool isChildNull,
                                                            [Values] bool withValue, [Values] bool isRegularExpression)
        {
            const string name   = "name_1";
            const string value  = "Value_";
            const string xmlTag = "child_";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);
            XmlSerializableElementForTest child =
                new XmlSerializableElementForTest(xmlTag + 2, value + 2, NUnitElementType.Id);

            const string parentString = "{NUnitFilterContainerElement: {Type: RootFilter}}";
            string       childString  = isChildNull ? "Null" : "{XmlSerializableElementForTest: {Type: Id}}";
            string       elementValue = withValue ? "Value_1" : null;
            string       expected     =
                $"{{NUnitFilterElementForTest: {{Type: Test, Name: \"name_1\", Value: \"{elementValue}\"," +
                $" IsRegularExpression: {isRegularExpression}, Parent: {parentString}, Child: {childString}}}}}";

            NUnitFilterElementForTest element = new NUnitFilterElementForTest(parent, NUnitElementType.Test, name,
                                                                              isRegularExpression, elementValue);

            if (!isChildNull)
            {
                element.SetChild(child);
            }

            string actual = element.ToString();

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void TestConstructorWithValidArgumentsAndElementTypeSupportedButNotProperty(
            [ValueSource(typeof(NUnitFilterTestHelper), nameof(NUnitFilterTestHelper.GetFilterElementsExceptProperty))]
            NUnitElementType elementType, [Values] bool isRegularExpression)
        {
            const string name = "name_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;

            // NUnitElementType.Property covered in a dedicated test case
            case NUnitElementType.NUnitName:
                expectedXmlTag = "name";
                break;

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

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

            Assert.AreSame(parent, element.Parent);
            Assert.IsNull(element.Child);
            Assert.AreEqual(name, element.ElementName);
            Assert.IsNull(element.ElementValue);
            Assert.AreSame(expectedXmlTag, element.XmlTag);
            Assert.AreEqual(elementType, element.ElementType);
            Assert.AreEqual(isRegularExpression, element.IsRegularExpression);
        }
コード例 #4
0
        public void TestConstructorWithParentNullAndElementTypeRootFilter()
        {
            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            Assert.IsNull(element.Parent);
            Assert.IsNull(element.Child);
            Assert.AreEqual(NUnitElementType.RootFilter, element.ElementType);
            Assert.AreEqual(NUnitFilterTestHelper.XmlFilterTag, element.XmlTag);
        }
コード例 #5
0
        public void TestConstructorThrowsArgumentExceptionWhenNameIsNullOrEmpty([Values] bool isNull)
        {
            string name = isNull ? null : string.Empty;
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            Assert.Throws(
                Is.TypeOf <ArgumentException>().And.Message
                .EqualTo("The name cannot be null or empty. (Parameter 'name')"),
                // ReSharper disable once ObjectCreationAsStatement
                () => new NUnitFilterElement(parent, NUnitElementType.Test, name, false));
        }
コード例 #6
0
        public void TestElementNamePropertyReturnsElementNameProvidedWithConstructor()
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            INUnitFilterElementInternal element =
                new NUnitFilterElement(parent, NUnitElementType.Property, name, false, value);

            Assert.AreEqual(name, element.ElementName);
        }
コード例 #7
0
        public void TestXmlTagPropertyReturnsXmlTagProvidedWithConstructor()
        {
            const string value  = "Value_1";
            const string xmlTag = "name_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            Assert.AreEqual(NUnitFilterTestHelper.XmlAndTag, element.XmlTag);
        }
コード例 #8
0
        public void TestElementValuePropertyReturnsElementValueProvidedWithConstructor(
            [Values] bool isNull)
        {
            const string                name        = "name_1";
            string                      value       = isNull ? null : "Value_1";
            NUnitElementType            elementType = isNull ? NUnitElementType.Test : NUnitElementType.Property;
            NUnitFilterContainerElement parent      =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

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

            Assert.AreEqual(value, element.ElementValue);
        }
コード例 #9
0
        public void TestIsRegularExpressionPropertyReturnsIsRegularExpressionProvidedWithConstructor(
            [Values] bool isRegularExpression)
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            INUnitFilterElementInternal element =
                new NUnitFilterElement(parent, NUnitElementType.Property, name, isRegularExpression, value);

            Assert.AreEqual(isRegularExpression, element.IsRegularExpression);
        }
コード例 #10
0
        TestConstructorThrowsArgumentExceptionWhenElementTypeIsPropertyAndValueIsNullOrEmpty(
            [Values] bool isNull)
        {
            const string name  = "name_1";
            string       value = isNull ? null : string.Empty;
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            Assert.Throws(
                Is.TypeOf <ArgumentException>().And.Message
                .EqualTo("The value cannot be null or empty. (Parameter 'value')"),
                // ReSharper disable once ObjectCreationAsStatement
                () => new NUnitFilterElement(parent, NUnitElementType.Property, name, false, value));
        }
コード例 #11
0
        public void TestChildPropertyThrowsArgumentNullExceptionWhenChildSetToNull()
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            NUnitFilterElementForTest element =
                new NUnitFilterElementForTest(parent, NUnitElementType.Property, name, false, value);

            Assert.Throws(
                Is.TypeOf <ArgumentNullException>().And.Message
                .EqualTo("The value cannot be null. (Parameter 'value')"), () => element.SetChild(null));
        }
コード例 #12
0
        TestConstructorThrowsArgumentOutOfRangeExceptionWhenElementTypeNotSupported(
            NUnitElementType elementType)
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            Assert.Throws(
                Is.TypeOf <ArgumentOutOfRangeException>().And.Message
                .EqualTo(
                    $"The given element type is not supported. (Parameter 'elementType'){Environment.NewLine}" +
                    $"Actual value was {elementType}."),
                // ReSharper disable once ObjectCreationAsStatement
                () => new NUnitFilterElement(parent, elementType, name, false, value));
        }
コード例 #13
0
        public void TestOrPropertySetsChildAndReturnsNewOrElementWithParent()
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            INUnitFilterElementInternal element =
                new NUnitFilterElement(parent, NUnitElementType.Property, name, false, value);

            INUnitFilterElementCollectionInternal or = (INUnitFilterElementCollectionInternal)element.Or;

            Assert.IsNotNull(or);
            Assert.AreEqual(NUnitElementType.Or, or.ElementType);
            Assert.AreSame(element, or.Parent);
            Assert.AreSame(or, element.Child);
        }
コード例 #14
0
        TestIdThrowsArgumentExceptionWhenMultipleTestIdsContainsOnlyNullOrEmptyValues()
        {
            const string value  = "Value_1";
            const string xmlTag = "name_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            Assert.Throws(
                Is.TypeOf <ArgumentException>().And.Message
                .EqualTo("The name cannot be null or empty. (Parameter 'name')"), () =>
            {
                // ReSharper disable once UnusedVariable
                INUnitFilterElement id = element.Id(null, string.Empty);
            });
        }
コード例 #15
0
        public void TestChildPropertyReturnsSetChild()
        {
            const string name   = "name_1";
            const string value  = "Value_";
            const string xmlTag = "child_";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);
            XmlSerializableElementForTest child =
                new XmlSerializableElementForTest(xmlTag + 2, value + 2, NUnitElementType.Test);

            NUnitFilterElementForTest element =
                new NUnitFilterElementForTest(parent, NUnitElementType.Property, name, false, value);

            Assert.IsNull(element.Child);

            element.SetChild(child);

            Assert.AreSame(child, element.Child);
        }
コード例 #16
0
        public void TestConstructorWithValidArgumentsAndElementTypeProperty(
            [Values] bool isRegularExpression)
        {
            const string name  = "name_1";
            const string value = "Value_1";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);

            INUnitFilterElementInternal element =
                new NUnitFilterElement(parent, NUnitElementType.Property, name, isRegularExpression, value);

            Assert.AreSame(parent, element.Parent);
            Assert.IsNull(element.Child);
            Assert.AreEqual(name, element.ElementName);
            Assert.AreEqual(value, element.ElementValue);
            Assert.AreSame("prop", element.XmlTag);
            Assert.AreEqual(NUnitElementType.Property, element.ElementType);
            Assert.AreEqual(isRegularExpression, element.IsRegularExpression);
        }
コード例 #17
0
        public void TestIdThrowsArgumentExceptionWhenTestIdArrayNullOrEmpty(
            [Values] bool isNull)
        {
            string[]     names  = isNull ? null : Array.Empty <string>();
            const string value  = "Value_1";
            const string xmlTag = "name_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            Assert.Throws(
                Is.TypeOf <ArgumentException>().And.Message
                .EqualTo("The testIds cannot be null or empty. (Parameter 'testIds')"), () =>
            {
                // ReSharper disable once UnusedVariable
                INUnitFilterElement id = element.Id(names);
            });
        }
コード例 #18
0
        public void TestNameThrowsArgumentExceptionWhenNameElementNameIsNullOrEmpty(
            [Values] bool isNull)
        {
            string       name   = isNull ? null : string.Empty;
            const string value  = "Value_1";
            const string xmlTag = "parent_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            Assert.Throws(
                Is.TypeOf <ArgumentException>().And.Message
                .EqualTo("The name cannot be null or empty. (Parameter 'name')"), () =>
            {
                // ReSharper disable once UnusedVariable
                INUnitFilterElement nameElement = element.Name(name);
            });
        }
コード例 #19
0
        public void TestParentPropertyReturnsParentProvidedWithConstructor(
            [Values] bool isNull)
        {
            const string value  = "Value_1";
            const string xmlTag = "name_1";
            XmlSerializableElementForTest parent =
                isNull ? null : new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);
            NUnitElementType elementType = isNull ? NUnitElementType.RootFilter : NUnitElementType.And;

            INUnitFilterContainerElementInternal element = new NUnitFilterContainerElement(parent, elementType);

            if (isNull)
            {
                Assert.IsNull(element.Parent);
            }
            else
            {
                Assert.AreSame(parent, element.Parent);
            }
        }
コード例 #20
0
        public void TestIdWithSingleTestIdSetsChildAndReturnsNewAndElementWithParent()
        {
            const string name   = "name_1";
            const string value  = "Value_1";
            const string xmlTag = "parent_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            INUnitFilterElementInternal id = (INUnitFilterElementInternal)element.Id(name);

            Assert.IsNotNull(id);
            Assert.AreEqual(NUnitElementType.Id, id.ElementType);
            Assert.AreSame(element, id.Parent);
            Assert.AreSame(id, element.Child);
            Assert.AreEqual(name, id.ElementName);
            Assert.IsNull(id.ElementValue);
            Assert.IsFalse(id.IsRegularExpression);
        }
コード例 #21
0
        public void TestTestSetsChildAndReturnsNewAndElementWithParent(
            [Values] bool isRegularExpression)
        {
            const string name   = "name_1";
            const string value  = "Value_1";
            const string xmlTag = "parent_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            INUnitFilterContainerElementInternal element =
                new NUnitFilterContainerElement(parent, NUnitElementType.And);

            INUnitFilterElementInternal test = (INUnitFilterElementInternal)element.Test(name, isRegularExpression);

            Assert.IsNotNull(test);
            Assert.AreEqual(NUnitElementType.Test, test.ElementType);
            Assert.AreSame(element, test.Parent);
            Assert.AreSame(test, element.Child);
            Assert.AreEqual(name, test.ElementName);
            Assert.IsNull(test.ElementValue);
            Assert.AreEqual(isRegularExpression, test.IsRegularExpression);
        }
コード例 #22
0
        public void TestOrPropertyThrowsInvalidOperationExceptionWhenChildIsAlreadySet()
        {
            const string name   = "name_1";
            const string value  = "Value_";
            const string xmlTag = "child_";
            NUnitFilterContainerElement parent =
                new NUnitFilterContainerElement(null, NUnitElementType.RootFilter);
            XmlSerializableElementForTest child =
                new XmlSerializableElementForTest(xmlTag + 2, value + 2, NUnitElementType.Test);

            NUnitFilterElementForTest element =
                new NUnitFilterElementForTest(parent, NUnitElementType.Property, name, false, value);

            element.SetChild(child);

            Assert.Throws(
                Is.TypeOf <InvalidOperationException>().And.Message
                .EqualTo("The child element has already been set for this instance."), () =>
            {
                // ReSharper disable once UnusedVariable
                INUnitFilterElementCollection or = element.Or;
            });
        }
コード例 #23
0
        public void TestConstructorWithParentNotNullAndElementTypeSupportedButNotRootFilter(
            NUnitElementType elementType)
        {
            const string value  = "Value_1";
            const string xmlTag = "name_1";
            XmlSerializableElementForTest parent =
                new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.Test);

            string expectedXmlTag = null;

            switch (elementType)
            {
            // NUnitElementType.RootFilter covered in a dedicated test case
            case NUnitElementType.And:
                expectedXmlTag = NUnitFilterTestHelper.XmlAndTag;
                break;

            case NUnitElementType.Or:
                expectedXmlTag = NUnitFilterTestHelper.XmlOrTag;
                break;

            case NUnitElementType.Not:
                expectedXmlTag = NUnitFilterTestHelper.XmlNotTag;
                break;

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

            INUnitFilterContainerElementInternal element = new NUnitFilterContainerElement(parent, elementType);

            Assert.AreSame(parent, element.Parent);
            Assert.IsNull(element.Child);
            Assert.AreEqual(elementType, element.ElementType);
            Assert.AreEqual(expectedXmlTag, element.XmlTag);
        }
コード例 #24
0
        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);
        }