2 // DBConcurrencyExceptionTest.cs - NUnit Test Cases for DBConcurrencyException
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // Copyright (c) 2008 Gert Driesen
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
32 using NUnit.Framework;
34 namespace MonoTests_System.Data
37 public class DBConcurrencyExceptionTest
40 public void Constructor1 ()
42 DBConcurrencyException dbce = new DBConcurrencyException ();
43 Assert.IsNull (dbce.InnerException, "InnerException");
44 Assert.IsNotNull (dbce.Message, "Message1");
46 Assert.IsNotNull (dbce.Message, "Message2:" + dbce.Message);
48 Assert.AreEqual (new SystemException ().Message, dbce.Message, "Message2:" + dbce.Message);
50 Assert.IsNull (dbce.Row, "Row");
52 Assert.AreEqual (0, dbce.RowCount, "RowCount");
56 [Test] // .ctor (String)
57 public void Constructor2 ()
59 DBConcurrencyException dbce;
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");
67 Assert.AreEqual (0, dbce.RowCount, "#A:RowCount");
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");
77 Assert.AreEqual (0, dbce.RowCount, "#B:RowCount");
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");
85 Assert.AreEqual (0, dbce.RowCount, "#C:RowCount");
89 [Test] // .ctor (String, Exception)
90 public void Constructor3 ()
92 Exception inner = new Exception ();
93 DBConcurrencyException dbce;
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");
101 Assert.AreEqual (0, dbce.RowCount, "#A:RowCount");
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");
109 Assert.AreEqual (0, dbce.RowCount, "#B:RowCount");
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");
117 Assert.AreEqual (0, dbce.RowCount, "#C:RowCount");
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");
125 Assert.AreEqual (0, dbce.RowCount, "#D:RowCount");
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");
133 Assert.AreEqual (0, dbce.RowCount, "#E:RowCount");
138 [Test] // .ctor (String, Exception, DataRow [])
139 public void Constructor4 ()
141 DataTable dt = new DataTable ();
142 DataRow rowA = dt.NewRow ();
143 DataRow rowB = dt.NewRow ();
145 Exception inner = new Exception ();
146 DBConcurrencyException dbce;
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");
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");
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");
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");
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");
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");
196 DataTable dt = new DataTable ();
197 DataRow rowA = dt.NewRow ();
198 DataRow rowB = dt.NewRow ();
200 DBConcurrencyException dbce = new DBConcurrencyException ();
202 Assert.AreSame (rowA, dbce.Row, "#A:Row");
204 Assert.AreEqual (1, dbce.RowCount, "#A:RowCount");
207 Assert.AreSame (rowB, dbce.Row, "#B:Row");
209 Assert.AreEqual (1, dbce.RowCount, "#B:RowCount");
212 Assert.IsNull (dbce.Row, "#C:Row");
214 Assert.AreEqual (1, dbce.RowCount, "#C:RowCount");