Exemplo n.º 1
0
        public void TripleEntryEnumerable()
        {
            List <string> list = new List <string>();

            list.Add("x");
            list.Add("y");
            list.Add("z");

            SmartEnumerable <string> subject = new SmartEnumerable <string>(list);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = subject.GetEnumerator())
            {
                Assert.IsTrue(iterator.MoveNext());
                Assert.IsTrue(iterator.Current.IsFirst);
                Assert.IsFalse(iterator.Current.IsLast);
                Assert.AreEqual("x", iterator.Current.Value);
                Assert.AreEqual(0, iterator.Current.Index);

                Assert.IsTrue(iterator.MoveNext());
                Assert.IsFalse(iterator.Current.IsFirst);
                Assert.IsFalse(iterator.Current.IsLast);
                Assert.AreEqual("y", iterator.Current.Value);
                Assert.AreEqual(1, iterator.Current.Index);

                Assert.IsTrue(iterator.MoveNext());
                Assert.IsFalse(iterator.Current.IsFirst);
                Assert.IsTrue(iterator.Current.IsLast);
                Assert.AreEqual("z", iterator.Current.Value);
                Assert.AreEqual(2, iterator.Current.Index);
                Assert.IsFalse(iterator.MoveNext());
            }
        }
Exemplo n.º 2
0
        public void EmptyEnumerable()
        {
            List<string> emptyList = new List<string>();

            SmartEnumerable<string> subject = new SmartEnumerable<string>(emptyList);
            using (IEnumerator<SmartEnumerable<string>.Entry> iterator = subject.GetEnumerator())
            {
                Assert.IsFalse(iterator.MoveNext());
            }
        }
Exemplo n.º 3
0
        public void SmartEnumerableDoesNotIterateForEmptyCollection()
        {
            IList <string> inner = new List <string>();

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                Assert.IsFalse(iterator.MoveNext());
            }
        }
Exemplo n.º 4
0
        public void EmptyEnumerable()
        {
            List <string> emptyList = new List <string>();

            SmartEnumerable <string> subject = new SmartEnumerable <string>(emptyList);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = subject.GetEnumerator())
            {
                Assert.IsFalse(iterator.MoveNext());
            }
        }
Exemplo n.º 5
0
 private static void TestSingleEntry(SmartEnumerable<string> subject)
 {
     using (IEnumerator<SmartEnumerable<string>.Entry> iterator = subject.GetEnumerator())
     {
         Assert.IsTrue(iterator.MoveNext());
         Assert.IsTrue(iterator.Current.IsFirst);
         Assert.IsTrue(iterator.Current.IsLast);
         Assert.AreEqual("x", iterator.Current.Value);
         Assert.AreEqual(0, iterator.Current.Index);
         Assert.IsFalse(iterator.MoveNext());
     }
 }
Exemplo n.º 6
0
 private static void TestSingleEntry(SmartEnumerable <string> subject)
 {
     using (IEnumerator <SmartEnumerable <string> .Entry> iterator = subject.GetEnumerator())
     {
         Assert.IsTrue(iterator.MoveNext());
         Assert.IsTrue(iterator.Current.IsFirst);
         Assert.IsTrue(iterator.Current.IsLast);
         Assert.AreEqual("x", iterator.Current.Value);
         Assert.AreEqual(0, iterator.Current.Index);
         Assert.IsFalse(iterator.MoveNext());
     }
 }
Exemplo n.º 7
0
        public void SmartEnumerableIteratesForCollectionWithSingleEntry()
        {
            List <string> inner = new List <string> {
                "a"
            };

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                iterator.MoveNext();

                var current = iterator.Current;
                Assert.IsNotNull(current);
            }
        }
Exemplo n.º 8
0
        public void SmartEnumerableForCollectionWithMoreThanOneEntryStopsIterating()
        {
            List <string> inner = new List <string> {
                "a", "b"
            };

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                iterator.MoveNext();
                iterator.MoveNext();

                Assert.IsFalse(iterator.MoveNext());
            }
        }
Exemplo n.º 9
0
        public void SmartEnumerableIteratorWithMoreThanOneEntryReturnsFirstEntryWithExpectedIndex()
        {
            List <string> inner = new List <string> {
                "a", "b"
            };

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                iterator.MoveNext();

                var first = iterator.Current;

                Assert.AreEqual(0, first.Index);
            }
        }
Exemplo n.º 10
0
        public void SmartEnumerableIteratorForCollectionWithMoreThanOneEntryReturnsEntryThatIsFirstButNotLast()
        {
            List <string> inner = new List <string> {
                "a", "b"
            };

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                iterator.MoveNext();

                var first = iterator.Current;

                Assert.IsTrue(first.IsFirst);
                Assert.IsFalse(first.IsLast);
            }
        }
Exemplo n.º 11
0
        public void SmartEnumerableIteratorReturnsSingleEntryThatIsFirstAndLastEntry()
        {
            List <string> inner = new List <string> {
                "a"
            };

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                iterator.MoveNext();

                var current = iterator.Current;

                Assert.IsTrue(current.IsFirst);
                Assert.IsTrue(current.IsLast);
            }
        }
Exemplo n.º 12
0
        public void SmartEnumerableIteratorReturnsSingleEntryWithExpectedValue()
        {
            const string expected = "a";

            List <string> inner = new List <string> {
                "a"
            };

            SmartEnumerable <string> smart = new SmartEnumerable <string>(inner);

            using (IEnumerator <SmartEnumerable <string> .Entry> iterator = smart.GetEnumerator())
            {
                iterator.MoveNext();

                var current = iterator.Current;

                Assert.AreEqual(expected, current.Value);
            }
        }
Exemplo n.º 13
0
        public void DoubleEntryEnumerable()
        {
            List<string> list = new List<string>();
            list.Add("x");
            list.Add("y");

            SmartEnumerable<string> subject = new SmartEnumerable<string>(list);
            using (IEnumerator<SmartEnumerable<string>.Entry> iterator = subject.GetEnumerator())
            {
                Assert.IsTrue(iterator.MoveNext());
                Assert.IsTrue(iterator.Current.IsFirst);
                Assert.IsFalse(iterator.Current.IsLast);
                Assert.AreEqual("x", iterator.Current.Value);
                Assert.AreEqual(0, iterator.Current.Index);

                Assert.IsTrue(iterator.MoveNext());
                Assert.IsFalse(iterator.Current.IsFirst);
                Assert.IsTrue(iterator.Current.IsLast);
                Assert.AreEqual("y", iterator.Current.Value);
                Assert.AreEqual(1, iterator.Current.Index);
                Assert.IsFalse(iterator.MoveNext());
            }
        }