2 // DataAdapterTest.cs - NUnit Test Cases for testing the DataAdapter class
5 // Miguel de Icaza (miguel@novell.com)
6 // Gert Driesen (drieseng@users.sourceforge.net)
8 // Copyright (c) 2006 Novell Inc., and the individuals listed
9 // on the ChangeLog entries.
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.Data.Common;
35 using NUnit.Framework;
37 namespace MonoTests.System.Data.Common
40 public class DataAdapterTest
43 public void AcceptChangesDuringFill ()
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");
56 public void AcceptChangesDuringUpdate ()
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");
69 public void ContinueUpdateOnError ()
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");
82 public void Fill_Direct ()
84 DataAdapter da = new MyAdapter ();
85 DataSet ds = new DataSet ();
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");
98 public void FillLoadOption ()
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");
110 public void FillLoadOption_Invalid ()
112 DataAdapter da = new MyAdapter ();
114 da.FillLoadOption = (LoadOption) 666;
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");
130 public void MissingMappingAction_Valid ()
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");
142 public void MissingMappingAction_Invalid ()
144 DataAdapter da = new MyAdapter ();
146 da.MissingMappingAction = (MissingMappingAction) 666;
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");
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");
173 public void MissingSchemaAction_Valid ()
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");
185 public void MissingSchemaAction_Invalid ()
187 DataAdapter da = new MyAdapter ();
189 da.MissingSchemaAction = (MissingSchemaAction) 666;
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");
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");
217 public void ReturnProviderSpecificTypes ()
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");
230 class MyAdapter : DataAdapter
233 public override int Fill (DataSet dataSet)
235 throw new NotImplementedException ();
238 public override DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
240 throw new NotImplementedException ();
243 public override IDataParameter[] GetFillParameters ()
245 throw new NotImplementedException ();
248 public override int Update (DataSet dataSet)
250 throw new NotImplementedException ();