OleDbConnection_Open.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Copyright (c) 2006 Mainsoft Co.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Data;
  25. using System.Data.OleDb;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OleDb
  29. {
  30. [TestFixture]
  31. public class OleDbConnection_Open : GHTBase
  32. {
  33. OleDbConnection con = null;
  34. string ConString = "";
  35. [SetUp]
  36. public void SetUp()
  37. {
  38. Exception exp = null;
  39. BeginCase("Setup");
  40. try
  41. {
  42. ConString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString;
  43. }
  44. catch(Exception ex) {exp = ex;}
  45. finally {EndCase(exp); exp = null;}
  46. }
  47. [TearDown]
  48. public void TearDown()
  49. {
  50. if (con != null)
  51. {
  52. con.Close();
  53. }
  54. }
  55. public static void Main()
  56. {
  57. OleDbConnection_Open tc = new OleDbConnection_Open();
  58. Exception exp = null;
  59. try
  60. {
  61. tc.BeginTest("OleDBOpenConnection");
  62. tc.SetUp();
  63. tc.run();
  64. tc.TearDown();
  65. }
  66. catch(Exception ex)
  67. {
  68. exp = ex;
  69. }
  70. finally
  71. {
  72. tc.EndTest(exp);
  73. }
  74. }
  75. [Test]
  76. public void run()
  77. {
  78. Exception exp = null;
  79. BeginCase("Open Connection ");
  80. try
  81. {
  82. con = new OleDbConnection(ConString);
  83. con.Open();
  84. Compare(con.State , ConnectionState.Open);
  85. }
  86. catch (Exception ex)
  87. {
  88. exp = ex;
  89. }
  90. finally
  91. {
  92. if (con != null) con.Close();
  93. EndCase(exp);
  94. exp = null;
  95. }
  96. ConString = ConString.Replace("User Id", "uid");
  97. BeginCase("Open Connection - uid");
  98. try
  99. {
  100. con = new OleDbConnection(ConString);
  101. con.Open();
  102. Compare(con.State , ConnectionState.Open);
  103. }
  104. catch (Exception ex)
  105. {
  106. exp = ex;
  107. }
  108. finally
  109. {
  110. if (con != null) con.Close();
  111. EndCase(exp);
  112. exp = null;
  113. }
  114. BeginCase("Open Connection - garbage value");
  115. try
  116. {
  117. con = new OleDbConnection("xxx");
  118. con.Open();
  119. }
  120. catch (ArgumentException ex)
  121. {
  122. ExpectedExceptionCaught(ex);
  123. }
  124. catch
  125. {
  126. ExpectedExceptionNotCaught("System.ArgumentException");
  127. }
  128. finally
  129. {
  130. if (con != null) con.Close();
  131. EndCase(exp);
  132. exp = null;
  133. }
  134. }
  135. }
  136. }