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