2 // SqlDataReaderTest.cs - NUnit Test Cases for testing the
5 // Umadevi S (sumadevi@novell.com)
6 // Kornél Pál <http://www.kornelpal.hu/>
7 // Sureshkumar T (tsureshkumar@novell.com)
8 // Senganal T (tsenganal@novell.com)
10 // Copyright (c) 2004 Novell Inc., and the individuals listed
11 // on the ChangeLog entries.
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.Data.SqlTypes;
37 using System.Data.Common;
38 using System.Data.SqlClient;
40 using NUnit.Framework;
42 namespace MonoTests.System.Data.SqlClient
46 [Category ("sqlserver")]
47 public class SqlDataReaderTest
49 SqlConnection conn = null;
50 SqlCommand cmd = null;
51 SqlDataReader reader = null;
52 String query = "Select type_{0},type_{1},convert({0},null) from numeric_family where id=1";
53 DataSet sqlDataset = null;
55 DataTable numericDataTable =null;
56 DataTable stringDataTable =null;
57 DataTable binaryDataTable =null;
58 DataTable datetimeDataTable =null;
60 DataRow numericRow = null;
61 DataRow stringRow = null;
62 DataRow binaryRow = null;
63 DataRow datetimeRow = null;
68 conn = new SqlConnection (ConnectionManager.Singleton.ConnectionString);
69 cmd = conn.CreateCommand ();
71 sqlDataset = (new DataProvider()).GetDataSet ();
73 numericDataTable = sqlDataset.Tables["numeric_family"];
74 stringDataTable = sqlDataset.Tables["string_family"];
75 binaryDataTable = sqlDataset.Tables["binary_family"];
76 datetimeDataTable = sqlDataset.Tables["datetime_family"];
78 numericRow = numericDataTable.Select ("id=1")[0];
79 stringRow = stringDataTable.Select ("id=1")[0];
80 binaryRow = binaryDataTable.Select ("id=1")[0];
81 datetimeRow = datetimeDataTable.Select ("id=1")[0];
90 public void TearDown ()
99 public void ReadEmptyNTextFieldTest () {
101 DBHelper.ExecuteNonQuery (conn, "create table #tmp_monotest (name ntext)");
102 DBHelper.ExecuteNonQuery (conn, "insert into #tmp_monotest values ('')");
104 SqlCommand cmd = (SqlCommand) conn.CreateCommand ();
105 cmd.CommandText = "select * from #tmp_monotest";
106 SqlDataReader dr = cmd.ExecuteReader ();
108 Assert.AreEqual("System.String",dr["NAME"].GetType().FullName);
110 Assert.AreEqual (false, dr.Read (), "#2");
112 ConnectionManager.Singleton.CloseConnection ();
117 public void ReadBingIntTest()
120 string query = "SELECT CAST(548967465189498 AS bigint) AS Value";
121 SqlCommand cmd = new SqlCommand();
122 cmd.Connection = conn;
123 cmd.CommandText = query;
124 SqlDataReader r = cmd.ExecuteReader();
126 Assert.AreEqual (true, r.Read(), "#1");
127 long id = r.GetInt64(0);
128 Assert.AreEqual(548967465189498, id, "#2");
129 id = r.GetSqlInt64(0).Value;
130 Assert.AreEqual(548967465189498, id, "#3");
133 ConnectionManager.Singleton.CloseConnection ();
139 // This method just helps in Calling common tests among all the Get* Methods
140 // without replicating code
142 void CallGetMethod (string s, int i)
145 case "Boolean" : reader.GetBoolean (i) ; break;
146 case "SqlBoolean": reader.GetSqlBoolean (i); break;
147 case "Int16" : reader.GetInt16 (i); break;
148 case "SqlInt16" : reader.GetSqlInt16 (i); break;
149 case "Int32" : reader.GetInt32 (i);break;
150 case "SqlInt32" : reader.GetSqlInt32(i);break;
151 case "Int64" : reader.GetInt64 (i);break;
152 case "SqlInt64" : reader.GetSqlInt64(i); break;
153 case "Decimal" : reader.GetDecimal(i);break;
154 case "SqlDecimal" : reader.GetSqlDecimal (i);break;
155 case "SqlMoney" : reader.GetSqlMoney (i);break;
156 case "Float" : reader.GetFloat (i);break;
157 case "SqlSingle" : reader.GetSqlSingle(i);break;
158 case "Double" : reader.GetDouble (i);break;
159 case "SqlDouble" : reader.GetSqlDouble(i);break;
160 case "Guid" : reader.GetGuid(i);break;
161 case "SqlGuid" : reader.GetSqlGuid(i);break;
162 case "String" : reader.GetString(i);break;
163 case "SqlString" : reader.GetSqlString(i);break;
164 case "Char" : reader.GetChar(i);break;
165 case "Byte" : reader.GetByte (i);break;
166 case "SqlByte" : reader.GetSqlByte(i); break;
167 case "DateTime" : reader.GetDateTime(i); break;
168 case "SqlDateTime" : reader.GetSqlDateTime(i); break;
169 case "SqlBinary" : reader.GetSqlBinary(i); break;
170 default : Console.WriteLine ("OOOOPSSSSSS {0}",s);break;
174 // This method just helps in Calling common tests among all the Get* Methods
175 // without replicating code
176 void GetMethodTests (string s)
180 CallGetMethod (s, 1);
181 Assert.Fail ("#1[Get"+s+"] InvalidCastException must be thrown");
182 }catch (AssertionException e) {
184 }catch (Exception e) {
185 Assert.AreEqual (typeof(InvalidCastException), e.GetType(),
186 "#2[Get"+s+"] Incorrect Exception : " + e);
189 // GetSql* Methods do not throw SqlNullValueException
190 // So, Testimg only for Get* Methods
191 if (!s.StartsWith("Sql")) {
193 CallGetMethod (s, 2);
194 Assert.Fail ("#3[Get"+s+"] Exception must be thrown");
195 }catch (AssertionException e) {
197 }catch (Exception e){
198 Assert.AreEqual (typeof(SqlNullValueException),e.GetType(),
199 "#4[Get"+s+"] Incorrect Exception : " + e);
204 CallGetMethod (s, 3);
205 Assert.Fail ("#5[Get"+s+"] IndexOutOfRangeException must be thrown");
206 }catch (AssertionException e) {
208 }catch (Exception e){
209 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
210 "#6[Get"+s+"] Incorrect Exception : " + e);
215 public void GetBooleanTest ()
217 cmd.CommandText = string.Format (query, "bit", "int");
218 reader = cmd.ExecuteReader ();
220 // Test for standard exceptions
221 GetMethodTests("Boolean");
223 // Test if data is returned correctly
224 Assert.AreEqual (numericRow["type_bit"], reader.GetBoolean(0),
225 "#2 DataValidation Failed");
227 // Test for standard exceptions
228 GetMethodTests("SqlBoolean");
230 // Test if data is returned correctly
231 Assert.AreEqual (numericRow["type_bit"], reader.GetSqlBoolean(0).Value,
232 "#4 DataValidation Failed");
237 public void GetByteTest ()
239 cmd.CommandText = string.Format (query, "tinyint", "int");
240 reader = cmd.ExecuteReader ();
242 // Test for standard exceptions
243 GetMethodTests("Byte");
245 // Test if data is returned correctly
246 Assert.AreEqual (numericRow["type_tinyint"], reader.GetByte(0),
247 "#2 DataValidation Failed");
249 // Test for standard exceptions
250 GetMethodTests("SqlByte");
252 // Test if data is returned correctly
253 Assert.AreEqual (numericRow["type_tinyint"], reader.GetSqlByte(0).Value,
254 "#4 DataValidation Failed");
259 public void GetInt16Test ()
261 cmd.CommandText = string.Format (query, "smallint", "int");
262 reader = cmd.ExecuteReader();
264 // Test for standard exceptions
265 GetMethodTests("Int16");
267 // Test if data is returned correctly
268 Assert.AreEqual (numericRow["type_smallint"], reader.GetInt16(0),
269 "#2 DataValidation Failed");
271 // Test for standard exceptions
272 GetMethodTests("SqlInt16");
274 // Test if data is returned correctly
275 Assert.AreEqual (numericRow["type_smallint"], reader.GetSqlInt16(0).Value,
276 "#4 DataValidation Failed");
281 public void GetInt32Test ()
283 cmd.CommandText = string.Format (query, "int", "bigint");
284 reader = cmd.ExecuteReader ();
286 // Test for standard exceptions
287 GetMethodTests("Int32");
289 // Test if data is returned correctly
290 Assert.AreEqual (numericRow["type_int"], reader.GetInt32(0),
291 "#2 DataValidation Failed");
293 // Test for standard exceptions
294 GetMethodTests("SqlInt32");
296 // Test if data is returned correctly
297 Assert.AreEqual (numericRow["type_int"], reader.GetSqlInt32(0).Value,
298 "#4 DataValidation Failed");
303 public void GetInt64Test ()
305 cmd.CommandText = string.Format (query, "bigint", "int");
306 reader = cmd.ExecuteReader ();
309 // Test for standard exceptions
310 GetMethodTests("Int64");
312 // Test if data is returned correctly
313 Assert.AreEqual (numericRow["type_bigint"], reader.GetInt64(0),
314 "#2 DataValidation Failed");
316 // Test for standard exceptions
317 GetMethodTests("SqlInt64");
319 // Test if data is returned correctly
320 Assert.AreEqual (numericRow["type_bigint"], reader.GetSqlInt64(0).Value,
321 "#4 DataValidation Failed");
326 public void GetDecimalTest ()
328 cmd.CommandText = string.Format (query, "decimal", "int");
329 reader = cmd.ExecuteReader ();
331 // Test for standard exceptions
332 GetMethodTests("Decimal");
334 // Test if data is returned correctly
335 Assert.AreEqual (numericRow["type_decimal"], reader.GetDecimal(0),
336 "#2 DataValidation Failed");
338 // Test for standard exceptions
339 GetMethodTests("SqlDecimal");
341 // Test if data is returned correctly
342 Assert.AreEqual (numericRow["type_decimal"], reader.GetSqlDecimal(0).Value,
343 "#4 DataValidation Failed");
348 public void GetSqlMoneyTest ()
350 cmd.CommandText = string.Format (query, "money", "int");
351 reader = cmd.ExecuteReader ();
353 // Test for standard exceptions
354 GetMethodTests("SqlMoney");
356 // Test if data is returned correctly
357 Assert.AreEqual (numericRow["type_money"], reader.GetSqlMoney(0).Value,
358 "#2 DataValidation Failed");
363 public void GetFloatTest ()
365 cmd.CommandText = "select type_float,type_double,convert(real,null)";
366 cmd.CommandText += "from numeric_family where id=1";
367 reader = cmd.ExecuteReader ();
369 // Test for standard exceptions
370 GetMethodTests("Float");
372 // Test if data is returned correctly
373 Assert.AreEqual (numericRow["type_float"], reader.GetFloat(0),
374 "#2 DataValidation Failed");
376 // Test for standard exceptions
377 GetMethodTests("SqlSingle");
379 // Test if data is returned correctly
380 Assert.AreEqual (numericRow["type_float"], reader.GetSqlSingle(0).Value,
381 "#2 DataValidation Failed");
386 public void GetDoubleTest ()
388 cmd.CommandText = "select type_double,type_float,convert(float,null)";
389 cmd.CommandText += " from numeric_family where id=1";
390 reader = cmd.ExecuteReader ();
392 // Test for standard exceptions
393 GetMethodTests("Double");
395 // Test if data is returned correctly
396 Assert.AreEqual (numericRow["type_double"], reader.GetDouble(0),
397 "#2 DataValidation Failed");
399 // Test for standard exceptions
400 GetMethodTests("SqlDouble");
402 // Test if data is returned correctly
403 Assert.AreEqual (numericRow["type_double"], reader.GetSqlDouble(0).Value,
404 "#4 DataValidation Failed");
409 public void GetBytesTest ()
411 cmd.CommandText = "Select type_text,type_ntext,convert(text,null) ";
412 cmd.CommandText += "from string_family where id=1";
413 reader = cmd.ExecuteReader ();
416 reader.GetBytes (0,0,null,0,0);
417 Assert.Fail ("#1 GetBytes shud be used only wth Sequential Access");
418 }catch (AssertionException e) {
420 }catch (Exception e) {
421 Assert.AreEqual (typeof(InvalidCastException), e.GetType (),
422 "#2 Incorrect Exception : " + e);
426 byte[] asciiArray = (new ASCIIEncoding ()).GetBytes ("text");
427 byte[] unicodeArray = (new UnicodeEncoding ()).GetBytes ("ntext");
428 byte[] buffer = null ;
431 reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
433 size = reader.GetBytes (0,0,null,0,0);
434 Assert.AreEqual (asciiArray.Length, size, "#3 Data Incorrect");
436 buffer = new byte[size];
437 size = reader.GetBytes (0,0,buffer,0,(int)size);
438 for (int i=0;i<size; i++)
439 Assert.AreEqual (asciiArray[i], buffer[i], "#4 Data Incorrect");
441 size = reader.GetBytes (1,0,null,0,0);
442 Assert.AreEqual (unicodeArray.Length, size, "#5 Data Incorrect");
443 buffer = new byte[size];
444 size = reader.GetBytes (1,0,buffer,0,(int)size);
445 for (int i=0;i<size; i++)
446 Assert.AreEqual (unicodeArray[i], buffer[i], "#6 Data Incorrect");
448 // Test if msdotnet behavior s followed when null value
449 // is read using GetBytes
450 Assert.AreEqual (0, reader.GetBytes (2,0,null,0,0), "#7");
451 reader.GetBytes (2,0,buffer,0,10);
454 // do i need to test for image/binary values also ???
458 public void GetStringTest ()
460 cmd.CommandText = "Select type_varchar,10,convert(varchar,null)";
461 cmd.CommandText += "from string_family where id=1";
462 reader = cmd.ExecuteReader ();
464 // Test for standard exceptions
465 GetMethodTests("String");
467 // Test if data is returned correctly
468 Assert.AreEqual (stringRow["type_varchar"], reader.GetString(0),
469 "#2 DataValidation Failed");
471 // Test for standard exceptions
472 GetMethodTests("SqlString");
474 // Test if data is returned correctly
475 Assert.AreEqual (stringRow["type_varchar"], reader.GetSqlString(0).Value,
476 "#4 DataValidation Failed");
481 public void GetSqlBinaryTest ()
483 cmd.CommandText = "Select type_binary ,10 ,convert(binary,null)";
484 cmd.CommandText += "from binary_family where id=1";
485 reader = cmd.ExecuteReader ();
487 // Test for standard exceptions
488 GetMethodTests ("SqlBinary");
490 // Test if data is returned correctly
491 Assert.AreEqual (binaryRow["type_binary"], reader.GetSqlBinary(0).Value,
492 "#2 DataValidation Failed");
497 public void GetGuidTest ()
499 cmd.CommandText = "Select type_guid,id,convert(uniqueidentifier,null)";
500 cmd.CommandText += "from string_family where id=1";
501 reader = cmd.ExecuteReader ();
504 // Test for standard exceptions
505 GetMethodTests("Guid");
507 // Test if data is returned correctly
508 Assert.AreEqual (stringRow["type_guid"], reader.GetGuid(0),
509 "#2 DataValidation Failed");
511 // Test for standard exceptions
512 GetMethodTests("SqlGuid");
514 // Test if data is returned correctly
515 Assert.AreEqual (stringRow["type_guid"], reader.GetSqlGuid(0).Value,
516 "#4 DataValidation Failed");
521 public void GetDateTimeTest ()
523 cmd.CommandText = "Select type_datetime,10,convert(datetime,null)";
524 cmd.CommandText += "from datetime_family where id=1";
525 reader = cmd.ExecuteReader ();
528 // Test for standard exceptions
529 GetMethodTests("DateTime");
531 // Test if data is returned correctly
532 Assert.AreEqual (datetimeRow["type_datetime"], reader.GetDateTime(0),
533 "#2 DataValidation Failed");
535 // Test for standard exceptions
536 GetMethodTests("SqlDateTime");
538 // Test if data is returned correctly
539 Assert.AreEqual (datetimeRow["type_datetime"], reader.GetSqlDateTime(0).Value,
540 "#2 DataValidation Failed");
545 [Ignore ("Not Supported by msdotnet")]
546 public void GetCharTest ()
548 cmd.CommandText = "Select type_char,type_guid,convert(char,null)";
549 cmd.CommandText += "from string_family where id=1";
550 reader = cmd.ExecuteReader ();
552 // Test for standard exceptions
553 GetMethodTests ("Char");
558 public void GetValueTest ()
560 cmd.CommandText = "Select id, null from numeric_family where id=1";
561 reader = cmd.ExecuteReader ();
565 obj = reader.GetValue (0);
566 Assert.AreEqual ((byte)1, obj, "#1 Shud return the value of id");
567 obj = reader.GetValue (1);
568 Assert.AreEqual (DBNull.Value, obj, "#2 shud return DBNull");
573 public void GetSqlValueTest ()
575 cmd.CommandText = "Select id, type_tinyint, null from numeric_family where id=1";
576 reader = cmd.ExecuteReader ();
579 Assert.AreEqual ((byte)255, ((SqlByte) reader.GetSqlValue(1)).Value, "#1");
580 //Assert.AreEqual (DBNull.Value, reader.GetSqlValue(2), "#2");
586 public void GetValuesTest ()
588 cmd.CommandText = "Select 10,20,30 from numeric_family where id=1";
589 reader = cmd.ExecuteReader ();
595 count = reader.GetValues (arr);
596 Assert.AreEqual (10, (int)arr[0], "#1 Only first object shud be copied");
597 Assert.AreEqual (1, count, "#1 return value shud equal objects copied");
600 count = reader.GetValues (arr);
601 Assert.AreEqual (3, count, "#2 return value shud equal objects copied");
604 count = reader.GetValues (arr);
605 Assert.AreEqual (3, count, "#3 return value shud equal objects copied");
606 Assert.IsNull (arr[3], "#4 Only 3 objects shud be copied");
612 public void GetSqlValuesTest ()
614 cmd.CommandText = "Select 10,20,30 from numeric_family where id=1";
615 reader = cmd.ExecuteReader ();
621 count = reader.GetSqlValues (arr);
622 // Something is wrong with types ... gotta figure it out
623 //Assert.AreEqual (10, arr[0], "#1 Only first object shud be copied");
624 Assert.AreEqual (1, count, "#1 return value shud equal objects copied");
627 count = reader.GetSqlValues (arr);
628 Assert.AreEqual (3, count, "#2 return value shud equal objects copied");
631 count = reader.GetSqlValues (arr);
632 Assert.AreEqual (3, count, "#3 return value shud equal objects copied");
633 Assert.IsNull (arr[3], "#4 Only 3 objects shud be copied");
639 public void isDBNullTest ()
641 cmd.CommandText = "select id , null from numeric_family where id=1";
642 reader = cmd.ExecuteReader ();
645 Assert.IsFalse (reader.IsDBNull (0), "#1");
646 Assert.IsTrue (reader.IsDBNull (1) , "#2");
649 reader.IsDBNull (10);
650 Assert.Fail ("#1 Invalid Argument");
651 }catch (AssertionException e) {
653 }catch (Exception e) {
654 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
655 "#1 Incorrect Exception : " + e);
660 public void ReadTest ()
662 cmd.CommandText = "select id, type_bit from numeric_family where id=1" ;
663 reader = cmd.ExecuteReader ();
664 Assert.IsTrue (reader.Read () , "#1");
665 Assert.IsFalse (reader.Read (), "#2");
670 Assert.Fail ("#3 Exception shud be thrown : Reader is closed");
671 }catch (AssertionException e) {
673 }catch (Exception e) {
674 Assert.AreEqual (typeof(InvalidOperationException), e.GetType (),
675 "#4 Incorrect Exception : " + e);
680 public void NextResultTest ()
682 cmd.CommandText = "Select id from numeric_family where id=1";
683 reader = cmd.ExecuteReader ();
684 Assert.IsFalse (reader.NextResult (), "#1");
687 cmd.CommandText = "select id from numeric_family where id=1;";
688 cmd.CommandText += "select type_bit from numeric_family where id=2;";
689 reader = cmd.ExecuteReader ();
690 Assert.IsTrue (reader.NextResult (), "#2");
691 Assert.IsFalse (reader.NextResult (), "#3");
695 reader.NextResult ();
696 Assert.Fail ("#4 Exception shud be thrown : Reader is closed");
697 }catch (AssertionException e) {
699 }catch (Exception e) {
700 Assert.AreEqual (typeof(InvalidOperationException), e.GetType (),
701 "#5 Incorrect Exception : " + e);
706 public void GetNameTest ()
708 cmd.CommandText = "Select id,10 as gen,20 from numeric_family where id=1";
709 reader = cmd.ExecuteReader ();
711 Assert.AreEqual ("id" , reader.GetName(0) , "#1");
712 Assert.AreEqual ("gen" , reader.GetName(1) , "#2");
716 Assert.Fail ("#4 Exception shud be thrown");
717 }catch (AssertionException e) {
719 }catch (Exception e) {
720 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
721 "#5 Incorrect Exception : " + e);
726 public void GetOrdinalTest ()
728 //what is kana-width insensitive ?????
729 cmd.CommandText = "Select id,10 as gen,20 from numeric_family where id=1";
730 reader = cmd.ExecuteReader ();
732 Assert.AreEqual (0, reader.GetOrdinal ("id"), "#1");
733 Assert.AreEqual (0, reader.GetOrdinal ("ID"), "#2");
734 Assert.AreEqual (1, reader.GetOrdinal ("gen"), "#3");
735 // Would expect column1,columnn2 etc for unnamed columns,
736 // but msdotnet return empty string for unnamed columns
737 Assert.AreEqual (2, reader.GetOrdinal (""), "#4");
740 reader.GetOrdinal ("invalidname");
741 }catch (AssertionException e) {
743 }catch (Exception e) {
744 Assert.AreEqual (typeof (IndexOutOfRangeException),
745 e.GetType(), "#4 Incorrect Exception : " + e);
750 public void GetSchemaTableTest ()
752 cmd.CommandText = "Select type_decimal as decimal,id,10 ";
753 cmd.CommandText += "from numeric_family where id=1";
754 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
755 DataTable schemaTable = reader.GetSchemaTable ();
756 DataRow row0 = schemaTable.Rows[0];
757 DataRow row1 = schemaTable.Rows[1];
759 Assert.AreEqual ("decimal", row0["ColumnName"], "#1");
760 Assert.AreEqual ("", schemaTable.Rows[2]["ColumnName"], "#2");
762 Assert.AreEqual (0, row0["ColumnOrdinal"], "#2");
763 Assert.AreEqual (17, row0["ColumnSize"], "#3");
764 Assert.AreEqual (38, row0["NumericPrecision"], "#4");
765 Assert.AreEqual (0, row0["NumericScale"], "#5");
767 Assert.AreEqual (false, row0["IsUnique"], "#6");
768 // msdotnet returns IsUnique as false for Primary key
769 // even though table consists of a single Primary Key
770 //Assert.AreEqual (true, row1["IsUnique"], "#7");
771 Assert.AreEqual (false, row0["IsKey"], "#8");
772 Assert.AreEqual (true, row1["IsKey"], "#9");
774 //Assert.AreEqual ("servername", row0["BaseServerName"], "#10");
775 //Assert.AreEqual ("monotest", row0["BaseCatalogName"], "#11");
776 Assert.AreEqual ("type_decimal", row0["BaseColumnName"], "#12");
777 //Assert.IsNull(row0["BaseSchemaName"], "#13");
778 Assert.AreEqual ("numeric_family", row0["BaseTableName"], "#14");
779 Assert.AreEqual (typeof (Decimal), row0["DataType"], "#15");
780 Assert.AreEqual (true, row0["AllowDBNull"], "#16");
781 Assert.AreEqual (false, row1["AllowDBNull"], "#17");
782 //Assert.IsNull(row0["ProviderType"], "#18");
783 Assert.AreEqual (true, row0["IsAliased"], "#19");
784 Assert.AreEqual (false, row1["IsAliased"], "#20");
786 Assert.AreEqual (false, row0["IsExpression"], "#21");
787 Assert.AreEqual (false, row0["IsIdentity"], "#22");
788 Assert.AreEqual (false, row0["IsAutoIncrement"], "#23");
789 Assert.AreEqual (false, row0["IsRowVersion"], "#24");
790 Assert.AreEqual (false, row0["IsHidden"], "#25");
791 Assert.AreEqual (false, row0["IsLong"], "#26");
792 Assert.AreEqual (false, row0["IsReadOnly"], "#27");
793 Assert.AreEqual (true, schemaTable.Rows[2]["IsReadOnly"], "#27");
795 // Test Exception is thrown when reader is closed
798 reader.GetSchemaTable ();
799 Assert.Fail ("#28 Exception shud be thrown" );
800 }catch (AssertionException e) {
802 }catch (Exception e) {
803 Assert.AreEqual (typeof(InvalidOperationException), e.GetType(),
804 "#29 Incorrect Exception");
809 public void GetDataTypeNameTest ()
811 cmd.CommandText = "Select id, type_tinyint, 10,null from numeric_family where id=1";
812 reader = cmd.ExecuteReader ();
814 Assert.AreEqual ("tinyint", reader.GetDataTypeName(1), "#1");
815 Assert.AreEqual ("int", reader.GetDataTypeName(2), "#2");
816 //need check on windows
817 Assert.AreEqual ("int", reader.GetDataTypeName(3), "#3");
819 reader.GetDataTypeName (10);
820 Assert.Fail ("#4 Exception shud be thrown");
821 }catch (AssertionException e) {
823 }catch (Exception e) {
824 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
825 "#5 Incorrect Exception : " + e);
830 public void GetFieldTypeTest ()
832 cmd.CommandText = "Select id , type_tinyint, 10 , null from numeric_family where id=1";
833 reader = cmd.ExecuteReader ();
835 Assert.AreEqual ("tinyint", reader.GetDataTypeName(1), "#1");
836 Assert.AreEqual ("int", reader.GetDataTypeName(2) , "#2");
837 Assert.AreEqual ("int", reader.GetDataTypeName(3), "#3");
839 reader.GetDataTypeName (10);
840 Assert.Fail ("#4 Exception shud be thrown");
841 }catch (AssertionException e) {
843 }catch (Exception e) {
844 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
845 "#5 Incorrect Exception : " + e);
849 // Need to populate the data from a config file
850 // Will be replaced later
851 void validateData(string sqlQuery, DataTable table)
853 string fmt = "#TAB[{0}] ROW[{1}] COL[{2}] Data Mismatch";
855 int noOfColumns = table.Columns.Count ;
858 cmd.CommandText = sqlQuery ;
859 reader = cmd.ExecuteReader ();
861 while (reader.Read ()){
862 for (int j=1; j< noOfColumns ; ++j)
863 Assert.AreEqual (table.Rows[i][j], reader[j],
864 String.Format (fmt, table.TableName, i+1, j));
872 public void NumericDataValidation ()
874 validateData ("select * from numeric_family order by id ASC",
879 public void StringDataValidation ()
881 validateData ("select * from string_family order by id ASC",
886 public void BinaryDataValidation ()
888 validateData ("select * from binary_family order by id ASC",
893 public void DatetimeDataValidation ()
895 validateData ("select * from datetime_family order by id ASC",