SqlParameterTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // SqlParameterTest.cs - NUnit Test Cases for testing the
  3. // SqlParameter class
  4. // Author:
  5. // Senganal T ([email protected])
  6. //
  7. // Copyright (c) 2004 Novell Inc., and the individuals listed
  8. // on the ChangeLog entries.
  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 System;
  30. using System.Data;
  31. using System.Data.Common;
  32. using System.Data.SqlClient;
  33. using System.Data.SqlTypes;
  34. using NUnit.Framework;
  35. namespace MonoTests.System.Data.SqlClient
  36. {
  37. [TestFixture]
  38. [Category ("sqlserver")]
  39. //FIXME : Add more testcases
  40. public class SqlParameterTest
  41. {
  42. //testcase for #77410
  43. [Test]
  44. public void ParameterNullTest ()
  45. {
  46. SqlParameter param = new SqlParameter ("param", SqlDbType.Decimal);
  47. Assert.AreEqual (0, param.Scale, "#1");
  48. param.Value = DBNull.Value;
  49. Assert.AreEqual (0, param.Scale, "#2");
  50. param = new SqlParameter ("param", SqlDbType.Int);
  51. Assert.AreEqual (0, param.Scale, "#3");
  52. param.Value = DBNull.Value;
  53. Assert.AreEqual (0, param.Scale, "#4");
  54. }
  55. [Test]
  56. public void ParameterType ()
  57. {
  58. // If Type is not set, then type is inferred from the value
  59. // assigned. The Type should inferred everytime Value is assigned
  60. // If value is null/DBNull, then the current Type should retained.
  61. SqlParameter param = new SqlParameter ();
  62. Assert.AreEqual (SqlDbType.NVarChar, param.SqlDbType, "#1");
  63. param.Value = DBNull.Value;
  64. Assert.AreEqual (SqlDbType.NVarChar, param.SqlDbType, "#2");
  65. param.Value = 1;
  66. Assert.AreEqual (SqlDbType.Int, param.SqlDbType, "#3");
  67. param.Value = DBNull.Value;
  68. Assert.AreEqual (SqlDbType.Int, param.SqlDbType, "#4");
  69. param.Value = null;
  70. Assert.AreEqual (SqlDbType.Int, param.SqlDbType, "#4");
  71. //If Type is set, then the Type should not inferred from the value
  72. //assigned.
  73. SqlParameter param1 = new SqlParameter ();
  74. param1.DbType = DbType.String;
  75. Assert.AreEqual (SqlDbType.NVarChar, param1.SqlDbType, "#5");
  76. param1.Value = 1;
  77. Assert.AreEqual (SqlDbType.NVarChar, param1.SqlDbType, "#6");
  78. SqlParameter param2 = new SqlParameter ();
  79. param2.SqlDbType = SqlDbType.NVarChar;
  80. Assert.AreEqual (SqlDbType.NVarChar, param2.SqlDbType, "#7");
  81. param2.Value = 1;
  82. Assert.AreEqual (SqlDbType.NVarChar, param2.SqlDbType, "#8");
  83. }
  84. #if NET_2_0
  85. [Test]
  86. public void CompareInfoTest ()
  87. {
  88. SqlParameter parameter = new SqlParameter ();
  89. Assert.AreEqual (SqlCompareOptions.None, parameter.CompareInfo, "#1 Default value should be System.Data.SqlTypes.SqlCompareOptions.None");
  90. parameter.CompareInfo = SqlCompareOptions.IgnoreNonSpace;
  91. Assert.AreEqual (SqlCompareOptions.IgnoreNonSpace, parameter.CompareInfo, "#2 It should return CompareOptions.IgnoreSpace after setting this value for the property");
  92. }
  93. [Test]
  94. public void LocaleIdTest ()
  95. {
  96. SqlParameter parameter = new SqlParameter ();
  97. Assert.AreEqual (0, parameter.LocaleId, "#1 Default value for the property should be 0");
  98. parameter.LocaleId = 15;
  99. Assert.AreEqual(15, parameter.LocaleId, "#2");
  100. }
  101. [Test]
  102. public void SqlValue ()
  103. {
  104. SqlParameter parameter = new SqlParameter ();
  105. Assert.AreEqual (null, parameter.SqlValue, "#1 Default value for the property should be Null");
  106. parameter.SqlValue = SqlDbType.Char.ToString ();
  107. Assert.AreEqual ("Char", parameter.SqlValue, "#1 The value for the property should be Char after setting SqlDbType to Char");
  108. }
  109. #endif
  110. }
  111. }