Windows msbuild triggers too much to rebuild.
[mono.git] / mcs / class / System.Data / Test / ProviderTests / ProviderIndependant / DbDataReaderTest.cs
1 // DbDataReaderTest.cs - NUnit Test Cases for testing the
2 // DbDataReader family of classes
3 //
4 // Authors:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (c) 2008 Gert Driesen
8 //
9 // Permission is hereby granted, free of charge, to any person
10 // obtaining a copy of this software and associated documentation
11 // files (the "Software"), to deal in the Software without
12 // restriction, including without limitation the rights to use, copy,
13 // modify, merge, publish, distribute, sublicense, and/or sell copies
14 // of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 // SOFTWARE.
28
29
30 using System;
31 using System.Data;
32 using System.Data.Common;
33 using System.Data.Odbc;
34 using System.Data.SqlClient;
35 using System.Data.SqlTypes;
36 using System.Globalization;
37
38 using Mono.Data;
39
40 using NUnit.Framework;
41
42 namespace MonoTests.System.Data
43 {
44         [TestFixture]
45         [Category ("odbc")]
46         [Category ("sqlserver")]
47         public class DbDataReaderTest
48         {
49                 DbConnection conn;
50                 DbCommand cmd;
51                 DbDataReader rdr;
52
53                 [SetUp]
54                 public void SetUp ()
55                 {
56                         conn = ConnectionManager.Singleton.Connection;
57                         ConnectionManager.Singleton.OpenConnection ();
58                         cmd = conn.CreateCommand ();
59                 }
60
61                 [TearDown]
62                 public void TearDown ()
63                 {
64                         if (cmd != null)
65                                 cmd.Dispose ();
66                         if (rdr != null)
67                                 rdr.Dispose ();
68                         ConnectionManager.Singleton.CloseConnection ();
69                 }
70
71                 [Test]
72                 public void GetProviderSpecificValues_Reader_Closed ()
73                 {
74                         cmd.CommandText = "SELECT * FROM employee";
75                         rdr = cmd.ExecuteReader ();
76                         rdr.Close ();
77
78                         try {
79                                 rdr.GetProviderSpecificValues (null);
80                                 Assert.Fail ("#1");
81                         } catch (InvalidOperationException ex) {
82                                 // Invalid attempt to call MetaData
83                                 // when reader is closed
84                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
85                                 Assert.IsNull (ex.InnerException, "#3");
86                                 Assert.IsNotNull (ex.Message, "#4");
87                         }
88                 }
89
90                 [Test]
91                 public void GetProviderSpecificValues_Reader_NoData ()
92                 {
93                         cmd.CommandText = "SELECT * FROM employee where id = 6666";
94                         rdr = cmd.ExecuteReader ();
95
96                         try {
97                                 rdr.GetProviderSpecificValues (null);
98                                 Assert.Fail ("#A1");
99                         } catch (InvalidOperationException ex) {
100                                 // Invalid attempt to read when no data
101                                 // is present
102                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
103                                 Assert.IsNull (ex.InnerException, "#A3");
104                                 Assert.IsNotNull (ex.Message, "#A4");
105                         }
106
107                         Assert.IsFalse (rdr.Read (), "B");
108
109                         try {
110                                 rdr.GetProviderSpecificValues (null);
111                                 Assert.Fail ("#C1");
112                         } catch (InvalidOperationException ex) {
113                                 // Invalid attempt to read when no data
114                                 // is present
115                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
116                                 Assert.IsNull (ex.InnerException, "#C3");
117                                 Assert.IsNotNull (ex.Message, "#C4");
118                         }
119                 }
120         }
121 }
122