예제 #1
0
        public void ReadToDataTable()
        {
            var rs = RecordSetTests.generateRecordSet();

            var tblWithOneRow = new DataReaderResult(new RecordSetReader(rs), 0, 1).ToDataTable();

            Assert.Equal(1, tblWithOneRow.Rows.Count);
            Assert.Equal(4, tblWithOneRow.Columns.Count);
            Assert.Equal(0, tblWithOneRow.Rows[0]["id"]);
            Assert.Equal("Name0", tblWithOneRow.Rows[0]["name"]);

            var tblAll = new DataReaderResult(new RecordSetReader(rs)).ToDataTable();

            Assert.Equal(100, tblAll.Rows.Count);

            // load into specified DataTable
            var ds      = new DataSet();
            var testTbl = ds.Tables.Add("test");
            var idCol   = testTbl.Columns.Add("id", typeof(int));

            idCol.AllowDBNull  = false;
            testTbl.PrimaryKey = new[] { idCol };
            new DataReaderResult(new RecordSetReader(rs)).ToDataTable(testTbl);
            Assert.Equal(4, testTbl.Columns.Count);              // missed cols are added automatically
            Assert.Equal(100, testTbl.Rows.Count);
            Assert.Equal("Name20", testTbl.Rows.Find(20)["name"]);
        }
예제 #2
0
        public void ReadToDictionary()
        {
            var rs = RecordSetTests.generateRecordSet();

            var firstRecord = new DataReaderResult(new RecordSetReader(rs)).ToDictionary();

            Assert.NotNull(firstRecord);
            Assert.Equal(0, firstRecord["id"]);
            Assert.Equal(4, firstRecord.Count);

            var allRecords = new DataReaderResult(new RecordSetReader(rs)).ToDictionaryList();

            Assert.Equal(100, allRecords.Count);
        }
예제 #3
0
        public void ReadToRecordSet()
        {
            var rs = RecordSetTests.generateRecordSet();

            var allRecords = new DataReaderResult(new RecordSetReader(rs)).ToRecordSet();

            Assert.Equal(4, allRecords.Columns.Count);
            Assert.Equal(0, allRecords[0]["id"]);
            Assert.Equal(100, allRecords.Count);

            var allRecordsAsyncRes = new DataReaderResult(new RecordSetReader(rs)).ToRecordSetAsync().Result;

            Assert.Equal(100, allRecordsAsyncRes.Count);
        }
예제 #4
0
        public void ReadToModel()
        {
            var rs = RecordSetTests.generateRecordSet();

            var secondId = new DataReaderResult(new RecordSetReader(rs), 1, 1).Single <int>();

            Assert.Equal(1, secondId);

            var firstRecord = new DataReaderResult(new RecordSetReader(rs)).Single <TestModel>();

            Assert.NotNull(firstRecord);
            Assert.Equal(0, firstRecord.id);

            var allRecords = new DataReaderResult(new RecordSetReader(rs)).ToList <TestModel>();

            Assert.Equal(100, allRecords.Count);
        }
예제 #5
0
        public void Select_MultipleResultSets()
        {
            var batchCmdBuilder = new DbBatchCommandBuilder(DbAdapter.CommandBuilder.DbFactory);

            batchCmdBuilder.BeginBatch();
            batchCmdBuilder.GetSelectCommand(new Query("companies"));
            batchCmdBuilder.GetSelectCommand(new Query("contacts"));
            var selectMultipleCmd = batchCmdBuilder.EndBatch();

            (var companies, var contacts) = DbAdapter.Select(selectMultipleCmd).ExecuteReader((rdr) => {
                var companiesRes = new DataReaderResult(rdr).ToList <CompanyModelAnnotated>();
                rdr.NextResult();
                var contactsRes = new DataReaderResult(rdr).ToList <ContactModel>();
                return(companiesRes, contactsRes);
            });
            Assert.Equal(2, companies.Count);
            Assert.Equal(5, contacts.Count);
        }