OciDefineHandleTest.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // OracleParameterTest.cs -
  3. // NUnit Test Cases for OciDefineHandle
  4. //
  5. // Author:
  6. // Leszek Ciesielski <[email protected]>
  7. //
  8. // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System.Configuration;
  31. using System.Globalization;
  32. using System.Threading;
  33. using System.Data.OracleClient;
  34. using System.Data;
  35. using System;
  36. namespace MonoTests.System.Data.OracleClient {
  37. [TestFixture]
  38. public class OciDefineHandleTest {
  39. String connection_string;
  40. OracleConnection connection;
  41. OracleCommand command;
  42. // test string
  43. string test_value = " sim\u4FF5ply\u65E5 tri\u672Cm te\u4F00st ";
  44. string test_value2 = " simply \u672Ctrim\u4F00 test in\u65E5 query \u4FF5 ";
  45. [TestFixtureSetUp]
  46. public void FixtureSetUp ()
  47. {
  48. connection_string = ConfigurationSettings.AppSettings.Get ("ConnectionString");
  49. if(connection_string == null)
  50. Assert.Ignore ("Please consult README.tests.");
  51. }
  52. [SetUp]
  53. public void SetUp ()
  54. {
  55. connection = new OracleConnection (connection_string);
  56. connection.Open ();
  57. using (command = connection.CreateCommand ()) {
  58. // create the tables
  59. command.CommandText =
  60. "create table utf8test (id number(10), text nvarchar2(64), text2 nvarchar2(64) )";
  61. command.ExecuteNonQuery ();
  62. }
  63. }
  64. [TearDown]
  65. public void TearDown ()
  66. {
  67. using (command = connection.CreateCommand ()) {
  68. command.CommandText = "drop table utf8test";
  69. command.ExecuteNonQuery ();
  70. }
  71. connection.Close ();
  72. connection.Dispose ();
  73. }
  74. [Test] // regression for bug #79004
  75. public void TrimsUnicodeStringsTest ()
  76. {
  77. using (command = connection.CreateCommand ()) { // reusing command from SetUp causes parameter names mismatch
  78. // insert test values
  79. command.CommandText =
  80. "insert into utf8test (id,text,text2) values (:id,:txt,'" + test_value2 + "')";
  81. command.Parameters.Add (new OracleParameter ("ID", OracleType.Int32));
  82. command.Parameters.Add( new OracleParameter ("TXT", OracleType.NVarChar));
  83. command.Parameters ["ID"].Value = 101;
  84. command.Parameters ["TXT"].Value = test_value;
  85. command.ExecuteNonQuery ();
  86. // read test values
  87. command.CommandText =
  88. "select text,text2 from utf8test where id = 101";
  89. command.Parameters.Clear ();
  90. using (OracleDataReader reader = command.ExecuteReader ()) {
  91. if (reader.Read ()) {
  92. Assert.AreEqual (test_value, reader.GetString (0), "Passed through bind value mismatched");
  93. Assert.AreEqual (test_value2, reader.GetString (1), "Directly passed value mismatched");
  94. }
  95. else {
  96. Assert.Fail ("Expected records not found.");
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }