MemoryMappedFile support on Windows
[mono.git] / mcs / class / System.Data / Test / MSSqlTestBed.cs
1 //
2 // MSSqlTestBed.cs : This is base class which manages the connections to 
3 //                    MSSql database. This serves as a base class for all
4 //                    MSSql database dependant tests.
5 //
6 // To run :
7 //  
8 //  * compile using following command
9 //      mcs /r:System.Data.dll,nunit.framework.dll /t:library /debug
10 //      /out:MSSqlTestBed.dll MSSqlTestBed.cs System.Data.Common/*.cs
11 //  * To run the tests
12 //      mono /usr/local/bin/nunit-console.exe MSSqlTestBed.dll
13 //
14 // Author:
15 //      Umadevi S (sumadevi@novell.com)
16 //
17 // Copyright (c) 2004 Novell Inc., and the individuals listed
18 // on the ChangeLog entries.
19 // 
20 // Permission is hereby granted, free of charge, to any person obtaining
21 // a copy of this software and associated documentation files (the
22 // "Software"), to deal in the Software without restriction, including
23 // without limitation the rights to use, copy, modify, merge, publish,
24 // distribute, sublicense, and/or sell copies of the Software, and to
25 // permit persons to whom the Software is furnished to do so, subject to
26 // the following conditions:
27 // 
28 // The above copyright notice and this permission notice shall be
29 // included in all copies or substantial portions of the Software.
30 // 
31 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 //
39
40 using System;
41 using System.Data;
42 using System.Data.Common;
43 using System.Data.SqlClient;
44 using System.Collections.Specialized;
45
46 namespace MonoTests.System.Data 
47 {
48         public class MSSqlTestClient  
49         {
50                 #region protected members
51                 protected string connectionString = null;
52                 protected SqlConnection conn = null;
53                 protected bool isConnAlive = false;
54                 #endregion
55
56                 public MSSqlTestClient ()
57                 {
58                                 connectionString =
59                                         "Server=164.99.168.131;" +
60                                         "Database=Northwind;" +
61                                         "User ID=sa;" +
62                                         "Password=novell";
63                                 conn = new SqlConnection(connectionString);
64                 }
65
66                 protected void OpenConnection () 
67                 {
68                         conn.ConnectionString = connectionString;
69                         conn.Open ();
70                         // run tests only if the connection is open,
71                         // otherwise make it fail, to setup with correct
72                         // database settings
73                         if (conn != null && conn.State != ConnectionState.Closed) 
74                                 isConnAlive = true;
75                 }
76
77                 protected void CloseConnection () 
78                 {
79                         if (conn != null && conn.State != ConnectionState.Closed) {
80                                 conn.Close ();
81                                 isConnAlive = false;
82                         }
83                 }
84
85                 internal void ExecuteQuery (string query)
86                 {
87                         SqlCommand cmd = new SqlCommand ();
88                         cmd.Connection = conn;
89                         cmd.CommandText = query;
90                         try {
91                                 int recordsAff = cmd.ExecuteNonQuery ();
92                         } catch (Exception e) {
93                                 Console.WriteLine("exception");
94                                 Console.WriteLine(e.StackTrace);
95                         }
96                 }
97         
98
99         }
100 }