Exemple #1
0
        public void RecordSetReader()
        {
            var testRS = generateRecordSet();

            var rdr = new RecordSetReader(testRS);

            Assert.True(rdr.HasRows);
            Assert.Throws <InvalidOperationException>(() => { var o = rdr[0]; });

            Assert.True(rdr.Read());
            Assert.Equal(4, rdr.FieldCount);
            Assert.Equal("id", rdr.GetName(0));
            Assert.Equal(2, rdr.GetOrdinal("amount"));
            Assert.Equal("added_date", rdr.GetName(3));
            Assert.Throws <IndexOutOfRangeException>(() => { var o = rdr.GetName(4); });

            Assert.Equal(0, rdr.GetInt32(0));
            Assert.Equal(0, rdr[0]);
            Assert.Equal("Name0", rdr[1]);
            Assert.Equal(0, rdr[2]);
            Assert.Equal(1, rdr.GetDateTime(3).Month);

            int cnt = 1;

            while (rdr.Read())
            {
                Assert.Equal(cnt, rdr[0]);
                cnt++;
            }
            Assert.Throws <InvalidOperationException>(() => { var o = rdr[0]; });

            rdr.Dispose();
            Assert.Throws <InvalidOperationException>(() => { var o = rdr.FieldCount; });
            Assert.Throws <InvalidOperationException>(() => { var o = rdr.GetOrdinal("id"); });

            Assert.Equal(100, cnt);

            // read RS from RecordSetReader
            var testRSCopy = RecordSet.FromReader(new RecordSetReader(testRS));

            Assert.Equal(testRS.Count, testRSCopy.Count);
            Assert.Equal(testRS.Columns.Count, testRSCopy.Columns.Count);

            var testRSCopyOneRec = RecordSet.FromReader(new RecordSetReader(testRS), 1);

            Assert.Equal(1, testRSCopyOneRec.Count);

            // read into initialized RecordSet
            var newRS = new RecordSet(
                new[] {
                new RecordSet.Column("id", typeof(int)),
                new RecordSet.Column("name", typeof(string))
            }
                );

            newRS.Load(new RecordSetReader(testRS));
            Assert.Equal(testRS.Count, newRS.Count);
            Assert.Equal("Name99", newRS[99].Field <string>("name"));
        }
Exemple #2
0
        public void RecordSetReader()
        {
            var testRS = new RecordSet(new [] {
                new RecordSet.Column("id", typeof(int)),
                new RecordSet.Column("name", typeof(string)),
                new RecordSet.Column("amount", typeof(decimal)),
                new RecordSet.Column("added_date", typeof(DateTime))
            });

            for (int i = 0; i < 100; i++)
            {
                testRS.Add(new object[] {
                    i, "Name" + i.ToString(), i % 20, new DateTime(2000, 1, 1).AddMonths(i)
                });
            }

            var rdr = new RecordSetReader(testRS);

            Assert.True(rdr.HasRows);
            Assert.Throws <InvalidOperationException>(() => { var o = rdr[0]; });

            Assert.True(rdr.Read());
            Assert.Equal(4, rdr.FieldCount);
            Assert.Equal("id", rdr.GetName(0));
            Assert.Equal(2, rdr.GetOrdinal("amount"));
            Assert.Equal("added_date", rdr.GetName(3));
            Assert.Throws <IndexOutOfRangeException>(() => { var o = rdr.GetName(4); });

            Assert.Equal(0, rdr.GetInt32(0));
            Assert.Equal(0, rdr[0]);
            Assert.Equal("Name0", rdr[1]);
            Assert.Equal(0, rdr[2]);
            Assert.Equal(1, rdr.GetDateTime(3).Month);

            int cnt = 1;

            while (rdr.Read())
            {
                Assert.Equal(cnt, rdr[0]);
                cnt++;
            }
            Assert.Throws <InvalidOperationException>(() => { var o = rdr[0]; });

            rdr.Dispose();
            Assert.Throws <InvalidOperationException>(() => { var o = rdr.FieldCount; });
            Assert.Throws <InvalidOperationException>(() => { var o = rdr.GetOrdinal("id"); });

            Assert.Equal(100, cnt);

            // read RS from RecordSetReader
            var testRSCopy = RecordSet.FromReader(new RecordSetReader(testRS));

            Assert.Equal(testRS.Count, testRSCopy.Count);
            Assert.Equal(testRS.Columns.Count, testRSCopy.Columns.Count);

            // read into initialized RecordSet
            var newRS = new RecordSet(
                new[] {
                new RecordSet.Column("id", typeof(int)),
                new RecordSet.Column("name", typeof(string))
            }
                );

            newRS.Load(new RecordSetReader(testRS));
            Assert.Equal(testRS.Count, newRS.Count);
            Assert.Equal("Name99", newRS[99].Field <string>("name"));
        }
Exemple #3
0
 public void Dispose() => recordSetReader.Dispose();