Merge pull request #323 from crazyjncsu/master
[mono.git] / mcs / class / System.Data / Test / System.Data.Common / DataAdapterTest.cs
1 //
2 // DataAdapterTest.cs - NUnit Test Cases for testing the DataAdapter class
3 //
4 // Author:
5 //      Miguel de Icaza (miguel@novell.com)
6 //      Gert Driesen (drieseng@users.sourceforge.net)
7 //
8 // Copyright (c) 2006 Novell Inc., and the individuals listed
9 // on the ChangeLog entries.
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // 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 BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Data;
33 using System.Data.Common;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Data.Common
38 {
39         [TestFixture]
40         public class DataAdapterTest
41         {
42                 [Test]
43                 public void AcceptChangesDuringFill ()
44                 {
45                         DataAdapter da = new MyAdapter ();
46                         da.AcceptChangesDuringFill = true;
47                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
48                         da.AcceptChangesDuringFill = false;
49                         Assert.IsFalse (da.AcceptChangesDuringFill, "#2");
50                         da.AcceptChangesDuringFill = true;
51                         Assert.IsTrue (da.AcceptChangesDuringFill, "#3");
52                 }
53
54 #if NET_2_0
55                 [Test]
56                 public void AcceptChangesDuringUpdate ()
57                 {
58                         DataAdapter da = new MyAdapter ();
59                         da.AcceptChangesDuringUpdate = true;
60                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#1");
61                         da.AcceptChangesDuringUpdate = false;
62                         Assert.IsFalse (da.AcceptChangesDuringUpdate, "#2");
63                         da.AcceptChangesDuringUpdate = true;
64                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#3");
65                 }
66 #endif
67
68                 [Test]
69                 public void ContinueUpdateOnError ()
70                 {
71                         DataAdapter da = new MyAdapter ();
72                         da.ContinueUpdateOnError = true;
73                         Assert.IsTrue (da.ContinueUpdateOnError, "#1");
74                         da.ContinueUpdateOnError = false;
75                         Assert.IsFalse (da.ContinueUpdateOnError, "#2");
76                         da.ContinueUpdateOnError = true;
77                         Assert.IsTrue (da.ContinueUpdateOnError, "#3");
78                 }
79
80 #if NET_2_0
81                 [Test]
82                 public void Fill_Direct ()
83                 {
84                         DataAdapter da = new MyAdapter ();
85                         DataSet ds = new DataSet ();
86                         try {
87                                 da.Fill (ds);
88                                 Assert.Fail ("#1");
89                         } catch (NotSupportedException ex) {
90                                 // Specified method is not supported
91                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
92                                 Assert.IsNull (ex.InnerException, "#3");
93                                 Assert.IsNotNull (ex.Message, "#4");
94                         }
95                 }
96
97                 [Test]
98                 public void FillLoadOption ()
99                 {
100                         DataAdapter da = new MyAdapter ();
101                         da.FillLoadOption = LoadOption.PreserveChanges;
102                         Assert.AreEqual (LoadOption.PreserveChanges, da.FillLoadOption, "#1");
103                         da.FillLoadOption = LoadOption.OverwriteChanges;
104                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#2");
105                         da.FillLoadOption = LoadOption.Upsert;
106                         Assert.AreEqual (LoadOption.Upsert, da.FillLoadOption, "#3");
107                 }
108
109                 [Test]
110                 public void FillLoadOption_Invalid ()
111                 {
112                         DataAdapter da = new MyAdapter ();
113                         try {
114                                 da.FillLoadOption = (LoadOption) 666;
115                                 Assert.Fail ("#1");
116                         } catch (ArgumentOutOfRangeException ex) {
117                                 // The LoadOption enumeration value, 666, is invalid
118                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
119                                 Assert.IsNull (ex.InnerException, "#3");
120                                 Assert.IsNotNull (ex.Message, "#4");
121                                 Assert.IsTrue (ex.Message.IndexOf ("LoadOption") != -1, "#5");
122                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
123                                 Assert.IsNotNull (ex.ParamName, "#7");
124                                 Assert.AreEqual ("LoadOption", ex.ParamName, "#8");
125                         }
126                 }
127 #endif
128
129                 [Test]
130                 public void MissingMappingAction_Valid ()
131                 {
132                         DataAdapter da = new MyAdapter ();
133                         da.MissingMappingAction = MissingMappingAction.Passthrough;
134                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#1");
135                         da.MissingMappingAction = MissingMappingAction.Ignore;
136                         Assert.AreEqual (MissingMappingAction.Ignore, da.MissingMappingAction, "#2");
137                         da.MissingMappingAction = MissingMappingAction.Error;
138                         Assert.AreEqual (MissingMappingAction.Error, da.MissingMappingAction, "#3");
139                 }
140
141                 [Test]
142                 public void MissingMappingAction_Invalid ()
143                 {
144                         DataAdapter da = new MyAdapter ();
145                         try {
146                                 da.MissingMappingAction = (MissingMappingAction) 666;
147                                 Assert.Fail ("#1");
148 #if NET_2_0
149                         } catch (ArgumentOutOfRangeException ex) {
150                                 // The MissingMappingAction enumeration value, 666, is invalid
151                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
152                                 Assert.IsNull (ex.InnerException, "#3");
153                                 Assert.IsNotNull (ex.Message, "#4");
154                                 Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
155                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
156                                 Assert.IsNotNull (ex.ParamName, "#7");
157                                 Assert.AreEqual ("MissingMappingAction", ex.ParamName, "#8");
158                         }
159 #else
160                         } catch (ArgumentException ex) {
161                                 // The MissingMappingAction enumeration value, 666, is invalid
162                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
163                                 Assert.IsNull (ex.InnerException, "#3");
164                                 Assert.IsNotNull (ex.Message, "#4");
165                                 Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
166                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
167                                 Assert.IsNull (ex.ParamName, "#7");
168                         }
169 #endif
170                 }
171
172                 [Test]
173                 public void MissingSchemaAction_Valid ()
174                 {
175                         DataAdapter da = new MyAdapter ();
176                         da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
177                         Assert.AreEqual (MissingSchemaAction.AddWithKey, da.MissingSchemaAction, "#1");
178                         da.MissingSchemaAction = MissingSchemaAction.Ignore;
179                         Assert.AreEqual (MissingSchemaAction.Ignore, da.MissingSchemaAction, "#2");
180                         da.MissingSchemaAction = MissingSchemaAction.Error;
181                         Assert.AreEqual (MissingSchemaAction.Error, da.MissingSchemaAction, "#3");
182                 }
183
184                 [Test]
185                 public void MissingSchemaAction_Invalid ()
186                 {
187                         DataAdapter da = new MyAdapter ();
188                         try {
189                                 da.MissingSchemaAction = (MissingSchemaAction) 666;
190                                 Assert.Fail ("#1");
191 #if NET_2_0
192                         } catch (ArgumentOutOfRangeException ex) {
193                                 // The MissingSchemaAction enumeration value, 666, is invalid
194                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
195                                 Assert.IsNull (ex.InnerException, "#3");
196                                 Assert.IsNotNull (ex.Message, "#4");
197                                 Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
198                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
199                                 Assert.IsNotNull (ex.ParamName, "#7");
200                                 Assert.AreEqual ("MissingSchemaAction", ex.ParamName, "#8");
201                         }
202 #else
203                         } catch (ArgumentException ex) {
204                                 // The MissingSchemaAction enumeration value, 666, is invalid
205                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
206                                 Assert.IsNull (ex.InnerException, "#3");
207                                 Assert.IsNotNull (ex.Message, "#4");
208                                 Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
209                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
210                                 Assert.IsNull (ex.ParamName, "#7");
211                         }
212 #endif
213                 }
214
215 #if NET_2_0
216                 [Test]
217                 public void ReturnProviderSpecificTypes ()
218                 {
219                         DataAdapter da = new MyAdapter ();
220                         da.ReturnProviderSpecificTypes = true;
221                         Assert.IsTrue (da.ReturnProviderSpecificTypes, "#1");
222                         da.ReturnProviderSpecificTypes = false;
223                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#2");
224                         da.ReturnProviderSpecificTypes = true;
225                         Assert.IsTrue (da.ReturnProviderSpecificTypes, "#3");
226                 }
227 #endif
228         }
229
230         class MyAdapter : DataAdapter
231         {
232 #if ONLY_1_1
233                 public override int Fill (DataSet dataSet)
234                 {
235                         throw new NotImplementedException ();
236                 }
237
238                 public override DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
239                 {
240                         throw new NotImplementedException ();
241                 }
242
243                 public override IDataParameter[] GetFillParameters ()
244                 {
245                         throw new NotImplementedException ();
246                 }
247
248                 public override int Update (DataSet dataSet)
249                 {
250                         throw new NotImplementedException ();
251                 }
252 #endif
253         }
254 }