OracleConnection_Open.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.OracleClient;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OracleClient
  29. {
  30. [TestFixture]
  31. public class OracleConnection_Open : GHTBase
  32. {
  33. OracleConnection 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. OracleConnection_Open tc = new OracleConnection_Open();
  58. Exception exp = null;
  59. try
  60. {
  61. tc.BeginTest("OracleOpenConnection");
  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 OracleConnection(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. BeginCase("Open Connection - garbage value");
  97. try
  98. {
  99. con = new OracleConnection("xxx");
  100. con.Open();
  101. }
  102. catch (ArgumentException ex)
  103. {
  104. ExpectedExceptionCaught(ex);
  105. }
  106. catch
  107. {
  108. ExpectedExceptionNotCaught("System.ArgumentException");
  109. }
  110. finally
  111. {
  112. if (con != null) con.Close();
  113. EndCase(exp);
  114. exp = null;
  115. }
  116. }
  117. }
  118. }