5e2182042cab239988dc98b11f138ca12f733846
[mono.git] / mcs / class / System.Data / Test / System.Data.Common / DbCommandBuilderTest.cs
1 // DbCommandBuilderTest.cs - NUnit Test Cases for DbCommandBuilder class
2 //
3 // Author: 
4 //      Gert Driesen (drieseng@users.sourceforge.net)
5 //
6 // Copyright (C) 2008 Gert Driesen
7 //
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:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
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.
26 //
27
28 #if NET_2_0
29 using System;
30 using System.Data;
31 using System.Data.Common;
32 using System.Globalization;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Data.Common
37 {
38         [TestFixture]
39         public class DbCommandBuilderTest
40         {
41                 [Test]
42                 public void QuotePrefix ()
43                 {
44                         MyCommandBuilder cb = new MyCommandBuilder ();
45                         Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
46                         cb.QuotePrefix = "mono";
47                         Assert.AreEqual ("mono", cb.QuotePrefix, "#2");
48                         cb.QuotePrefix = null;
49                         Assert.AreEqual (string.Empty, cb.QuotePrefix, "#3");
50                         cb.QuotePrefix = "'\"";
51                         Assert.AreEqual ("'\"", cb.QuotePrefix, "#4");
52                         cb.QuotePrefix = string.Empty;
53                         Assert.AreEqual (string.Empty, cb.QuotePrefix, "#5");
54                         cb.QuotePrefix = " ";
55                         Assert.AreEqual (" ", cb.QuotePrefix, "#6");
56                 }
57
58                 [Test]
59                 public void QuoteSuffix ()
60                 {
61                         MyCommandBuilder cb = new MyCommandBuilder ();
62                         Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
63                         cb.QuoteSuffix = "mono";
64                         Assert.AreEqual ("mono", cb.QuoteSuffix, "#2");
65                         cb.QuoteSuffix = null;
66                         Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#3");
67                         cb.QuoteSuffix = "'\"";
68                         Assert.AreEqual ("'\"", cb.QuoteSuffix, "#4");
69                         cb.QuoteSuffix = string.Empty;
70                         Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#5");
71                 }
72
73                 private class MyCommandBuilder : DbCommandBuilder
74                 {
75                         protected override string GetParameterPlaceholder (int parameterOrdinal)
76                         {
77                                 return string.Format (CultureInfo.InvariantCulture,
78                                         "@PH:{0}@", parameterOrdinal);
79                         }
80
81                         protected override string GetParameterName (string parameterName)
82                         {
83                                 return string.Format (CultureInfo.InvariantCulture,
84                                         "@NAME:{0}@", parameterName);
85                         }
86
87                         protected override string GetParameterName (int parameterOrdinal)
88                         {
89                                 return string.Format (CultureInfo.InvariantCulture,
90                                         "@NAME:{0}@", parameterOrdinal);
91                         }
92
93                         protected override void ApplyParameterInfo (DbParameter parameter, DataRow row, StatementType statementType, bool whereClause)
94                         {
95                         }
96
97                         protected override void SetRowUpdatingHandler (DbDataAdapter adapter)
98                         {
99                         }
100                 }
101         }
102 }
103 #endif // NET_2_0