OdbcConnectionStringBuilderTest.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // OdbcConnectionStringBuilderTest.cs - NUnit Test Cases for testing the
  2. // OdbcConnectionStringBuilder Class.
  3. //
  4. // Authors:
  5. // Nidhi Rawal ([email protected])
  6. //
  7. // Copyright (c) 2007 Novell Inc., and the individuals listed on the
  8. // ChangeLog entries.
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person
  12. // obtaining a copy of this software and associated documentation
  13. // files (the "Software"), to deal in the Software without
  14. // restriction, including without limitation the rights to use, copy,
  15. // modify, merge, publish, distribute, sublicense, and/or sell copies
  16. // of the Software, and to permit persons to whom the Software is
  17. // furnished to do so, subject to the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  26. // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  28. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. // SOFTWARE.
  30. using System;
  31. using System.Data;
  32. using System.Data.Common;
  33. using System.Data.Odbc;
  34. using Mono.Data;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Data
  37. {
  38. [TestFixture]
  39. [Category ("odbc")]
  40. public class OdbcConnectionStringBuilderTest
  41. {
  42. [Test]
  43. public void ClearTest ()
  44. {
  45. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  46. string temp = "";
  47. builder ["Dbq"] = "C:\\Data.xls";
  48. builder ["DriverID"] = "790";
  49. builder ["DefaultDir"] = "C:\\";
  50. foreach (string key in builder.Keys)
  51. temp += key + " = " + builder [key].ToString () + " ";
  52. Assert.AreEqual ("Dbq = C:\\Data.xls DriverID = 790 DefaultDir = C:\\ ", temp, "#1 All the keys and their values before clearing");
  53. builder.Clear ();
  54. temp = "";
  55. foreach (string key in builder.Keys)
  56. temp += key + " = " + builder [key].ToString () + "\n";
  57. Assert.AreEqual ("", temp, "#2 All the keys and their values after clearing");
  58. }
  59. [Test]
  60. public void ContainsKeyTest ()
  61. {
  62. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  63. builder ["SourceType"] = "DBC";
  64. Assert.AreEqual (true, builder.ContainsKey ("SourceType"), "#1 Returns true for the key explicitly added");
  65. Assert.AreEqual (false, builder.ContainsKey ("DSN"), "#2 Returns false for the key not explicitly added");
  66. Assert.AreEqual (false, builder.ContainsKey ("xyz"), "#3 Returns false for any invalid string");
  67. }
  68. [Test]
  69. [ExpectedException (typeof (ArgumentNullException))]
  70. public void ContainsKeyNullArgumentTest ()
  71. {
  72. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  73. builder ["SourceType"] = "DBC";
  74. builder.ContainsKey (null);
  75. }
  76. [Test]
  77. public void RemoveTest ()
  78. {
  79. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  80. builder ["DriverID"] = "790";
  81. builder ["DefaultDir"] = "C:\\";
  82. Assert.AreEqual (true, builder.Remove ("DriverID"), "#1 Removes and returns true for the key explicitly added");
  83. Assert.AreEqual (false, builder.Remove ("userid"), "#2 Unable to find key, returns false");
  84. Assert.AreEqual (false, builder.Remove ("DriverID"), "#3 Cannot find the key previously removed");
  85. }
  86. [Test]
  87. [ExpectedException (typeof (ArgumentNullException))]
  88. public void RemoveNullArgumentTest ()
  89. {
  90. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  91. builder.Remove (null);
  92. }
  93. [Test]
  94. public void TryGetValueTest ()
  95. {
  96. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  97. object value = null;
  98. builder ["DriverID"] = "790";
  99. builder ["Server"] = "C:\\";
  100. Assert.AreEqual (true, builder.TryGetValue ("DriverID", out value), "#1 Gets the value and returns true");
  101. Assert.AreEqual (false, builder.TryGetValue ("SERVER", out value), "#2 Unable to find the key");
  102. }
  103. [Test]
  104. [ExpectedException (typeof (ArgumentNullException))]
  105. public void TryGetValueNullArgumentTest ()
  106. {
  107. OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder ();
  108. object value = null;
  109. builder.TryGetValue (null, out value);
  110. }
  111. }
  112. }