Esempio n. 1
0
        public void WillDisposeInternalEnumeratorAndEnumerableWhenDisposed()
        {
            IEnumerable <Row> enumerable = Substitute.For <IEnumerable <Row>, IDisposable>();
            IEnumerator <Row> enumerator = Substitute.For <IEnumerator <Row> >();

            enumerable.GetEnumerator().Returns(enumerator);

            DictionaryEnumeratorDataReader reader =
                new DictionaryEnumeratorDataReader(new Dictionary <string, Type>(), enumerable);

            reader.Dispose();

            enumerator.Received(1).Dispose();
            ((IDisposable)enumerable).Received(1).Dispose();
        }
Esempio n. 2
0
        public void WillDisposeInternalEnumeratorAndEnumerableWhenDisposed()
        {
            MockRepository         mocks      = new MockRepository();
            IAsyncEnumerable <Row> enumerable = mocks.DynamicMultiMock <IAsyncEnumerable <Row> >(typeof(IAsyncDisposable));
            IAsyncEnumerator <Row> enumerator = mocks.DynamicMock <IAsyncEnumerator <Row> >();

            using (mocks.Record())
            {
                SetupResult.For(enumerable.GetAsyncEnumerator(Arg <CancellationToken> .Is.Anything)).Return(enumerator);
                SetupResult.For(enumerator.DisposeAsync()).Return(new ValueTask());
                SetupResult.For(((IAsyncDisposable)enumerable).DisposeAsync()).Return(new ValueTask());
            }
            using (mocks.Playback())
            {
                DictionaryEnumeratorDataReader reader =
                    new DictionaryEnumeratorDataReader(new Dictionary <string, Type>(), enumerable);
                reader.Dispose();
            }
        }
        public void WillDisposeInternalEnumeratorAndEnumerableWhenDisposed()
        {
            MockRepository    mocks      = new MockRepository();
            IEnumerable <Row> enumerable = mocks.DynamicMultiMock <IEnumerable <Row> >(typeof(IDisposable));
            IEnumerator <Row> enumerator = mocks.DynamicMock <IEnumerator <Row> >();

            using (mocks.Record())
            {
                SetupResult.For(enumerable.GetEnumerator()).Return(enumerator);
                enumerator.Dispose();
                ((IDisposable)enumerable).Dispose();
            }
            using (mocks.Playback())
            {
                DictionaryEnumeratorDataReader reader =
                    new DictionaryEnumeratorDataReader(new Dictionary <string, Type>(), enumerable);
                reader.Dispose();
            }
        }