From f0571296c39a4e26241de4e4409a98232ebb88be Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Tue, 30 Dec 2008 19:58:45 +0000 Subject: [PATCH] * DBConcurrencyException.cs: Marked .ctor taking DataRow [] as internal so we can use it on the 1.0 profile (internally). Implemented RowCount. * System.Data_test.dll.sources: Added DBConcurrencyExceptionTest.cs. * DBConcurrencyExceptionTest.cs: Added .ctor and Row(Count) tests. svn path=/trunk/mcs/; revision=122263 --- mcs/class/System.Data/ChangeLog | 4 + mcs/class/System.Data/System.Data/ChangeLog | 6 + .../System.Data/DBConcurrencyException.cs | 32 ++- .../System.Data/System.Data_test.dll.sources | 1 + .../System.Data/Test/System.Data/ChangeLog | 5 +- .../System.Data/DBConcurrencyExceptionTest.cs | 218 ++++++++++++++++++ 6 files changed, 255 insertions(+), 11 deletions(-) create mode 100644 mcs/class/System.Data/Test/System.Data/DBConcurrencyExceptionTest.cs diff --git a/mcs/class/System.Data/ChangeLog b/mcs/class/System.Data/ChangeLog index 60841ebe4a7..9531ff63512 100644 --- a/mcs/class/System.Data/ChangeLog +++ b/mcs/class/System.Data/ChangeLog @@ -1,3 +1,7 @@ +2008-12-30 Gert Driesen + + * System.Data_test.dll.sources: Added DBConcurrencyExceptionTest.cs. + 2008-12-30 Gert Driesen * System.Data_test.dll.sources: Added OdbcCommandBuilderTest.cs, diff --git a/mcs/class/System.Data/System.Data/ChangeLog b/mcs/class/System.Data/System.Data/ChangeLog index 28c2ed2f29d..5a92ec937f9 100644 --- a/mcs/class/System.Data/System.Data/ChangeLog +++ b/mcs/class/System.Data/System.Data/ChangeLog @@ -1,3 +1,9 @@ +2008-12-30 Gert Driesen + + * DBConcurrencyException.cs: Marked .ctor taking DataRow [] as + internal so we can use it on the 1.0 profile (internally). Implemented + RowCount. + 2008-12-29 Gert Driesen * SqlDbType: Added Date and Time (2.0 only). diff --git a/mcs/class/System.Data/System.Data/DBConcurrencyException.cs b/mcs/class/System.Data/System.Data/DBConcurrencyException.cs index ca03b8bdda3..78d408acf6e 100644 --- a/mcs/class/System.Data/System.Data/DBConcurrencyException.cs +++ b/mcs/class/System.Data/System.Data/DBConcurrencyException.cs @@ -37,15 +37,16 @@ namespace System.Data [Serializable] public sealed class DBConcurrencyException : SystemException { - DataRow row; + DataRow [] rows; #region Constructors -#if NET_1_1 - public DBConcurrencyException () : base () + public DBConcurrencyException () +#if NET_2_0 + : base ("Concurrency violation.") +#endif { } -#endif public DBConcurrencyException (string message) : base (message) @@ -58,11 +59,15 @@ namespace System.Data } #if NET_2_0 - public DBConcurrencyException (string message, Exception inner, DataRow[] dataRows) + public +#else + internal +#endif + DBConcurrencyException (string message, Exception inner, DataRow[] dataRows) : base (message, inner) { + rows = dataRows; } -#endif private DBConcurrencyException (SerializationInfo si, StreamingContext sc) : base(si, sc) { @@ -73,14 +78,21 @@ namespace System.Data #region Properties public DataRow Row { - get { return row; } - set { row = value;} // setting the row has no effect + get { + if (rows != null) + return rows [0]; + return null; + } + set { rows = new DataRow [] { value };} } #if NET_2_0 - [MonoTODO] public int RowCount { - get { throw new NotImplementedException (); } + get { + if (rows != null) + return rows.Length; + return 0; + } } #endif diff --git a/mcs/class/System.Data/System.Data_test.dll.sources b/mcs/class/System.Data/System.Data_test.dll.sources index bed4323c066..e8543f0c316 100644 --- a/mcs/class/System.Data/System.Data_test.dll.sources +++ b/mcs/class/System.Data/System.Data_test.dll.sources @@ -55,6 +55,7 @@ System.Data/DataViewTest.cs System.Data/DataViewTest2.cs System.Data/DataViewTest_IBindingList.cs System.Data/DataViewTest_IBindingListView.cs +System.Data/DBConcurrencyExceptionTest.cs System.Data/ForeignKeyConstraintTest.cs System.Data/ForeignKeyConstraintTest2.cs System.Data/MonkeyDataSet.cs diff --git a/mcs/class/System.Data/Test/System.Data/ChangeLog b/mcs/class/System.Data/Test/System.Data/ChangeLog index de2867a267d..3d00d009e8b 100644 --- a/mcs/class/System.Data/Test/System.Data/ChangeLog +++ b/mcs/class/System.Data/Test/System.Data/ChangeLog @@ -1,3 +1,7 @@ +2008-12-30 Gert Driesen + + * DBConcurrencyExceptionTest.cs: Added .ctor and Row(Count) tests. + 2008-12-29 Gert Driesen * DataTableTest.cs: Allow NFIFromBug55978 test to pass when MONO_PATH @@ -6,7 +10,6 @@ tests. * DataColumnTest2.cs: Change culture for culture-sensitive tests. - 2008-11-18 Raja R Harinath * DataSetTest.cs (Bug420862): New test. diff --git a/mcs/class/System.Data/Test/System.Data/DBConcurrencyExceptionTest.cs b/mcs/class/System.Data/Test/System.Data/DBConcurrencyExceptionTest.cs new file mode 100644 index 00000000000..bfae78d6e6e --- /dev/null +++ b/mcs/class/System.Data/Test/System.Data/DBConcurrencyExceptionTest.cs @@ -0,0 +1,218 @@ +// +// DBConcurrencyExceptionTest.cs - NUnit Test Cases for DBConcurrencyException +// +// Author: +// Gert Driesen (drieseng@users.sourceforge.net) +// +// Copyright (c) 2008 Gert Driesen +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Data; + +using NUnit.Framework; + +namespace MonoTests_System.Data +{ + [TestFixture] + public class DBConcurrencyExceptionTest + { + [Test] // .ctor () + public void Constructor1 () + { + DBConcurrencyException dbce = new DBConcurrencyException (); + Assert.IsNull (dbce.InnerException, "InnerException"); + Assert.IsNotNull (dbce.Message, "Message1"); +#if NET_2_0 + Assert.IsNotNull (dbce.Message, "Message2:" + dbce.Message); +#else + Assert.AreEqual (new SystemException ().Message, dbce.Message, "Message2:" + dbce.Message); +#endif + Assert.IsNull (dbce.Row, "Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "RowCount"); +#endif + } + + [Test] // .ctor (String) + public void Constructor2 () + { + DBConcurrencyException dbce; + string msg = "MONO"; + + dbce = new DBConcurrencyException (msg); + Assert.IsNull (dbce.InnerException, "#A:InnerException"); + Assert.AreSame (msg, dbce.Message, "#A:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#A:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#A:RowCount"); +#endif + + dbce = new DBConcurrencyException ((string) null); + Assert.IsNull (dbce.InnerException, "#B:InnerException"); + Assert.IsNotNull (dbce.Message, "#B:Message1"); + Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#B:Message2:" + dbce.Message); + Assert.IsNull (dbce.Row, "#B:Row"); + +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#B:RowCount"); +#endif + + dbce = new DBConcurrencyException (string.Empty); + Assert.IsNull (dbce.InnerException, "#C:InnerException"); + Assert.AreEqual (string.Empty, dbce.Message, "#C:Message"); + Assert.IsNull (dbce.Row, "#C:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#C:RowCount"); +#endif + } + + [Test] // .ctor (String, Exception) + public void Constructor3 () + { + Exception inner = new Exception (); + DBConcurrencyException dbce; + string msg = "MONO"; + + dbce = new DBConcurrencyException (msg, inner); + Assert.AreSame (inner, dbce.InnerException, "#A:InnerException"); + Assert.AreSame (msg, dbce.Message, "#A:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#A:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#A:RowCount"); +#endif + + dbce = new DBConcurrencyException ((string) null, inner); + Assert.AreSame (inner, dbce.InnerException, "#B:InnerException"); + Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#B:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#B:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#B:RowCount"); +#endif + + dbce = new DBConcurrencyException (string.Empty, inner); + Assert.AreSame (inner, dbce.InnerException, "#C:InnerException"); + Assert.AreEqual (string.Empty, dbce.Message, "#C:Message"); + Assert.IsNull (dbce.Row, "#C:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#C:RowCount"); +#endif + + dbce = new DBConcurrencyException (msg, (Exception) null); + Assert.IsNull (dbce.InnerException, "#D:InnerException"); + Assert.AreSame (msg, dbce.Message, "#D:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#D:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#D:RowCount"); +#endif + + dbce = new DBConcurrencyException ((string) null, (Exception) null); + Assert.IsNull (dbce.InnerException, "#E:InnerException"); + Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#E:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#E:Row"); +#if NET_2_0 + Assert.AreEqual (0, dbce.RowCount, "#E:RowCount"); +#endif + } + +#if NET_2_0 + [Test] // .ctor (String, Exception, DataRow []) + public void Constructor4 () + { + DataTable dt = new DataTable (); + DataRow rowA = dt.NewRow (); + DataRow rowB = dt.NewRow (); + DataRow [] rows; + Exception inner = new Exception (); + DBConcurrencyException dbce; + string msg = "MONO"; + + rows = new DataRow [] { rowA, null, rowB }; + dbce = new DBConcurrencyException (msg, inner, rows); + Assert.AreSame (inner, dbce.InnerException, "#A:InnerException"); + Assert.AreSame (msg, dbce.Message, "#A:Message:" + dbce.Message); + Assert.AreSame (rowA, dbce.Row, "#A:Row"); + Assert.AreEqual (3, dbce.RowCount, "#A:RowCount"); + + rows = new DataRow [] { rowB, rowA, null }; + dbce = new DBConcurrencyException ((string) null, inner, rows); + Assert.AreSame (inner, dbce.InnerException, "#B:InnerException"); + Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#B:Message:" + dbce.Message); + Assert.AreSame (rowB, dbce.Row, "#B:Row"); + Assert.AreEqual (3, dbce.RowCount, "#B:RowCount"); + + rows = new DataRow [] { null, rowA }; + dbce = new DBConcurrencyException (string.Empty, inner, rows); + Assert.AreSame (inner, dbce.InnerException, "#C:InnerException"); + Assert.AreEqual (string.Empty, dbce.Message, "#C:Message"); + Assert.IsNull (dbce.Row, "#C:Row"); + Assert.AreEqual (2, dbce.RowCount, "#C:RowCount"); + + rows = new DataRow [] { rowA }; + dbce = new DBConcurrencyException (msg, (Exception) null, rows); + Assert.IsNull (dbce.InnerException, "#D:InnerException"); + Assert.AreSame (msg, dbce.Message, "#D:Message:" + dbce.Message); + Assert.AreSame (rowA, dbce.Row, "#D:Row"); + Assert.AreEqual (1, dbce.RowCount, "#D:RowCount"); + + rows = null; + dbce = new DBConcurrencyException (msg, (Exception) null, rows); + Assert.IsNull (dbce.InnerException, "#E:InnerException"); + Assert.AreSame (msg, dbce.Message, "#E:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#E:Row"); + Assert.AreEqual (0, dbce.RowCount, "#E:RowCount"); + + rows = null; + dbce = new DBConcurrencyException ((string) null, (Exception) null, rows); + Assert.IsNull (dbce.InnerException, "#F:InnerException"); + Assert.IsTrue (dbce.Message.IndexOf (typeof (DBConcurrencyException).FullName) != -1, "#F:Message:" + dbce.Message); + Assert.IsNull (dbce.Row, "#F:Row"); + Assert.AreEqual (0, dbce.RowCount, "#F:RowCount"); + } +#endif + + [Test] + public void Row () + { + DataTable dt = new DataTable (); + DataRow rowA = dt.NewRow (); + DataRow rowB = dt.NewRow (); + + DBConcurrencyException dbce = new DBConcurrencyException (); + dbce.Row = rowA; + Assert.AreSame (rowA, dbce.Row, "#A:Row"); +#if NET_2_0 + Assert.AreEqual (1, dbce.RowCount, "#A:RowCount"); +#endif + dbce.Row = rowB; + Assert.AreSame (rowB, dbce.Row, "#B:Row"); +#if NET_2_0 + Assert.AreEqual (1, dbce.RowCount, "#B:RowCount"); +#endif + dbce.Row = null; + Assert.IsNull (dbce.Row, "#C:Row"); +#if NET_2_0 + Assert.AreEqual (1, dbce.RowCount, "#C:RowCount"); +#endif + } + } +} -- 2.25.1