Ejemplo n.º 1
0
        public void ShouldCallCleanup()
        {
            // Arrange
            bool cleanedUp = false;

            var list = BufferedEnumerable.Create("ABC".ToIterator(), () => cleanedUp = true)
                       .ToList();

            // Act
            Assert.AreEqual(3, list.Count);

            SpinWait.SpinUntil(() => cleanedUp, 1000);

            Assert.True(cleanedUp);
        }
Ejemplo n.º 2
0
        public static IEnumerable <IDictionary <string, object> > ToBufferedEnumerable(this IDbCommand command)
        {
            try
            {
                command.Connection.Open();
            }
            catch (DbException ex)
            {
                throw new AdoAdapterException(ex.Message, ex);
            }
            var reader = command.ExecuteReaderWithExceptionWrap();
            var index  = reader.CreateDictionaryIndex();

            return(BufferedEnumerable.Create(() => reader.Read()
                                                       ? Maybe.Some(reader.ToDictionary(index))
                                                       : Maybe <IDictionary <string, object> > .None,
                                             () => { using (command.Connection) using (command) using (reader) {}}));
        }
Ejemplo n.º 3
0
        public static IEnumerable <IDictionary <string, object> > ToBufferedEnumerable(this IDbCommand command, IDbConnection connection, IDictionary <string, int> index)
        {
            try
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
            }
            catch (DbException ex)
            {
                throw new AdoAdapterException(ex.Message, ex);
            }
            var reader = command.ExecuteReaderWithExceptionWrap();

            return(BufferedEnumerable.Create(() => reader.Read()
                                                       ? Maybe.Some(reader.ToDictionary(index))
                                                       : Maybe <IDictionary <string, object> > .None,
                                             () => DisposeCommandAndReader(connection, command, reader)));
        }