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); }
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); }
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); }
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); }
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); }
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); }
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); }