* System.Data_test.dll.sources: Added DbDataAdapterTest.cs,
[mono.git] / mcs / class / System.Data / Test / System.Data.Common / DbDataAdapterTest.cs
1 //
2 // DbDataAdapterTest.cs - NUnit Test Cases for testing the DbDataAdapter class
3 //
4 // Author:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (c) 2007 Gert Driesen
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Data;
31 using System.Data.Common;
32
33 using NUnit.Framework;
34
35 namespace MonoTests.System.Data.Common
36 {
37         [TestFixture]
38         public class DbDataAdapterTest
39         {
40 #if NET_2_0
41                 [Test]
42                 public void UpdateBatchSize ()
43                 {
44                         MyAdapter da = new MyAdapter ();
45                         try {
46                                 da.UpdateBatchSize = 0;
47                                 Assert.Fail ("#A1");
48                         } catch (NotSupportedException ex) {
49                                 // Specified method is not supported
50                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
51                                 Assert.IsNull (ex.InnerException, "#A3");
52                                 Assert.IsNotNull (ex.Message, "#A4");
53                         }
54                         Assert.AreEqual (1, da.UpdateBatchSize, "#A5");
55
56                         try {
57                                 da.UpdateBatchSize = int.MaxValue;
58                                 Assert.Fail ("#B1");
59                         } catch (NotSupportedException ex) {
60                                 // Specified method is not supported
61                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
62                                 Assert.IsNull (ex.InnerException, "#B3");
63                                 Assert.IsNotNull (ex.Message, "#B4");
64                         }
65                         Assert.AreEqual (1, da.UpdateBatchSize, "#B5");
66
67                         da.UpdateBatchSize = 1;
68                         Assert.AreEqual (1, da.UpdateBatchSize, "#C");
69                 }
70
71                 [Test]
72                 public void UpdateBatchSize_Negative ()
73                 {
74                         MyAdapter da = new MyAdapter ();
75                         try {
76                                 da.UpdateBatchSize = -1;
77                                 Assert.Fail ("#1");
78                         } catch (NotSupportedException ex) {
79                                 // Specified method is not supported
80                                 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
81                                 Assert.IsNull (ex.InnerException, "#3");
82                                 Assert.IsNotNull (ex.Message, "#4");
83                         }
84                 }
85 #endif
86
87                 class MyAdapter : DbDataAdapter
88                 {
89 #if ONLY_1_1
90                         protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command,
91                                                                                      StatementType statementType,
92                                                                                      DataTableMapping tableMapping)
93                         {
94                                 throw new NotImplementedException ();
95                         }
96
97                         protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command,
98                                                                                        StatementType statementType,
99                                                                                        DataTableMapping tableMapping)
100                         {
101                                 throw new NotImplementedException ();
102                         }
103
104                         protected override void OnRowUpdated (RowUpdatedEventArgs value)
105                         {
106                                 throw new NotImplementedException ();
107                         }
108
109                         protected override void OnRowUpdating (RowUpdatingEventArgs value)
110                         {
111                                 throw new NotImplementedException ();
112                         }
113 #endif
114                 }
115         }
116 }