public void Contains_IEnumerable_ResetWasCall()
        {
            var enumerable = EnumerableMock.CreateNotEmpty();

            EnumerableExtension.Contains(enumerable, new object());
            Assert.True(enumerable.ResetWasCall);
        }
        public void Any_IEnumerableManyElems_NoUnnecessaryIterations()
        {
            EnumerableMock enumerable = EnumerableMock.CreateWintCountElems(9);

            EnumerableExtension.Any(enumerable);
            Assert.Equal(1, enumerable.MoveNextCallCounter);
        }
        public void Any_IEnumerable_ResetWasCall()
        {
            var enumerable = EnumerableMock.CreateNotEmpty();

            EnumerableExtension.Any(enumerable);
            Assert.True(enumerable.ResetWasCall);
        }
Пример #4
0
        public void CountMoreThan_IEnumerable_ResetWasCall()
        {
            var enumerable = EnumerableMock.CreateWintCountElems(1);

            EnumerableExtension.CountMoreThan(enumerable, 1);
            Assert.True(enumerable.ResetWasCall);
        }
Пример #5
0
        public void CountMoreThan_IEnumerableManyElems_NoUnnecessaryIterations()
        {
            EnumerableMock enumerable = EnumerableMock.CreateWintCountElems(100);

            EnumerableExtension.CountMoreThan(enumerable, 100);
            Assert.Equal(101, enumerable.MoveNextCallCounter);
        }
Пример #6
0
        public void SliceDelete_FromEnumerableExtensions_DoesNotCallReset()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var sut = new EnumerableMock <int>(Enumerable.Range(0, length));
                EnumerableExtensions.SliceDelete(sut, from, to, step).Sum();

                if (sut.Enumerators.Count > 0)
                {
                    var resetCallCount = sut.Enumerators.Single().ResetCallCount;

                    LazyAssert.True(
                        resetCallCount == 0,
                        () => ErrorFormatter.Format(sliceDeleteDoesntCallResetErrorFormat, from, to, step, length, resetCallCount));
                }
            });
        }
Пример #7
0
        public void Slice_FromEnumerableExtensions_CallsDisposeOnce()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var sut = new EnumerableMock<int>(Enumerable.Range(0, length));
                EnumerableExtensions.Slice(sut, from, to, step).Sum();

                if (sut.Enumerators.Count > 0)
                {
                    var disposeCallCount = sut.Enumerators.Single().DisposeCallCount;

                    LazyAssert.True(
                        disposeCallCount == 1,
                        () => ErrorFormatter.Format(sliceDisposeOnceErrorFormat, from, to, step, length, disposeCallCount));
                }
            });
        }
Пример #8
0
        public void SliceDelete_FromEnumerableExtensions_CallsDisposeOnce()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var sut = new EnumerableMock <int>(Enumerable.Range(0, length));
                EnumerableExtensions.SliceDelete(sut, from, to, step).Sum();

                if (sut.Enumerators.Count > 0)
                {
                    var disposeCallCount = sut.Enumerators.Single().DisposeCallCount;

                    LazyAssert.True(
                        disposeCallCount == 1,
                        () => ErrorFormatter.Format(sliceDeleteDisposeOnceErrorFormat, from, to, step, length, disposeCallCount));
                }
            });
        }
Пример #9
0
        public void SliceDelete_FromEnumerableExtensions_DoesntHandleExceptions()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                bool expected  = false;
                var collection = new EnumerableMock <int>(Enumerable.Range(0, length));
                collection.EnumeratorCreated += e => { e.Current = () => { expected = true; throw new InvalidOperationException(); }; };
                bool sut = false;
                try
                {
                    EnumerableExtensions.SliceDelete(collection, from, to, step).Sum();
                }
                catch (InvalidOperationException)
                {
                    sut = true;
                }

                LazyAssert.True(sut == expected, () => ErrorFormatter.Format(sliceDeleteExceptionsAreNotHandledErrorFormat, from, to, step, length));
            });
        }
Пример #10
0
        public void Slice_FromEnumerableExtensions_CallsDisposeWhenExceptionWasThrownFromMoveNext()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var sut = new EnumerableMock<int>(Enumerable.Range(0, length));
                sut.EnumeratorCreated += e => { e.MoveNext = () => { throw new InvalidOperationException(); }; };

                try
                {
                    EnumerableExtensions.Slice(sut, from, to, step).Sum();
                }
                catch (InvalidOperationException) { }

                if (sut.Enumerators.Count > 0)
                {
                    var disposeCallCount = sut.Enumerators.Single().DisposeCallCount;

                    LazyAssert.True(
                        disposeCallCount == 1,
                        () => ErrorFormatter.Format(sliceDisposeOnceErrorFormat, from, to, step, length, disposeCallCount));
                }
            });
        }
