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