1 // DbCommandBuilderTest.cs - NUnit Test Cases for DbCommandBuilder class
4 // Gert Driesen (drieseng@users.sourceforge.net)
6 // Copyright (C) 2008 Gert Driesen
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Data.Common;
32 using System.Globalization;
34 using NUnit.Framework;
36 namespace MonoTests.System.Data.Common
39 public class DbCommandBuilderTest
42 public void CatalogLocationTest ()
44 MyCommandBuilder cb = new MyCommandBuilder ();
45 Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1");
46 cb.CatalogLocation = CatalogLocation.End;
47 Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#2");
51 public void CatalogLocation_Value_Invalid ()
53 MyCommandBuilder cb = new MyCommandBuilder ();
54 cb.CatalogLocation = CatalogLocation.End;
56 cb.CatalogLocation = (CatalogLocation) 666;
58 } catch (ArgumentOutOfRangeException ex) {
59 // The CatalogLocation enumeration value, 666, is invalid
60 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
61 Assert.IsNull (ex.InnerException, "#3");
62 Assert.IsNotNull (ex.Message, "#4");
63 Assert.IsTrue (ex.Message.IndexOf ("CatalogLocation") != -1, "#5:" + ex.Message);
64 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
65 Assert.AreEqual ("CatalogLocation", ex.ParamName, "#7");
67 Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#8");
71 public void CatalogSeparator ()
73 MyCommandBuilder cb = new MyCommandBuilder ();
74 Assert.AreEqual (".", cb.CatalogSeparator, "#1");
75 cb.CatalogSeparator = "a";
76 Assert.AreEqual ("a", cb.CatalogSeparator, "#2");
77 cb.CatalogSeparator = null;
78 Assert.AreEqual (".", cb.CatalogSeparator, "#3");
79 cb.CatalogSeparator = "b";
80 Assert.AreEqual ("b", cb.CatalogSeparator, "#4");
81 cb.CatalogSeparator = string.Empty;
82 Assert.AreEqual (".", cb.CatalogSeparator, "#5");
83 cb.CatalogSeparator = " ";
84 Assert.AreEqual (" ", cb.CatalogSeparator, "#6");
88 public void ConflictOptionTest ()
90 MyCommandBuilder cb = new MyCommandBuilder ();
91 Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictOption, "#1");
92 cb.ConflictOption = ConflictOption.CompareRowVersion;
93 Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#2");
97 public void ConflictOption_Value_Invalid ()
99 MyCommandBuilder cb = new MyCommandBuilder ();
100 cb.ConflictOption = ConflictOption.CompareRowVersion;
102 cb.ConflictOption = (ConflictOption) 666;
104 } catch (ArgumentOutOfRangeException ex) {
105 // The ConflictOption enumeration value, 666, is invalid
106 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
107 Assert.IsNull (ex.InnerException, "#3");
108 Assert.IsNotNull (ex.Message, "#4");
109 Assert.IsTrue (ex.Message.IndexOf ("ConflictOption") != -1, "#5:" + ex.Message);
110 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
111 Assert.AreEqual ("ConflictOption", ex.ParamName, "#7");
113 Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#8");
116 [Test] // QuoteIdentifier (String)
117 public void QuoteIdentifier ()
119 MyCommandBuilder cb = new MyCommandBuilder ();
121 cb.QuoteIdentifier ((string) null);
123 } catch (NotSupportedException ex) {
124 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
125 Assert.IsNull (ex.InnerException, "#A3");
126 Assert.AreEqual ((new NotSupportedException ()).Message, ex.Message, "#A4");
130 cb.QuoteIdentifier ("mono");
132 } catch (NotSupportedException ex) {
133 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
134 Assert.IsNull (ex.InnerException, "#B3");
135 Assert.AreEqual ((new NotSupportedException ()).Message, ex.Message, "#B4");
140 public void QuotePrefix ()
142 MyCommandBuilder cb = new MyCommandBuilder ();
143 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
144 cb.QuotePrefix = "mono";
145 Assert.AreEqual ("mono", cb.QuotePrefix, "#2");
146 cb.QuotePrefix = null;
147 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#3");
148 cb.QuotePrefix = "'\"";
149 Assert.AreEqual ("'\"", cb.QuotePrefix, "#4");
150 cb.QuotePrefix = string.Empty;
151 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#5");
152 cb.QuotePrefix = " ";
153 Assert.AreEqual (" ", cb.QuotePrefix, "#6");
157 public void QuoteSuffix ()
159 MyCommandBuilder cb = new MyCommandBuilder ();
160 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
161 cb.QuoteSuffix = "mono";
162 Assert.AreEqual ("mono", cb.QuoteSuffix, "#2");
163 cb.QuoteSuffix = null;
164 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#3");
165 cb.QuoteSuffix = "'\"";
166 Assert.AreEqual ("'\"", cb.QuoteSuffix, "#4");
167 cb.QuoteSuffix = string.Empty;
168 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#5");
169 cb.QuoteSuffix = " ";
170 Assert.AreEqual (" ", cb.QuoteSuffix, "#6");
174 public void SchemaSeparator ()
176 MyCommandBuilder cb = new MyCommandBuilder ();
177 Assert.AreEqual (".", cb.SchemaSeparator, "#1");
178 cb.SchemaSeparator = "a";
179 Assert.AreEqual ("a", cb.SchemaSeparator, "#2");
180 cb.SchemaSeparator = null;
181 Assert.AreEqual (".", cb.SchemaSeparator, "#3");
182 cb.SchemaSeparator = "b";
183 Assert.AreEqual ("b", cb.SchemaSeparator, "#4");
184 cb.SchemaSeparator = string.Empty;
185 Assert.AreEqual (".", cb.SchemaSeparator, "#5");
186 cb.SchemaSeparator = " ";
187 Assert.AreEqual (" ", cb.SchemaSeparator, "#6");
190 private class MyCommandBuilder : DbCommandBuilder
192 protected override string GetParameterPlaceholder (int parameterOrdinal)
194 return string.Format (CultureInfo.InvariantCulture,
195 "@PH:{0}@", parameterOrdinal);
198 protected override string GetParameterName (string parameterName)
200 return string.Format (CultureInfo.InvariantCulture,
201 "@NAME:{0}@", parameterName);
204 protected override string GetParameterName (int parameterOrdinal)
206 return string.Format (CultureInfo.InvariantCulture,
207 "@NAME:{0}@", parameterOrdinal);
210 protected override void ApplyParameterInfo (DbParameter parameter, DataRow row, StatementType statementType, bool whereClause)
214 protected override void SetRowUpdatingHandler (DbDataAdapter adapter)