Merge pull request #5714 from alexischr/update_bockbuild
[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                 [Test]
55                 public void AcceptChangesDuringUpdate ()
56                 {
57                         DataAdapter da = new MyAdapter ();
58                         da.AcceptChangesDuringUpdate = true;
59                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#1");
60                         da.AcceptChangesDuringUpdate = false;
61                         Assert.IsFalse (da.AcceptChangesDuringUpdate, "#2");
62                         da.AcceptChangesDuringUpdate = true;
63                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#3");
64                 }
65
66                 [Test]
67                 public void ContinueUpdateOnError ()
68                 {
69                         DataAdapter da = new MyAdapter ();
70                         da.ContinueUpdateOnError = true;
71                         Assert.IsTrue (da.ContinueUpdateOnError, "#1");
72                         da.ContinueUpdateOnError = false;
73                         Assert.IsFalse (da.ContinueUpdateOnError, "#2");
74                         da.ContinueUpdateOnError = true;
75                         Assert.IsTrue (da.ContinueUpdateOnError, "#3");
76                 }
77
78                 [Test]
79                 public void Fill_Direct ()
80                 {
81                         DataAdapter da = new MyAdapter ();
82                         DataSet ds = new DataSet ();
83                         try {
84                                 da.Fill (ds);
85                                 Assert.Fail ("#1");
86                         } catch (NotSupportedException ex) {
87                                 // Specified method is not supported
88                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
89                                 Assert.IsNull (ex.InnerException, "#3");
90                                 Assert.IsNotNull (ex.Message, "#4");
91                         }
92                 }
93
94                 [Test]
95                 public void FillLoadOption ()
96                 {
97                         DataAdapter da = new MyAdapter ();
98                         da.FillLoadOption = LoadOption.PreserveChanges;
99                         Assert.AreEqual (LoadOption.PreserveChanges, da.FillLoadOption, "#1");
100                         da.FillLoadOption = LoadOption.OverwriteChanges;
101                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#2");
102                         da.FillLoadOption = LoadOption.Upsert;
103                         Assert.AreEqual (LoadOption.Upsert, da.FillLoadOption, "#3");
104                 }
105
106                 [Test]
107                 public void FillLoadOption_Invalid ()
108                 {
109                         DataAdapter da = new MyAdapter ();
110                         try {
111                                 da.FillLoadOption = (LoadOption) 666;
112                                 Assert.Fail ("#1");
113                         } catch (ArgumentOutOfRangeException ex) {
114                                 // The LoadOption enumeration value, 666, is invalid
115                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
116                                 Assert.IsNull (ex.InnerException, "#3");
117                                 Assert.IsNotNull (ex.Message, "#4");
118                                 Assert.IsTrue (ex.Message.IndexOf ("LoadOption") != -1, "#5");
119                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
120                                 Assert.IsNotNull (ex.ParamName, "#7");
121                                 Assert.AreEqual ("LoadOption", ex.ParamName, "#8");
122                         }
123                 }
124
125                 [Test]
126                 public void MissingMappingAction_Valid ()
127                 {
128                         DataAdapter da = new MyAdapter ();
129                         da.MissingMappingAction = MissingMappingAction.Passthrough;
130                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#1");
131                         da.MissingMappingAction = MissingMappingAction.Ignore;
132                         Assert.AreEqual (MissingMappingAction.Ignore, da.MissingMappingAction, "#2");
133                         da.MissingMappingAction = MissingMappingAction.Error;
134                         Assert.AreEqual (MissingMappingAction.Error, da.MissingMappingAction, "#3");
135                 }
136
137                 [Test]
138                 public void MissingMappingAction_Invalid ()
139                 {
140                         DataAdapter da = new MyAdapter ();
141                         try {
142                                 da.MissingMappingAction = (MissingMappingAction) 666;
143                                 Assert.Fail ("#1");
144                         } catch (ArgumentOutOfRangeException ex) {
145                                 // The MissingMappingAction enumeration value, 666, is invalid
146                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
147                                 Assert.IsNull (ex.InnerException, "#3");
148                                 Assert.IsNotNull (ex.Message, "#4");
149                                 Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
150                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
151                                 Assert.IsNotNull (ex.ParamName, "#7");
152                                 Assert.AreEqual ("MissingMappingAction", ex.ParamName, "#8");
153                         }
154                 }
155
156                 [Test]
157                 public void MissingSchemaAction_Valid ()
158                 {
159                         DataAdapter da = new MyAdapter ();
160                         da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
161                         Assert.AreEqual (MissingSchemaAction.AddWithKey, da.MissingSchemaAction, "#1");
162                         da.MissingSchemaAction = MissingSchemaAction.Ignore;
163                         Assert.AreEqual (MissingSchemaAction.Ignore, da.MissingSchemaAction, "#2");
164                         da.MissingSchemaAction = MissingSchemaAction.Error;
165                         Assert.AreEqual (MissingSchemaAction.Error, da.MissingSchemaAction, "#3");
166                 }
167
168                 [Test]
169                 public void MissingSchemaAction_Invalid ()
170                 {
171                         DataAdapter da = new MyAdapter ();
172                         try {
173                                 da.MissingSchemaAction = (MissingSchemaAction) 666;
174                                 Assert.Fail ("#1");
175                         } catch (ArgumentOutOfRangeException ex) {
176                                 // The MissingSchemaAction enumeration value, 666, is invalid
177                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
178                                 Assert.IsNull (ex.InnerException, "#3");
179                                 Assert.IsNotNull (ex.Message, "#4");
180                                 Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
181                                 Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
182                                 Assert.IsNotNull (ex.ParamName, "#7");
183                                 Assert.AreEqual ("MissingSchemaAction", ex.ParamName, "#8");
184                         }
185                 }
186
187                 [Test]
188                 public void ReturnProviderSpecificTypes ()
189                 {
190                         DataAdapter da = new MyAdapter ();
191                         da.ReturnProviderSpecificTypes = true;
192                         Assert.IsTrue (da.ReturnProviderSpecificTypes, "#1");
193                         da.ReturnProviderSpecificTypes = false;
194                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#2");
195                         da.ReturnProviderSpecificTypes = true;
196                         Assert.IsTrue (da.ReturnProviderSpecificTypes, "#3");
197                 }
198         }
199
200         class MyAdapter : DataAdapter
201         {
202         }
203 }