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); }
public void TestCountReturnsNumberOfItems([Range(0, 3)] int count) { // Create collection ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); Assert.AreEqual(count, collection.Count); }
public void TestAddWithNullItemDoesNotAddItem() { // Create collection const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); collection.Add(null); Assert.AreEqual(count, collection.Count); }
public void TestContainsWhenItemIsPresentReturnsTrue() { // Create collection const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); Assert.AreEqual(count, collection.Count); bool contains = collection.Contains(collection.First()); Assert.IsTrue(contains); }
public void TestClearWithItemsInCollection() { // Create collection const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); Assert.AreEqual(count, collection.Count); collection.Clear(); Assert.AreEqual(0, collection.Count); }
/// <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); }
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)); }
public void TestAddWithNonNullItemAddsItem() { // Create collection and item to add const int count = 3; const string value = "Value_new"; const string xmlTag = "name_new"; XmlSerializableElementForTest item = new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.And); ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); collection.Add(item); Assert.AreEqual(count + 1, collection.Count); Assert.AreSame(item, collection.Last()); }
public void TestContainsWhenItemIsNotPresentReturnsFalse([Values] bool isNull) { // Create collection and item to search const int count = 3; const string value = "Value_new"; const string xmlTag = "name_new"; XmlSerializableElementForTest item = isNull ? null : new XmlSerializableElementForTest(xmlTag, value, NUnitElementType.And); ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); Assert.AreEqual(count, collection.Count); bool contains = collection.Contains(item); Assert.IsFalse(contains); }
public void TestRemoveWhenItemIsPresentRemovesItemAndReturnsTrue() { // Create collection const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); IList <INUnitFilterBaseElement> expected = new List <INUnitFilterBaseElement>(collection); expected.RemoveAt(0); Assert.AreEqual(count, collection.Count); bool removed = collection.Remove(collection.First()); Assert.IsTrue(removed); Assert.AreEqual(count - 1, collection.Count); CollectionAssert.AreEqual(expected, collection); }
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 TestCopyToWithItemsInCollectionCopiesToArray([Range(0, 2)] int arrayIndex) { // Create collection and expected const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); IList <INUnitFilterBaseElement> collectionList = collection.ToList(); INUnitFilterBaseElement[] expected = new INUnitFilterBaseElement[count + arrayIndex]; for (int i = arrayIndex, j = 0; i < expected.Length; i++, j++) { expected[i] = collectionList[j]; } INUnitFilterBaseElement[] array = new INUnitFilterBaseElement[count + arrayIndex]; Assert.AreEqual(count, collection.Count); collection.CopyTo(array, arrayIndex); CollectionAssert.AreEqual(expected, array); }
public void TestCopyToThrowsArgumentExceptionWhenCollectionDoesNotFitInArrayLength( [Values] bool indexOutOfRange) { // Create collection const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); // If indexOutOfRange then the array index plus collection length is longer than the array, // otherwise the array is just not long enough to hold collection int arrayLength = indexOutOfRange ? count : 0; int arrayIndex = indexOutOfRange ? 1 : 0; INUnitFilterBaseElement[] array = new INUnitFilterBaseElement[arrayLength]; Assert.Throws( Is.TypeOf <ArgumentException>().And.Message.EqualTo( "Destination array was not long enough." + " Check the destination index, length, and the array's lower bounds." + " (Parameter 'destinationArray')"), () => collection.CopyTo(array, arrayIndex)); }
public void TestGetEnumeratorWithItemsInCollection() { // Create collection const int count = 3; ExpressionCollection <INUnitFilterBaseElement> collection = NUnitFilterTestHelper.CreateCollection(count, out _); IEnumerator <INUnitFilterBaseElement> enumerator = collection.GetEnumerator(); Assert.AreEqual(count, collection.Count); Assert.IsNotNull(enumerator); // Copy enumerator to list IList <INUnitFilterBaseElement> copy = new List <INUnitFilterBaseElement>(); while (enumerator.MoveNext()) { copy.Add(enumerator.Current); } CollectionAssert.AreEqual(collection, copy); enumerator.Dispose(); }
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); }