MSSqlTestBed.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 ([email protected])
  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. using System;
  40. using System.Data;
  41. using System.Data.Common;
  42. using System.Data.SqlClient;
  43. using System.Collections.Specialized;
  44. namespace MonoTests.System.Data
  45. {
  46. public class MSSqlTestClient
  47. {
  48. #region protected members
  49. protected string connectionString = null;
  50. protected SqlConnection conn = null;
  51. protected bool isConnAlive = false;
  52. #endregion
  53. public MSSqlTestClient ()
  54. {
  55. connectionString =
  56. "Server=164.99.168.131;" +
  57. "Database=Northwind;" +
  58. "User ID=sa;" +
  59. "Password=novell";
  60. conn = new SqlConnection(connectionString);
  61. }
  62. protected void OpenConnection ()
  63. {
  64. conn.ConnectionString = connectionString;
  65. conn.Open ();
  66. // run tests only if the connection is open,
  67. // otherwise make it fail, to setup with correct
  68. // database settings
  69. if (conn != null && conn.State != ConnectionState.Closed)
  70. isConnAlive = true;
  71. }
  72. protected void CloseConnection ()
  73. {
  74. if (conn != null && conn.State != ConnectionState.Closed) {
  75. conn.Close ();
  76. isConnAlive = false;
  77. }
  78. }
  79. internal void ExecuteQuery (string query)
  80. {
  81. SqlCommand cmd = new SqlCommand ();
  82. cmd.Connection = conn;
  83. cmd.CommandText = query;
  84. try {
  85. int recordsAff = cmd.ExecuteNonQuery ();
  86. } catch (Exception e) {
  87. Console.WriteLine("exception");
  88. Console.WriteLine(e.StackTrace);
  89. }
  90. }
  91. }
  92. }