Merge pull request #1266 from esdrubal/datetimenewformat
[mono.git] / mcs / class / System.Data / Test / System.Data / DBConcurrencyExceptionTest.cs
1 //
2 // DBConcurrencyExceptionTest.cs - NUnit Test Cases for DBConcurrencyException
3 //
4 // Author:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (c) 2008 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
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Data
35 {
36         [TestFixture]
37         public class DBConcurrencyExceptionTest
38         {
39                 [Test] // .ctor ()
40                 public void Constructor1 ()
41                 {
42                         DBConcurrencyException dbce = new DBConcurrencyException ();
43                         Assert.IsNull (dbce.InnerException, "InnerException");
44                         Assert.IsNotNull (dbce.Message, "Message1");
45 #if NET_2_0
46                         Assert.IsNotNull (dbce.Message, "Message2:" + dbce.Message);
47 #else
48                         Assert.AreEqual (new SystemException ().Message, dbce.Message, "Message2:" + dbce.Message);
49 #endif
50                         Assert.IsNull (dbce.Row, "Row");
51 #if NET_2_0
52                         Assert.AreEqual (0, dbce.RowCount, "RowCount");
53 #endif
54                 }
55
56                 [Test] // .ctor (String)
57                 public void Constructor2 ()
58                 {
59                         DBConcurrencyException dbce;
60                         string msg = "MONO";
61
62                         dbce = new DBConcurrencyException (msg);
63                         Assert.IsNull (dbce.InnerException, "#A:InnerException");
64                         Assert.AreSame (msg, dbce.Message, "#A:Message:" + dbce.Message);
65                         Assert.IsNull (dbce.Row, "#A:Row");
66 #if NET_2_0
67                         Assert.AreEqual (0, dbce.RowCount, "#A:RowCount");
68 #endif
69
70                         dbce = new DBConcurrencyException ((string) null);
71                         Assert.IsNull (dbce.InnerException, "#B:InnerException");
72                         Assert.IsNotNull (dbce.Message, "#B:Message1");
73                         Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#B:Message2:" + dbce.Message);
74                         Assert.IsNull (dbce.Row, "#B:Row");
75
76 #if NET_2_0
77                         Assert.AreEqual (0, dbce.RowCount, "#B:RowCount");
78 #endif
79
80                         dbce = new DBConcurrencyException (string.Empty);
81                         Assert.IsNull (dbce.InnerException, "#C:InnerException");
82                         Assert.AreEqual (string.Empty, dbce.Message, "#C:Message");
83                         Assert.IsNull (dbce.Row, "#C:Row");
84 #if NET_2_0
85                         Assert.AreEqual (0, dbce.RowCount, "#C:RowCount");
86 #endif
87                 }
88
89                 [Test] // .ctor (String, Exception)
90                 public void Constructor3 ()
91                 {
92                         Exception inner = new Exception ();
93                         DBConcurrencyException dbce;
94                         string msg = "MONO";
95
96                         dbce = new DBConcurrencyException (msg, inner);
97                         Assert.AreSame (inner, dbce.InnerException, "#A:InnerException");
98                         Assert.AreSame (msg, dbce.Message, "#A:Message:" + dbce.Message);
99                         Assert.IsNull (dbce.Row, "#A:Row");
100 #if NET_2_0
101                         Assert.AreEqual (0, dbce.RowCount, "#A:RowCount");
102 #endif
103
104                         dbce = new DBConcurrencyException ((string) null, inner);
105                         Assert.AreSame (inner, dbce.InnerException, "#B:InnerException");
106                         Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#B:Message:" + dbce.Message);
107                         Assert.IsNull (dbce.Row, "#B:Row");
108 #if NET_2_0
109                         Assert.AreEqual (0, dbce.RowCount, "#B:RowCount");
110 #endif
111
112                         dbce = new DBConcurrencyException (string.Empty, inner);
113                         Assert.AreSame (inner, dbce.InnerException, "#C:InnerException");
114                         Assert.AreEqual (string.Empty, dbce.Message, "#C:Message");
115                         Assert.IsNull (dbce.Row, "#C:Row");
116 #if NET_2_0
117                         Assert.AreEqual (0, dbce.RowCount, "#C:RowCount");
118 #endif
119
120                         dbce = new DBConcurrencyException (msg, (Exception) null);
121                         Assert.IsNull (dbce.InnerException, "#D:InnerException");
122                         Assert.AreSame (msg, dbce.Message, "#D:Message:" + dbce.Message);
123                         Assert.IsNull (dbce.Row, "#D:Row");
124 #if NET_2_0
125                         Assert.AreEqual (0, dbce.RowCount, "#D:RowCount");
126 #endif
127
128                         dbce = new DBConcurrencyException ((string) null, (Exception) null);
129                         Assert.IsNull (dbce.InnerException, "#E:InnerException");
130                         Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#E:Message:" + dbce.Message);
131                         Assert.IsNull (dbce.Row, "#E:Row");
132 #if NET_2_0
133                         Assert.AreEqual (0, dbce.RowCount, "#E:RowCount");
134 #endif
135                 }
136
137 #if NET_2_0
138                 [Test] // .ctor (String, Exception, DataRow [])
139                 public void Constructor4 ()
140                 {
141                         DataTable dt = new DataTable ();
142                         DataRow rowA = dt.NewRow ();
143                         DataRow rowB = dt.NewRow ();
144                         DataRow [] rows;
145                         Exception inner = new Exception ();
146                         DBConcurrencyException dbce;
147                         string msg = "MONO";
148
149                         rows = new DataRow [] { rowA, null, rowB };
150                         dbce = new DBConcurrencyException (msg, inner, rows);
151                         Assert.AreSame (inner, dbce.InnerException, "#A:InnerException");
152                         Assert.AreSame (msg, dbce.Message, "#A:Message:" + dbce.Message);
153                         Assert.AreSame (rowA, dbce.Row, "#A:Row");
154                         Assert.AreEqual (3, dbce.RowCount, "#A:RowCount");
155
156                         rows = new DataRow [] { rowB, rowA, null };
157                         dbce = new DBConcurrencyException ((string) null, inner, rows);
158                         Assert.AreSame (inner, dbce.InnerException, "#B:InnerException");
159                         Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#B:Message:" + dbce.Message);
160                         Assert.AreSame (rowB, dbce.Row, "#B:Row");
161                         Assert.AreEqual (3, dbce.RowCount, "#B:RowCount");
162
163                         rows = new DataRow [] { null, rowA };
164                         dbce = new DBConcurrencyException (string.Empty, inner, rows);
165                         Assert.AreSame (inner, dbce.InnerException, "#C:InnerException");
166                         Assert.AreEqual (string.Empty, dbce.Message, "#C:Message");
167                         Assert.IsNull (dbce.Row, "#C:Row");
168                         Assert.AreEqual (2, dbce.RowCount, "#C:RowCount");
169
170                         rows = new DataRow [] { rowA };
171                         dbce = new DBConcurrencyException (msg, (Exception) null, rows);
172                         Assert.IsNull (dbce.InnerException, "#D:InnerException");
173                         Assert.AreSame (msg, dbce.Message, "#D:Message:" + dbce.Message);
174                         Assert.AreSame (rowA, dbce.Row, "#D:Row");
175                         Assert.AreEqual (1, dbce.RowCount, "#D:RowCount");
176
177                         rows = null;
178                         dbce = new DBConcurrencyException (msg, (Exception) null, rows);
179                         Assert.IsNull (dbce.InnerException, "#E:InnerException");
180                         Assert.AreSame (msg, dbce.Message, "#E:Message:" + dbce.Message);
181                         Assert.IsNull (dbce.Row, "#E:Row");
182                         Assert.AreEqual (0, dbce.RowCount, "#E:RowCount");
183
184                         rows = null;
185                         dbce = new DBConcurrencyException ((string) null, (Exception) null, rows);
186                         Assert.IsNull (dbce.InnerException, "#F:InnerException");
187                         Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#F:Message:" + dbce.Message);
188                         Assert.IsNull (dbce.Row, "#F:Row");
189                         Assert.AreEqual (0, dbce.RowCount, "#F:RowCount");
190                 }
191 #endif
192
193                 [Test]
194                 public void Row ()
195                 {
196                         DataTable dt = new DataTable ();
197                         DataRow rowA = dt.NewRow ();
198                         DataRow rowB = dt.NewRow ();
199
200                         DBConcurrencyException dbce = new DBConcurrencyException ();
201                         dbce.Row = rowA;
202                         Assert.AreSame (rowA, dbce.Row, "#A:Row");
203 #if NET_2_0
204                         Assert.AreEqual (1, dbce.RowCount, "#A:RowCount");
205 #endif
206                         dbce.Row = rowB;
207                         Assert.AreSame (rowB, dbce.Row, "#B:Row");
208 #if NET_2_0
209                         Assert.AreEqual (1, dbce.RowCount, "#B:RowCount");
210 #endif
211                         dbce.Row = null;
212                         Assert.IsNull (dbce.Row, "#C:Row");
213 #if NET_2_0
214                         Assert.AreEqual (1, dbce.RowCount, "#C:RowCount");
215 #endif
216                 }
217         }
218 }