Example #1
0
        public void Iterators_Assert_DoesNotTriggerAssert_WhenFalseAndInputEmpty()
        {
            var rows     = new object[0];
            var expected = rows;

            using (var input = new MockedIterator(rows))
                using (var iterator = new AssertIterator(input, () => false, string.Empty))
                {
                    AssertProduces(iterator, expected);
                }
        }
Example #2
0
        public void Iterators_Assert_DoesNotTriggerAssert_WhenTrue()
        {
            var rows     = new object[] { 1 };
            var expected = rows;

            using (var input = new MockedIterator(rows))
                using (var iterator = new AssertIterator(input, () => true, string.Empty))
                {
                    AssertProduces(iterator, expected);
                }
        }
Example #3
0
        private static void AssertSumWithIndex(int times, int expected)
        {
            var sum     = 0;
            var indexes = new List <int>();

            times.Times(index => { ++sum; indexes.Add(index); });

            Assert.AreEqual(expected, sum);
            Assert.AreEqual(times < 0 ? 0 : times, indexes.Count);
            AssertIterator.IndexesGrow(0, indexes);
        }
Example #4
0
        private static void AssertEachWithIndex(string input)
        {
            var sb      = new StringBuilder();
            var indexes = new List <int>();

            input.Each((ch, i) => {
                sb.Append(ch);
                indexes.Add(i);
            });

            Assert.AreEqual(sb.ToString(), input);
            AssertIterator.IndexesGrow(0, indexes);
        }
Example #5
0
        public void Iterators_Assert_TriggersAssert_WhenFalseAndInputNonEmpty()
        {
            const string message = "This should be detected";

            var rows = new object[] { 1 };

            using (var input = new MockedIterator(rows))
                using (var iterator = new AssertIterator(input, () => false, message))
                {
                    iterator.Open();

                    var exception = Assert.Throws <InvalidOperationException>(() => iterator.Read());
                    Assert.Equal(exception.Message, message);
                }
        }
Example #6
0
        public void Iterators_Assert_ForwardsProperly()
        {
            var rows     = new object[] { 1, 2 };
            var expected = rows;

            using (var input = new MockedIterator(rows))
            {
                using (var iterator = new AssertIterator(input, () => true, string.Empty))
                {
                    for (var i = 0; i < 2; i++)
                    {
                        AssertProduces(iterator, expected);
                    }
                }

                Assert.Equal(2, input.TotalOpenCount);
                Assert.Equal(4, input.TotalReadCount);
                Assert.Equal(1, input.DisposalCount);
            }
        }