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.
30 using System.Data.Common;
31 using System.Globalization;
33 using NUnit.Framework;
35 namespace MonoTests.System.Data.Common
38 public class DbCommandBuilderTest
41 public void CatalogLocationTest ()
43 MyCommandBuilder cb = new MyCommandBuilder ();
44 Assert.AreEqual (CatalogLocation.Start, cb.CatalogLocation, "#1");
45 cb.CatalogLocation = CatalogLocation.End;
46 Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#2");
50 public void CatalogLocation_Value_Invalid ()
52 MyCommandBuilder cb = new MyCommandBuilder ();
53 cb.CatalogLocation = CatalogLocation.End;
55 cb.CatalogLocation = (CatalogLocation) 666;
57 } catch (ArgumentOutOfRangeException ex) {
58 // The CatalogLocation enumeration value, 666, is invalid
59 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
60 Assert.IsNull (ex.InnerException, "#3");
61 Assert.IsNotNull (ex.Message, "#4");
62 Assert.IsTrue (ex.Message.IndexOf ("CatalogLocation") != -1, "#5:" + ex.Message);
63 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
64 Assert.AreEqual ("CatalogLocation", ex.ParamName, "#7");
66 Assert.AreEqual (CatalogLocation.End, cb.CatalogLocation, "#8");
70 public void CatalogSeparator ()
72 MyCommandBuilder cb = new MyCommandBuilder ();
73 Assert.AreEqual (".", cb.CatalogSeparator, "#1");
74 cb.CatalogSeparator = "a";
75 Assert.AreEqual ("a", cb.CatalogSeparator, "#2");
76 cb.CatalogSeparator = null;
77 Assert.AreEqual (".", cb.CatalogSeparator, "#3");
78 cb.CatalogSeparator = "b";
79 Assert.AreEqual ("b", cb.CatalogSeparator, "#4");
80 cb.CatalogSeparator = string.Empty;
81 Assert.AreEqual (".", cb.CatalogSeparator, "#5");
82 cb.CatalogSeparator = " ";
83 Assert.AreEqual (" ", cb.CatalogSeparator, "#6");
87 public void ConflictOptionTest ()
89 MyCommandBuilder cb = new MyCommandBuilder ();
90 Assert.AreEqual (ConflictOption.CompareAllSearchableValues, cb.ConflictOption, "#1");
91 cb.ConflictOption = ConflictOption.CompareRowVersion;
92 Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#2");
96 public void ConflictOption_Value_Invalid ()
98 MyCommandBuilder cb = new MyCommandBuilder ();
99 cb.ConflictOption = ConflictOption.CompareRowVersion;
101 cb.ConflictOption = (ConflictOption) 666;
103 } catch (ArgumentOutOfRangeException ex) {
104 // The ConflictOption enumeration value, 666, is invalid
105 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
106 Assert.IsNull (ex.InnerException, "#3");
107 Assert.IsNotNull (ex.Message, "#4");
108 Assert.IsTrue (ex.Message.IndexOf ("ConflictOption") != -1, "#5:" + ex.Message);
109 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6:" + ex.Message);
110 Assert.AreEqual ("ConflictOption", ex.ParamName, "#7");
112 Assert.AreEqual (ConflictOption.CompareRowVersion, cb.ConflictOption, "#8");
115 [Test] // QuoteIdentifier (String)
116 public void QuoteIdentifier ()
118 MyCommandBuilder cb = new MyCommandBuilder ();
120 cb.QuoteIdentifier ((string) null);
122 } catch (NotSupportedException ex) {
123 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
124 Assert.IsNull (ex.InnerException, "#A3");
125 Assert.AreEqual ((new NotSupportedException ()).Message, ex.Message, "#A4");
129 cb.QuoteIdentifier ("mono");
131 } catch (NotSupportedException ex) {
132 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
133 Assert.IsNull (ex.InnerException, "#B3");
134 Assert.AreEqual ((new NotSupportedException ()).Message, ex.Message, "#B4");
139 public void QuotePrefix ()
141 MyCommandBuilder cb = new MyCommandBuilder ();
142 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
143 cb.QuotePrefix = "mono";
144 Assert.AreEqual ("mono", cb.QuotePrefix, "#2");
145 cb.QuotePrefix = null;
146 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#3");
147 cb.QuotePrefix = "'\"";
148 Assert.AreEqual ("'\"", cb.QuotePrefix, "#4");
149 cb.QuotePrefix = string.Empty;
150 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#5");
151 cb.QuotePrefix = " ";
152 Assert.AreEqual (" ", cb.QuotePrefix, "#6");
156 public void QuoteSuffix ()
158 MyCommandBuilder cb = new MyCommandBuilder ();
159 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
160 cb.QuoteSuffix = "mono";
161 Assert.AreEqual ("mono", cb.QuoteSuffix, "#2");
162 cb.QuoteSuffix = null;
163 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#3");
164 cb.QuoteSuffix = "'\"";
165 Assert.AreEqual ("'\"", cb.QuoteSuffix, "#4");
166 cb.QuoteSuffix = string.Empty;
167 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#5");
168 cb.QuoteSuffix = " ";
169 Assert.AreEqual (" ", cb.QuoteSuffix, "#6");
173 public void SchemaSeparator ()
175 MyCommandBuilder cb = new MyCommandBuilder ();
176 Assert.AreEqual (".", cb.SchemaSeparator, "#1");
177 cb.SchemaSeparator = "a";
178 Assert.AreEqual ("a", cb.SchemaSeparator, "#2");
179 cb.SchemaSeparator = null;
180 Assert.AreEqual (".", cb.SchemaSeparator, "#3");
181 cb.SchemaSeparator = "b";
182 Assert.AreEqual ("b", cb.SchemaSeparator, "#4");
183 cb.SchemaSeparator = string.Empty;
184 Assert.AreEqual (".", cb.SchemaSeparator, "#5");
185 cb.SchemaSeparator = " ";
186 Assert.AreEqual (" ", cb.SchemaSeparator, "#6");
189 private class MyCommandBuilder : DbCommandBuilder
191 protected override string GetParameterPlaceholder (int parameterOrdinal)
193 return string.Format (CultureInfo.InvariantCulture,
194 "@PH:{0}@", parameterOrdinal);
197 protected override string GetParameterName (string parameterName)
199 return string.Format (CultureInfo.InvariantCulture,
200 "@NAME:{0}@", parameterName);
203 protected override string GetParameterName (int parameterOrdinal)
205 return string.Format (CultureInfo.InvariantCulture,
206 "@NAME:{0}@", parameterOrdinal);
209 protected override void ApplyParameterInfo (DbParameter parameter, DataRow row, StatementType statementType, bool whereClause)
213 protected override void SetRowUpdatingHandler (DbDataAdapter adapter)