Ejemplo n.º 1
0
        public void SliceDelete_FromEnumerableExtensions_ReturnsCorrectValues()
        {
            this.RunSliceTestCases((from, to, step, length) =>
            {
                var source   = Enumerable.Range(0, length);
                var sut      = EnumerableExtensions.SliceDelete(source, from, to, step).ToArray();
                var expected = SliceDeleteExpectedResultCalculator.Calculate(from, to, step, length);

                LazyAssert.True(
                    expected.SequenceEqual(sut),
                    () => ErrorFormatter.Format(sliceDeleteResultErrorFormat, source, from, to, step, expected, sut));
            });
        }
Ejemplo n.º 2
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));
                }
            });
        }
Ejemplo n.º 3
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));
                }
            });
        }
Ejemplo n.º 4
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));
            });
        }
Ejemplo n.º 5
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));
                }
            });
        }