Пример #11
0
        public void SliceDelete_FromEnumerableExtensions_CallsDisposeWhenExceptionWasThrownFromCurrent()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var sut = new EnumerableMock <int>(Enumerable.Range(0, length));
                sut.EnumeratorCreated += e => { e.Current = () => { throw new InvalidOperationException(); }; };

                try
                {
                    EnumerableExtensions.SliceDelete(sut, from, to, step).Sum();
                }
                catch (InvalidOperationException) { }

                if (sut.Enumerators.Count > 0)
                {
                    var disposeCallCount = sut.Enumerators.Single().DisposeCallCount;

                    LazyAssert.True(
                        disposeCallCount == 1,
                        () => ErrorFormatter.Format(sliceDeleteDisposeOnceErrorFormat, from, to, step, length, disposeCallCount));
                }
            });
        }
Пример #12
0
 public void CountMoreThan_IEnumerableCountIsEquals_False()
 {
     Assert.False(EnumerableExtension.CountMoreThan(EnumerableMock.CreateWintCountElems(2), 2));
 }
 public void CountEquals_IEnumerableCountIsEquals_True()
 {
     Assert.True(EnumerableExtension.CountEquals(EnumerableMock.CreateWintCountElems(2), 2));
 }
Пример #14
0
 public void CountMoreThan_IEnumerableCountIsLess_False()
 {
     Assert.False(EnumerableExtension.CountMoreThan(EnumerableMock.CreateEmpty(), 1));
 }
Пример #15
0
 public void CountMoreThan_IEnumerableCountIsMore_True()
 {
     Assert.True(EnumerableExtension.CountMoreThan(EnumerableMock.CreateWintCountElems(2), 1));
 }
Пример #16
0
        public void Slice_FromEnumerableExtensions_DoesNotCallReset()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var sut = new EnumerableMock<int>(Enumerable.Range(0, length));
                EnumerableExtensions.Slice(sut, from, to, step).Sum();

                if (sut.Enumerators.Count > 0)
                {
                    var resetCallCount = sut.Enumerators.Single().ResetCallCount;

                    LazyAssert.True(
                        resetCallCount == 0,
                        () => ErrorFormatter.Format(sliceDoesntCallResetErrorFormat, from, to, step, length, resetCallCount));
                }
            });
        }
Пример #17
0
        public void Slice_FromEnumerableExtensions_DoesntHandleExceptions()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                bool expected = false;
                var collection = new EnumerableMock<int>(Enumerable.Range(0, length));
                collection.EnumeratorCreated += e => { e.Current = () => { expected = true; throw new InvalidOperationException(); }; };
                bool sut = false;
                try
                {
                    EnumerableExtensions.Slice(collection, from, to, step).Sum();
                }
                catch (InvalidOperationException)
                {
                    sut = true;
                }

                LazyAssert.True(sut == expected, () => ErrorFormatter.Format(sliceExceptionsAreNotHandledErrorFormat, from, to, step, length));
            });
        }
        public void Any_IEnumerableIsNotEmpty_True()
        {
            EnumerableMock notEmpty = EnumerableMock.CreateNotEmpty();

            Assert.True(EnumerableExtension.Any(notEmpty));
        }
        public void Any_IEnumerableIsEmpty_False()
        {
            EnumerableMock empty = EnumerableMock.CreateEmpty();

            Assert.False(EnumerableExtension.Any(empty));
        }
Пример #20
0
 public void CountLessThan_IEnumerableCountIsLess_True()
 {
     Assert.True(EnumerableExtension.CountLessThan(EnumerableMock.CreateEmpty(), 1));
 }
Пример #21
0
 public void CountLessThan_IEnumerableCountIsMore_False()
 {
     Assert.False(EnumerableExtension.CountLessThan(EnumerableMock.CreateWintCountElems(2), 1));
 }
        public void Count_IEnumerableCountIsLess_False()
        {
            int count = 10;

            Assert.Equal(count, EnumerableExtension.Count(EnumerableMock.CreateWintCountElems(count)));
        }