Ejemplo n.º 1
0
        public void TestCountReturnsNumberOfItems([Range(0, 3)] int count)
        {
            // Create collection
            ExpressionCollection <INUnitFilterBaseElement> collection =
                NUnitFilterTestHelper.CreateCollection(count, out _);

            Assert.AreEqual(count, collection.Count);
        }
Ejemplo n.º 2
0
        public void TestAddWithNullItemDoesNotAddItem()
        {
            // Create collection
            const int count = 3;
            ExpressionCollection <INUnitFilterBaseElement> collection =
                NUnitFilterTestHelper.CreateCollection(count, out _);

            collection.Add(null);

            Assert.AreEqual(count, collection.Count);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        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();
        }