|
|
@@ -2,12 +2,12 @@
|
|
|
//
|
|
|
// Authors:
|
|
|
// Franklin Wise ([email protected])
|
|
|
-// Martin Willemoes Hansen ([email protected])
|
|
|
-// Hagit Yidov ([email protected])
|
|
|
+// Martin Willemoes Hansen ([email protected])
|
|
|
+// Hagit Yidov ([email protected])
|
|
|
//
|
|
|
// (C) Franklin Wise
|
|
|
-// (C) 2003 Martin Willemoes Hansen
|
|
|
-// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
|
|
|
+// (C) 2003 Martin Willemoes Hansen
|
|
|
+// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
|
|
|
|
|
|
//
|
|
|
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
|
|
@@ -39,14 +39,17 @@ using System.Data.SqlTypes;
|
|
|
using System.Globalization;
|
|
|
using System.IO;
|
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
|
-using System.Xml;
|
|
|
+using System.Xml;
|
|
|
+using MonoTests.System.Data.Utils;
|
|
|
+using System.Collections;
|
|
|
|
|
|
namespace MonoTests.System.Data
|
|
|
{
|
|
|
[TestFixture]
|
|
|
- public class DataTableTest : Assertion
|
|
|
- {
|
|
|
-
|
|
|
+ public class DataTableTest : DataSetAssertion
|
|
|
+ {
|
|
|
+ string EOL = Environment.NewLine;
|
|
|
+
|
|
|
[Test]
|
|
|
public void Ctor()
|
|
|
{
|
|
|
@@ -1527,8 +1530,8 @@ namespace MonoTests.System.Data
|
|
|
|
|
|
[Test]
|
|
|
public void ColumnObjectTypeTest() {
|
|
|
- DataTable dt = new DataTable();
|
|
|
- dt.Columns.Add("Series Label", typeof(SqlInt32));
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ dt.Columns.Add("Series Label", typeof(SqlInt32));
|
|
|
dt.Rows.Add(new object[] {"sss"});
|
|
|
AssertEquals(1, dt.Rows.Count);
|
|
|
}
|
|
|
@@ -1540,865 +1543,2042 @@ namespace MonoTests.System.Data
|
|
|
|
|
|
public void OnRowChanged (object src, DataRowChangeEventArgs args)
|
|
|
{
|
|
|
- rowActionChanged = args.Action;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-#if NET_2_0
|
|
|
- #region DataTable.CreateDataReader Tests and DataTable.Load Tests
|
|
|
-
|
|
|
- private DataTable dt;
|
|
|
-
|
|
|
- private void localSetup () {
|
|
|
- dt = new DataTable ("test");
|
|
|
- dt.Columns.Add ("id", typeof (int));
|
|
|
- dt.Columns.Add ("name", typeof (string));
|
|
|
- dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
|
|
|
-
|
|
|
- dt.Rows.Add (new object[] { 1, "mono 1" });
|
|
|
- dt.Rows.Add (new object[] { 2, "mono 2" });
|
|
|
- dt.Rows.Add (new object[] { 3, "mono 3" });
|
|
|
-
|
|
|
- dt.AcceptChanges ();
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void CreateDataReader1 () {
|
|
|
- localSetup ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- Assert ("HasRows", dtr.HasRows);
|
|
|
- AssertEquals ("CountCols", dt.Columns.Count, dtr.FieldCount);
|
|
|
- int ri = 0;
|
|
|
- while (dtr.Read ()) {
|
|
|
- for (int i = 0; i < dtr.FieldCount; i++) {
|
|
|
- AssertEquals ("RowData-" + ri + "-" + i, dt.Rows[ri][i],
|
|
|
- dtr[i]);
|
|
|
- }
|
|
|
- ri++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void CreateDataReader2 () {
|
|
|
- localSetup ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- Assert ("HasRows", dtr.HasRows);
|
|
|
- AssertEquals ("CountCols", dt.Columns.Count, dtr.FieldCount);
|
|
|
- dtr.Read ();
|
|
|
- AssertEquals ("RowData0-0", 1, dtr[0]);
|
|
|
- AssertEquals ("RowData0-1", "mono 1", dtr[1]);
|
|
|
- dtr.Read ();
|
|
|
- AssertEquals ("RowData1-0", 2, dtr[0]);
|
|
|
- AssertEquals ("RowData1-1", "mono 2", dtr[1]);
|
|
|
- dtr.Read ();
|
|
|
- AssertEquals ("RowData2-0", 3, dtr[0]);
|
|
|
- AssertEquals ("RowData2-1", "mono 3", dtr[1]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_Basic () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadBasic");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.Columns["id"].ReadOnly = true;
|
|
|
- dtLoad.Columns["name"].ReadOnly = true;
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "load 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "load 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "load 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
- AssertEquals ("NRows", 3, dtLoad.Rows.Count);
|
|
|
- AssertEquals ("RowData0-0", 1, dtLoad.Rows[0][0]);
|
|
|
- AssertEquals ("RowData0-1", "mono 1", dtLoad.Rows[0][1]);
|
|
|
- AssertEquals ("RowData1-0", 2, dtLoad.Rows[1][0]);
|
|
|
- AssertEquals ("RowData1-1", "mono 2", dtLoad.Rows[1][1]);
|
|
|
- AssertEquals ("RowData2-0", 3, dtLoad.Rows[2][0]);
|
|
|
- AssertEquals ("RowData2-1", "mono 3", dtLoad.Rows[2][1]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_NoSchema () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadNoSchema");
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
- AssertEquals ("NRows", 3, dtLoad.Rows.Count);
|
|
|
- AssertEquals ("RowData0-0", 1, dtLoad.Rows[0][0]);
|
|
|
- AssertEquals ("RowData0-1", "mono 1", dtLoad.Rows[0][1]);
|
|
|
- AssertEquals ("RowData1-0", 2, dtLoad.Rows[1][0]);
|
|
|
- AssertEquals ("RowData1-1", "mono 2", dtLoad.Rows[1][1]);
|
|
|
- AssertEquals ("RowData2-0", 3, dtLoad.Rows[2][0]);
|
|
|
- AssertEquals ("RowData2-1", "mono 3", dtLoad.Rows[2][1]);
|
|
|
- }
|
|
|
-
|
|
|
- internal struct fillErrorStruct {
|
|
|
- internal string error;
|
|
|
- internal string tableName;
|
|
|
- internal int rowKey;
|
|
|
- internal bool contFlag;
|
|
|
- internal void init (string tbl, int row, bool cont, string err) {
|
|
|
- tableName = tbl;
|
|
|
- rowKey = row;
|
|
|
- contFlag = cont;
|
|
|
- error = err;
|
|
|
- }
|
|
|
- }
|
|
|
- private fillErrorStruct[] fillErr = new fillErrorStruct[3];
|
|
|
- private int fillErrCounter;
|
|
|
- private void fillErrorHandler (object sender, FillErrorEventArgs e) {
|
|
|
- e.Continue = fillErr[fillErrCounter].contFlag;
|
|
|
- AssertEquals ("fillErr-T", fillErr[fillErrCounter].tableName, e.DataTable.TableName);
|
|
|
- AssertEquals ("fillErr-R", fillErr[fillErrCounter].rowKey, e.Values[0]);
|
|
|
- AssertEquals ("fillErr-C", fillErr[fillErrCounter].contFlag, e.Continue);
|
|
|
- AssertEquals ("fillErr-E", fillErr[fillErrCounter].error, e.Errors.Message);
|
|
|
- fillErrCounter++;
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (ArgumentException))]
|
|
|
- public void Load_Incompatible () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadIncompatible");
|
|
|
- dtLoad.Columns.Add ("name", typeof (double));
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- }
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- // Load doesn't have a third overload in System.Data
|
|
|
- // and is commented-out below
|
|
|
- public void Load_IncompatibleEHandlerT () {
|
|
|
- fillErrCounter = 0;
|
|
|
- fillErr[0].init ("LoadIncompatible", 1, true,
|
|
|
- "Input string was not in a correct format.Couldn't store <mono 1> in name Column. Expected type is Double.");
|
|
|
- fillErr[1].init ("LoadIncompatible", 2, true,
|
|
|
- "Input string was not in a correct format.Couldn't store <mono 2> in name Column. Expected type is Double.");
|
|
|
- fillErr[2].init ("LoadIncompatible", 3, true,
|
|
|
- "Input string was not in a correct format.Couldn't store <mono 3> in name Column. Expected type is Double.");
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadIncompatible");
|
|
|
- dtLoad.Columns.Add ("name", typeof (double));
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- //dtLoad.Load (dtr,LoadOption.PreserveChanges,fillErrorHandler);
|
|
|
- }
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- // Load doesn't have a third overload in System.Data
|
|
|
- // and is commented-out below
|
|
|
- [ExpectedException (typeof (ArgumentException))]
|
|
|
- public void Load_IncompatibleEHandlerF () {
|
|
|
- fillErrCounter = 0;
|
|
|
- fillErr[0].init ("LoadIncompatible", 1, false,
|
|
|
- "Input string was not in a correct format.Couldn't store <mono 1> in name Column. Expected type is Double.");
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadIncompatible");
|
|
|
- dtLoad.Columns.Add ("name", typeof (double));
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- //dtLoad.Load (dtr, LoadOption.PreserveChanges, fillErrorHandler);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_ExtraColsEqualVal () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadExtraCols");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1 });
|
|
|
- dtLoad.Rows.Add (new object[] { 2 });
|
|
|
- dtLoad.Rows.Add (new object[] { 3 });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
- AssertEquals ("NRows", 3, dtLoad.Rows.Count);
|
|
|
- AssertEquals ("RowData0-0", 1, dtLoad.Rows[0][0]);
|
|
|
- AssertEquals ("RowData0-1", "mono 1", dtLoad.Rows[0][1]);
|
|
|
- AssertEquals ("RowData1-0", 2, dtLoad.Rows[1][0]);
|
|
|
- AssertEquals ("RowData1-1", "mono 2", dtLoad.Rows[1][1]);
|
|
|
- AssertEquals ("RowData2-0", 3, dtLoad.Rows[2][0]);
|
|
|
- AssertEquals ("RowData2-1", "mono 3", dtLoad.Rows[2][1]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_ExtraColsNonEqualVal () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadExtraCols");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 4 });
|
|
|
- dtLoad.Rows.Add (new object[] { 5 });
|
|
|
- dtLoad.Rows.Add (new object[] { 6 });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
- AssertEquals ("NRows", 6, dtLoad.Rows.Count);
|
|
|
- AssertEquals ("RowData0-0", 4, dtLoad.Rows[0][0]);
|
|
|
- AssertEquals ("RowData1-0", 5, dtLoad.Rows[1][0]);
|
|
|
- AssertEquals ("RowData2-0", 6, dtLoad.Rows[2][0]);
|
|
|
- AssertEquals ("RowData3-0", 1, dtLoad.Rows[3][0]);
|
|
|
- AssertEquals ("RowData3-1", "mono 1", dtLoad.Rows[3][1]);
|
|
|
- AssertEquals ("RowData4-0", 2, dtLoad.Rows[4][0]);
|
|
|
- AssertEquals ("RowData4-1", "mono 2", dtLoad.Rows[4][1]);
|
|
|
- AssertEquals ("RowData5-0", 3, dtLoad.Rows[5][0]);
|
|
|
- AssertEquals ("RowData5-1", "mono 3", dtLoad.Rows[5][1]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (ConstraintException))]
|
|
|
- public void Load_MissingColsNonNullable () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadMissingCols");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.Columns.Add ("missing", typeof (string));
|
|
|
- dtLoad.Columns["missing"].AllowDBNull = false;
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 4, "mono 4", "miss4" });
|
|
|
- dtLoad.Rows.Add (new object[] { 5, "mono 5", "miss5" });
|
|
|
- dtLoad.Rows.Add (new object[] { 6, "mono 6", "miss6" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_MissingColsDefault () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadMissingCols");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.Columns.Add ("missing", typeof (string));
|
|
|
- dtLoad.Columns["missing"].AllowDBNull = false;
|
|
|
- dtLoad.Columns["missing"].DefaultValue = "DefaultValue";
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 4, "mono 4", "miss4" });
|
|
|
- dtLoad.Rows.Add (new object[] { 5, "mono 5", "miss5" });
|
|
|
- dtLoad.Rows.Add (new object[] { 6, "mono 6", "miss6" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("NColumns", 3, dtLoad.Columns.Count);
|
|
|
- AssertEquals ("NRows", 6, dtLoad.Rows.Count);
|
|
|
- AssertEquals ("RowData0-0", 4, dtLoad.Rows[0][0]);
|
|
|
- AssertEquals ("RowData0-1", "mono 4", dtLoad.Rows[0][1]);
|
|
|
- AssertEquals ("RowData0-2", "miss4", dtLoad.Rows[0][2]);
|
|
|
- AssertEquals ("RowData1-0", 5, dtLoad.Rows[1][0]);
|
|
|
- AssertEquals ("RowData1-1", "mono 5", dtLoad.Rows[1][1]);
|
|
|
- AssertEquals ("RowData1-2", "miss5", dtLoad.Rows[1][2]);
|
|
|
- AssertEquals ("RowData2-0", 6, dtLoad.Rows[2][0]);
|
|
|
- AssertEquals ("RowData2-1", "mono 6", dtLoad.Rows[2][1]);
|
|
|
- AssertEquals ("RowData2-2", "miss6", dtLoad.Rows[2][2]);
|
|
|
- AssertEquals ("RowData3-0", 1, dtLoad.Rows[3][0]);
|
|
|
- AssertEquals ("RowData3-1", "mono 1", dtLoad.Rows[3][1]);
|
|
|
- AssertEquals ("RowData3-2", "DefaultValue", dtLoad.Rows[3][2]);
|
|
|
- AssertEquals ("RowData4-0", 2, dtLoad.Rows[4][0]);
|
|
|
- AssertEquals ("RowData4-1", "mono 2", dtLoad.Rows[4][1]);
|
|
|
- AssertEquals ("RowData4-2", "DefaultValue", dtLoad.Rows[4][2]);
|
|
|
- AssertEquals ("RowData5-0", 3, dtLoad.Rows[5][0]);
|
|
|
- AssertEquals ("RowData5-1", "mono 3", dtLoad.Rows[5][1]);
|
|
|
- AssertEquals ("RowData5-2", "DefaultValue", dtLoad.Rows[5][2]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_MissingColsNullable () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadMissingCols");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.Columns.Add ("missing", typeof (string));
|
|
|
- dtLoad.Columns["missing"].AllowDBNull = true;
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 4, "mono 4", "miss4" });
|
|
|
- dtLoad.Rows.Add (new object[] { 5, "mono 5", "miss5" });
|
|
|
- dtLoad.Rows.Add (new object[] { 6, "mono 6", "miss6" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("NColumns", 3, dtLoad.Columns.Count);
|
|
|
- AssertEquals ("NRows", 6, dtLoad.Rows.Count);
|
|
|
- AssertEquals ("RowData0-0", 4, dtLoad.Rows[0][0]);
|
|
|
- AssertEquals ("RowData0-1", "mono 4", dtLoad.Rows[0][1]);
|
|
|
- AssertEquals ("RowData0-2", "miss4", dtLoad.Rows[0][2]);
|
|
|
- AssertEquals ("RowData1-0", 5, dtLoad.Rows[1][0]);
|
|
|
- AssertEquals ("RowData1-1", "mono 5", dtLoad.Rows[1][1]);
|
|
|
- AssertEquals ("RowData1-2", "miss5", dtLoad.Rows[1][2]);
|
|
|
- AssertEquals ("RowData2-0", 6, dtLoad.Rows[2][0]);
|
|
|
- AssertEquals ("RowData2-1", "mono 6", dtLoad.Rows[2][1]);
|
|
|
- AssertEquals ("RowData2-2", "miss6", dtLoad.Rows[2][2]);
|
|
|
- AssertEquals ("RowData3-0", 1, dtLoad.Rows[3][0]);
|
|
|
- AssertEquals ("RowData3-1", "mono 1", dtLoad.Rows[3][1]);
|
|
|
- //AssertEquals ("RowData3-2", null, dtLoad.Rows[3][2]);
|
|
|
- AssertEquals ("RowData4-0", 2, dtLoad.Rows[4][0]);
|
|
|
- AssertEquals ("RowData4-1", "mono 2", dtLoad.Rows[4][1]);
|
|
|
- //AssertEquals ("RowData4-2", null, dtLoad.Rows[4][2]);
|
|
|
- AssertEquals ("RowData5-0", 3, dtLoad.Rows[5][0]);
|
|
|
- AssertEquals ("RowData5-1", "mono 3", dtLoad.Rows[5][1]);
|
|
|
- //AssertEquals ("RowData5-2", null, dtLoad.Rows[5][2]);
|
|
|
- }
|
|
|
-
|
|
|
- private DataTable setupRowState () {
|
|
|
- DataTable tbl = new DataTable ("LoadRowStateChanges");
|
|
|
- tbl.RowChanged += new DataRowChangeEventHandler (dtLoad_RowChanged);
|
|
|
- tbl.RowChanging += new DataRowChangeEventHandler (dtLoad_RowChanging);
|
|
|
- tbl.Columns.Add ("id", typeof (int));
|
|
|
- tbl.Columns.Add ("name", typeof (string));
|
|
|
- tbl.PrimaryKey = new DataColumn[] { tbl.Columns["id"] };
|
|
|
- tbl.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- tbl.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- tbl.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- tbl.AcceptChanges ();
|
|
|
- // Update Table with following changes: Row0 unmodified,
|
|
|
- // Row1 modified, Row2 deleted, Row3 added, Row4 not-present.
|
|
|
- tbl.Rows[1]["name"] = "Modify 2";
|
|
|
- tbl.Rows[2].Delete ();
|
|
|
- DataRow row = tbl.NewRow ();
|
|
|
- row["id"] = 4;
|
|
|
- row["name"] = "Add 4";
|
|
|
- tbl.Rows.Add (row);
|
|
|
- return (tbl);
|
|
|
- }
|
|
|
-
|
|
|
- private DataRowAction[] rowChangeAction = new DataRowAction[5];
|
|
|
- private bool checkAction = false;
|
|
|
- private int rowChagedCounter, rowChangingCounter;
|
|
|
- private void rowActionInit (DataRowAction[] act) {
|
|
|
- checkAction = true;
|
|
|
- rowChagedCounter = 0;
|
|
|
- rowChangingCounter = 0;
|
|
|
- for (int i = 0; i < 5; i++)
|
|
|
- rowChangeAction[i] = act[i];
|
|
|
- }
|
|
|
- private void rowActionEnd () {
|
|
|
- checkAction = false;
|
|
|
- }
|
|
|
- private void dtLoad_RowChanged (object sender, DataRowChangeEventArgs e) {
|
|
|
- if (checkAction) {
|
|
|
- AssertEquals ("RowChanged" + rowChagedCounter,
|
|
|
- rowChangeAction[rowChagedCounter], e.Action);
|
|
|
- rowChagedCounter++;
|
|
|
- }
|
|
|
- }
|
|
|
- private void dtLoad_RowChanging (object sender, DataRowChangeEventArgs e) {
|
|
|
- if (checkAction) {
|
|
|
- AssertEquals ("RowChanging" + rowChangingCounter,
|
|
|
- rowChangeAction[rowChangingCounter], e.Action);
|
|
|
- rowChangingCounter++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateChangesDefault () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
- dt.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- DataTable dtLoad = setupRowState ();
|
|
|
- DataRowAction[] dra = new DataRowAction[] {
|
|
|
- DataRowAction.ChangeCurrentAndOriginal,
|
|
|
- DataRowAction.ChangeOriginal,
|
|
|
- DataRowAction.ChangeOriginal,
|
|
|
- DataRowAction.ChangeOriginal,
|
|
|
- DataRowAction.ChangeCurrentAndOriginal};
|
|
|
- rowActionInit (dra);
|
|
|
- dtLoad.Load (dtr);
|
|
|
- rowActionEnd ();
|
|
|
- // asserting Unchanged Row0
|
|
|
- AssertEquals ("RowData0-C", "mono 1",
|
|
|
- dtLoad.Rows[0][1,DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData0-O", "mono 1",
|
|
|
- dtLoad.Rows[0][1,DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[0].RowState);
|
|
|
- // asserting Modified Row1
|
|
|
- AssertEquals ("RowData1-C", "Modify 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData1-O", "mono 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState1", DataRowState.Modified,
|
|
|
- dtLoad.Rows[1].RowState);
|
|
|
- // asserting Deleted Row2
|
|
|
- AssertEquals ("RowData1-O", "mono 3",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState2", DataRowState.Deleted,
|
|
|
- dtLoad.Rows[2].RowState);
|
|
|
- // asserting Added Row3
|
|
|
- AssertEquals ("RowData3-C", "Add 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData3-O", "mono 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState3", DataRowState.Modified,
|
|
|
- dtLoad.Rows[3].RowState);
|
|
|
- // asserting Unpresent Row4
|
|
|
- AssertEquals ("RowData4-C", "mono 5",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData4-O", "mono 5",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState4", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[4].RowState);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateChangesDefaultDelete () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- dtLoad.Rows[2].Delete ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr);
|
|
|
- AssertEquals ("RowData2-C", " ",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStatePreserveChanges () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
- dt.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- DataTable dtLoad = setupRowState ();
|
|
|
- DataRowAction[] dra = new DataRowAction[] {
|
|
|
- DataRowAction.ChangeCurrentAndOriginal,
|
|
|
- DataRowAction.ChangeOriginal,
|
|
|
- DataRowAction.ChangeOriginal,
|
|
|
- DataRowAction.ChangeOriginal,
|
|
|
- DataRowAction.ChangeCurrentAndOriginal};
|
|
|
- rowActionInit (dra);
|
|
|
- dtLoad.Load (dtr, LoadOption.PreserveChanges);
|
|
|
- rowActionEnd ();
|
|
|
- // asserting Unchanged Row0
|
|
|
- AssertEquals ("RowData0-C", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData0-O", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[0].RowState);
|
|
|
- // asserting Modified Row1
|
|
|
- AssertEquals ("RowData1-C", "Modify 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData1-O", "mono 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState1", DataRowState.Modified,
|
|
|
- dtLoad.Rows[1].RowState);
|
|
|
- // asserting Deleted Row2
|
|
|
- AssertEquals ("RowData1-O", "mono 3",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState2", DataRowState.Deleted,
|
|
|
- dtLoad.Rows[2].RowState);
|
|
|
- // asserting Added Row3
|
|
|
- AssertEquals ("RowData3-C", "Add 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData3-O", "mono 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState3", DataRowState.Modified,
|
|
|
- dtLoad.Rows[3].RowState);
|
|
|
- // asserting Unpresent Row4
|
|
|
- AssertEquals ("RowData4-C", "mono 5",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData4-O", "mono 5",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState4", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[4].RowState);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStatePreserveChangesDelete () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- dtLoad.Rows[2].Delete ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr,LoadOption.PreserveChanges);
|
|
|
- AssertEquals ("RowData2-C", " ",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateOverwriteChanges () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
- dt.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- DataTable dtLoad = setupRowState ();
|
|
|
- DataRowAction[] dra = new DataRowAction[] {
|
|
|
- DataRowAction.ChangeCurrentAndOriginal,
|
|
|
- DataRowAction.ChangeCurrentAndOriginal,
|
|
|
- DataRowAction.ChangeCurrentAndOriginal,
|
|
|
- DataRowAction.ChangeCurrentAndOriginal,
|
|
|
- DataRowAction.ChangeCurrentAndOriginal};
|
|
|
- rowActionInit (dra);
|
|
|
- dtLoad.Load (dtr, LoadOption.OverwriteChanges);
|
|
|
- rowActionEnd ();
|
|
|
- // asserting Unchanged Row0
|
|
|
- AssertEquals ("RowData0-C", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData0-O", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[0].RowState);
|
|
|
- // asserting Modified Row1
|
|
|
- AssertEquals ("RowData1-C", "mono 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData1-O", "mono 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState1", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[1].RowState);
|
|
|
- // asserting Deleted Row2
|
|
|
- AssertEquals ("RowData1-C", "mono 3",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData1-O", "mono 3",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState2", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[2].RowState);
|
|
|
- // asserting Added Row3
|
|
|
- AssertEquals ("RowData3-C", "mono 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData3-O", "mono 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState3", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[3].RowState);
|
|
|
- // asserting Unpresent Row4
|
|
|
- AssertEquals ("RowData4-C", "mono 5",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData4-O", "mono 5",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState4", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[4].RowState);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateUpsert () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
- dt.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- DataTable dtLoad = setupRowState ();
|
|
|
- // Notice rowChange-Actions only occur 5 times, as number
|
|
|
- // of actual rows, ignoring row duplication of the deleted row.
|
|
|
- DataRowAction[] dra = new DataRowAction[] {
|
|
|
- DataRowAction.Change,
|
|
|
- DataRowAction.Change,
|
|
|
- DataRowAction.Add,
|
|
|
- DataRowAction.Change,
|
|
|
- DataRowAction.Add};
|
|
|
- rowActionInit (dra);
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- rowActionEnd ();
|
|
|
- // asserting Unchanged Row0
|
|
|
- AssertEquals ("RowData0-C", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData0-O", "RowState 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState0", DataRowState.Modified,
|
|
|
- dtLoad.Rows[0].RowState);
|
|
|
- // asserting Modified Row1
|
|
|
- AssertEquals ("RowData1-C", "mono 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData1-O", "RowState 2",
|
|
|
- dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState1", DataRowState.Modified,
|
|
|
- dtLoad.Rows[1].RowState);
|
|
|
- // asserting Deleted Row2 and "Deleted-Added" Row4
|
|
|
- AssertEquals ("RowData2-O", "RowState 3",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState2", DataRowState.Deleted,
|
|
|
- dtLoad.Rows[2].RowState);
|
|
|
- AssertEquals ("RowData4-C", "mono 3",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowState4", DataRowState.Added,
|
|
|
- dtLoad.Rows[4].RowState);
|
|
|
- // asserting Added Row3
|
|
|
- AssertEquals ("RowData3-C", "mono 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowState3", DataRowState.Added,
|
|
|
- dtLoad.Rows[3].RowState);
|
|
|
- // asserting Unpresent Row5
|
|
|
- // Notice row4 is used for added row of deleted row2 and so
|
|
|
- // unpresent row4 moves to row5
|
|
|
- AssertEquals ("RowData5-C", "mono 5",
|
|
|
- dtLoad.Rows[5][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowState5", DataRowState.Added,
|
|
|
- dtLoad.Rows[5].RowState);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateUpsertDuplicateKey1 () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- dtLoad.Rows[2].Delete ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- dtLoad.Rows[3][1] = "NEWVAL";
|
|
|
- AssertEquals ("A-RowState2", DataRowState.Deleted,
|
|
|
- dtLoad.Rows[2].RowState);
|
|
|
- AssertEquals ("A-RowData2-id", 3,
|
|
|
- dtLoad.Rows[2][0, DataRowVersion.Original]);
|
|
|
- AssertEquals ("A-RowData2-name", "RowState 3",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("A-RowState3", DataRowState.Added,
|
|
|
- dtLoad.Rows[3].RowState);
|
|
|
- AssertEquals ("A-RowData3-id", 3,
|
|
|
- dtLoad.Rows[3][0, DataRowVersion.Current]);
|
|
|
- AssertEquals ("A-RowData3-name", "NEWVAL",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("A-RowState4", DataRowState.Added,
|
|
|
- dtLoad.Rows[4].RowState);
|
|
|
- AssertEquals ("A-RowData4-id", 4,
|
|
|
- dtLoad.Rows[4][0, DataRowVersion.Current]);
|
|
|
- AssertEquals ("A-RowData4-name", "mono 4",
|
|
|
- dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
-
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
-
|
|
|
- AssertEquals ("B-RowState2", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[2].RowState);
|
|
|
- AssertEquals ("B-RowData2-id", 3,
|
|
|
- dtLoad.Rows[2][0, DataRowVersion.Current]);
|
|
|
- AssertEquals ("B-RowData2-name", "NEWVAL",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("B-RowState3", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[3].RowState);
|
|
|
- AssertEquals ("B-RowData3-id", 4,
|
|
|
- dtLoad.Rows[3][0, DataRowVersion.Current]);
|
|
|
- AssertEquals ("B-RowData3-name", "mono 4",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (IndexOutOfRangeException))]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateUpsertDuplicateKey2 () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- dtLoad.Rows[2].Delete ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- AssertEquals ("RowData4", " ", dtLoad.Rows[4][1]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateUpsertDelete1 () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- dtLoad.Rows[2].Delete ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- AssertEquals ("RowData2-C", " ",
|
|
|
- dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
- [Category ("NotWorking")]
|
|
|
- public void Load_RowStateUpsertDelete2 () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- dtLoad.Rows[2].Delete ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- AssertEquals ("RowData3-O", " ",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
- public void Load_RowStateUpsertAdd () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataRow row = dtLoad.NewRow ();
|
|
|
- row["id"] = 4;
|
|
|
- row["name"] = "Add 4";
|
|
|
- dtLoad.Rows.Add (row);
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- AssertEquals ("RowData3-O", " ",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
- public void Load_RowStateUpsertUnpresent () {
|
|
|
- localSetup ();
|
|
|
- dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
- dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
- dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- AssertEquals ("RowData3-O", " ",
|
|
|
- dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void Load_RowStateUpsertUnchangedEqualVal () {
|
|
|
- localSetup ();
|
|
|
- DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
- dtLoad.Columns.Add ("id", typeof (int));
|
|
|
- dtLoad.Columns.Add ("name", typeof (string));
|
|
|
- dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
- dtLoad.Rows.Add (new object[] { 1, "mono 1" });
|
|
|
- dtLoad.AcceptChanges ();
|
|
|
- DataTableReader dtr = dt.CreateDataReader ();
|
|
|
- DataRowAction[] dra = new DataRowAction[] {
|
|
|
- DataRowAction.Nothing,// REAL action
|
|
|
- DataRowAction.Nothing,// dummy
|
|
|
- DataRowAction.Nothing,// dummy
|
|
|
- DataRowAction.Nothing,// dummy
|
|
|
- DataRowAction.Nothing};// dummy
|
|
|
- rowActionInit (dra);
|
|
|
- dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
- rowActionEnd ();
|
|
|
- AssertEquals ("RowData0-C", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
- AssertEquals ("RowData0-O", "mono 1",
|
|
|
- dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
- AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
- dtLoad.Rows[0].RowState);
|
|
|
- }
|
|
|
-
|
|
|
- [Test]
|
|
|
- public void LoadDataRow_LoadOptions () {
|
|
|
- // LoadDataRow is covered in detail (without LoadOptions) in DataTableTest2
|
|
|
- // LoadOption tests are covered in detail in DataTable.Load().
|
|
|
- // Therefore only minimal tests of LoadDataRow with LoadOptions are covered here.
|
|
|
- DataTable dt;
|
|
|
- DataRow dr;
|
|
|
- dt = CreateDataTableExample ();
|
|
|
- dt.PrimaryKey = new DataColumn[] { dt.Columns[0] }; //add ParentId as Primary Key
|
|
|
- dt.Columns["String1"].DefaultValue = "Default";
|
|
|
-
|
|
|
- dr = dt.Select ("ParentId=1")[0];
|
|
|
-
|
|
|
- //Update existing row with LoadOptions = OverwriteChanges
|
|
|
- dt.BeginLoadData ();
|
|
|
- dt.LoadDataRow (new object[] { 1, null, "Changed" },
|
|
|
- LoadOption.OverwriteChanges);
|
|
|
- dt.EndLoadData ();
|
|
|
-
|
|
|
- // LoadDataRow(update1) - check column String2
|
|
|
- AssertEquals ("DT72-C", "Changed",
|
|
|
- dr["String2", DataRowVersion.Current]);
|
|
|
- AssertEquals ("DT72-O", "Changed",
|
|
|
- dr["String2", DataRowVersion.Original]);
|
|
|
-
|
|
|
- // LoadDataRow(update1) - check row state
|
|
|
- AssertEquals ("DT73-LO", DataRowState.Unchanged, dr.RowState);
|
|
|
-
|
|
|
- //Add New row with LoadOptions = Upsert
|
|
|
- dt.BeginLoadData ();
|
|
|
- dt.LoadDataRow (new object[] { 99, null, "Changed" },
|
|
|
- LoadOption.Upsert);
|
|
|
- dt.EndLoadData ();
|
|
|
-
|
|
|
- // LoadDataRow(insert1) - check column String2
|
|
|
- dr = dt.Select ("ParentId=99")[0];
|
|
|
- AssertEquals ("DT75-C", "Changed",
|
|
|
- dr["String2", DataRowVersion.Current]);
|
|
|
-
|
|
|
- // LoadDataRow(insert1) - check row state
|
|
|
- AssertEquals ("DT76-LO", DataRowState.Added, dr.RowState);
|
|
|
- }
|
|
|
-
|
|
|
- public static DataTable CreateDataTableExample () {
|
|
|
- DataTable dtParent = new DataTable ("Parent");
|
|
|
-
|
|
|
- dtParent.Columns.Add ("ParentId", typeof (int));
|
|
|
- dtParent.Columns.Add ("String1", typeof (string));
|
|
|
- dtParent.Columns.Add ("String2", typeof (string));
|
|
|
-
|
|
|
- dtParent.Columns.Add ("ParentDateTime", typeof (DateTime));
|
|
|
- dtParent.Columns.Add ("ParentDouble", typeof (double));
|
|
|
- dtParent.Columns.Add ("ParentBool", typeof (bool));
|
|
|
-
|
|
|
- dtParent.Rows.Add (new object[] { 1, "1-String1", "1-String2", new DateTime (2005, 1, 1, 0, 0, 0, 0), 1.534, true });
|
|
|
- dtParent.Rows.Add (new object[] { 2, "2-String1", "2-String2", new DateTime (2004, 1, 1, 0, 0, 0, 1), -1.534, true });
|
|
|
- dtParent.Rows.Add (new object[] { 3, "3-String1", "3-String2", new DateTime (2003, 1, 1, 0, 0, 1, 0), double.MinValue * 10000, false });
|
|
|
- dtParent.Rows.Add (new object[] { 4, "4-String1", "4-String2", new DateTime (2002, 1, 1, 0, 1, 0, 0), double.MaxValue / 10000, true });
|
|
|
- dtParent.Rows.Add (new object[] { 5, "5-String1", "5-String2", new DateTime (2001, 1, 1, 1, 0, 0, 0), 0.755, true });
|
|
|
- dtParent.Rows.Add (new object[] { 6, "6-String1", "6-String2", new DateTime (2000, 1, 1, 0, 0, 0, 0), 0.001, false });
|
|
|
- dtParent.AcceptChanges ();
|
|
|
- return dtParent;
|
|
|
- }
|
|
|
-
|
|
|
- #endregion // DataTable.CreateDataReader Tests and DataTable.Load Tests
|
|
|
-#endif // NET_2_0
|
|
|
-
|
|
|
+ rowActionChanged = args.Action;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+#if NET_2_0
|
|
|
+ private DataTable dt;
|
|
|
+ private void localSetup () {
|
|
|
+ dt = new DataTable ("test");
|
|
|
+ dt.Columns.Add ("id", typeof (int));
|
|
|
+ dt.Columns.Add ("name", typeof (string));
|
|
|
+ dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
|
|
|
+
|
|
|
+ dt.Rows.Add (new object[] { 1, "mono 1" });
|
|
|
+ dt.Rows.Add (new object[] { 2, "mono 2" });
|
|
|
+ dt.Rows.Add (new object[] { 3, "mono 3" });
|
|
|
+
|
|
|
+ dt.AcceptChanges ();
|
|
|
+ }
|
|
|
+
|
|
|
+ #region DataTable.CreateDataReader Tests
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void CreateDataReader1 () {
|
|
|
+ localSetup ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ Assert ("HasRows", dtr.HasRows);
|
|
|
+ AssertEquals ("CountCols", dt.Columns.Count, dtr.FieldCount);
|
|
|
+ int ri = 0;
|
|
|
+ while (dtr.Read ()) {
|
|
|
+ for (int i = 0; i < dtr.FieldCount; i++) {
|
|
|
+ AssertEquals ("RowData-" + ri + "-" + i, dt.Rows[ri][i],
|
|
|
+ dtr[i]);
|
|
|
+ }
|
|
|
+ ri++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void CreateDataReader2 () {
|
|
|
+ localSetup ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ Assert ("HasRows", dtr.HasRows);
|
|
|
+ AssertEquals ("CountCols", dt.Columns.Count, dtr.FieldCount);
|
|
|
+ dtr.Read ();
|
|
|
+ AssertEquals ("RowData0-0", 1, dtr[0]);
|
|
|
+ AssertEquals ("RowData0-1", "mono 1", dtr[1]);
|
|
|
+ dtr.Read ();
|
|
|
+ AssertEquals ("RowData1-0", 2, dtr[0]);
|
|
|
+ AssertEquals ("RowData1-1", "mono 2", dtr[1]);
|
|
|
+ dtr.Read ();
|
|
|
+ AssertEquals ("RowData2-0", 3, dtr[0]);
|
|
|
+ AssertEquals ("RowData2-1", "mono 3", dtr[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion // DataTable.CreateDataReader Tests
|
|
|
+
|
|
|
+ #region DataTable.Load Tests
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_Basic () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadBasic");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.Columns["id"].ReadOnly = true;
|
|
|
+ dtLoad.Columns["name"].ReadOnly = true;
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "load 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "load 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "load 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
+ AssertEquals ("NRows", 3, dtLoad.Rows.Count);
|
|
|
+ AssertEquals ("RowData0-0", 1, dtLoad.Rows[0][0]);
|
|
|
+ AssertEquals ("RowData0-1", "mono 1", dtLoad.Rows[0][1]);
|
|
|
+ AssertEquals ("RowData1-0", 2, dtLoad.Rows[1][0]);
|
|
|
+ AssertEquals ("RowData1-1", "mono 2", dtLoad.Rows[1][1]);
|
|
|
+ AssertEquals ("RowData2-0", 3, dtLoad.Rows[2][0]);
|
|
|
+ AssertEquals ("RowData2-1", "mono 3", dtLoad.Rows[2][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_NoSchema () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadNoSchema");
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
+ AssertEquals ("NRows", 3, dtLoad.Rows.Count);
|
|
|
+ AssertEquals ("RowData0-0", 1, dtLoad.Rows[0][0]);
|
|
|
+ AssertEquals ("RowData0-1", "mono 1", dtLoad.Rows[0][1]);
|
|
|
+ AssertEquals ("RowData1-0", 2, dtLoad.Rows[1][0]);
|
|
|
+ AssertEquals ("RowData1-1", "mono 2", dtLoad.Rows[1][1]);
|
|
|
+ AssertEquals ("RowData2-0", 3, dtLoad.Rows[2][0]);
|
|
|
+ AssertEquals ("RowData2-1", "mono 3", dtLoad.Rows[2][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ internal struct fillErrorStruct {
|
|
|
+ internal string error;
|
|
|
+ internal string tableName;
|
|
|
+ internal int rowKey;
|
|
|
+ internal bool contFlag;
|
|
|
+ internal void init (string tbl, int row, bool cont, string err) {
|
|
|
+ tableName = tbl;
|
|
|
+ rowKey = row;
|
|
|
+ contFlag = cont;
|
|
|
+ error = err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private fillErrorStruct[] fillErr = new fillErrorStruct[3];
|
|
|
+ private int fillErrCounter;
|
|
|
+ private void fillErrorHandler (object sender, FillErrorEventArgs e) {
|
|
|
+ e.Continue = fillErr[fillErrCounter].contFlag;
|
|
|
+ AssertEquals ("fillErr-T", fillErr[fillErrCounter].tableName, e.DataTable.TableName);
|
|
|
+ AssertEquals ("fillErr-R", fillErr[fillErrCounter].rowKey, e.Values[0]);
|
|
|
+ AssertEquals ("fillErr-C", fillErr[fillErrCounter].contFlag, e.Continue);
|
|
|
+ AssertEquals ("fillErr-E", fillErr[fillErrCounter].error, e.Errors.Message);
|
|
|
+ fillErrCounter++;
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (ArgumentException))]
|
|
|
+ public void Load_Incompatible () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadIncompatible");
|
|
|
+ dtLoad.Columns.Add ("name", typeof (double));
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ }
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ // Load doesn't have a third overload in System.Data
|
|
|
+ // and is commented-out below
|
|
|
+ public void Load_IncompatibleEHandlerT () {
|
|
|
+ fillErrCounter = 0;
|
|
|
+ fillErr[0].init ("LoadIncompatible", 1, true,
|
|
|
+ "Input string was not in a correct format.Couldn't store <mono 1> in name Column. Expected type is Double.");
|
|
|
+ fillErr[1].init ("LoadIncompatible", 2, true,
|
|
|
+ "Input string was not in a correct format.Couldn't store <mono 2> in name Column. Expected type is Double.");
|
|
|
+ fillErr[2].init ("LoadIncompatible", 3, true,
|
|
|
+ "Input string was not in a correct format.Couldn't store <mono 3> in name Column. Expected type is Double.");
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadIncompatible");
|
|
|
+ dtLoad.Columns.Add ("name", typeof (double));
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ //dtLoad.Load (dtr,LoadOption.PreserveChanges,fillErrorHandler);
|
|
|
+ }
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ // Load doesn't have a third overload in System.Data
|
|
|
+ // and is commented-out below
|
|
|
+ [ExpectedException (typeof (ArgumentException))]
|
|
|
+ public void Load_IncompatibleEHandlerF () {
|
|
|
+ fillErrCounter = 0;
|
|
|
+ fillErr[0].init ("LoadIncompatible", 1, false,
|
|
|
+ "Input string was not in a correct format.Couldn't store <mono 1> in name Column. Expected type is Double.");
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadIncompatible");
|
|
|
+ dtLoad.Columns.Add ("name", typeof (double));
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ //dtLoad.Load (dtr, LoadOption.PreserveChanges, fillErrorHandler);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_ExtraColsEqualVal () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadExtraCols");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1 });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2 });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3 });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
+ AssertEquals ("NRows", 3, dtLoad.Rows.Count);
|
|
|
+ AssertEquals ("RowData0-0", 1, dtLoad.Rows[0][0]);
|
|
|
+ AssertEquals ("RowData0-1", "mono 1", dtLoad.Rows[0][1]);
|
|
|
+ AssertEquals ("RowData1-0", 2, dtLoad.Rows[1][0]);
|
|
|
+ AssertEquals ("RowData1-1", "mono 2", dtLoad.Rows[1][1]);
|
|
|
+ AssertEquals ("RowData2-0", 3, dtLoad.Rows[2][0]);
|
|
|
+ AssertEquals ("RowData2-1", "mono 3", dtLoad.Rows[2][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_ExtraColsNonEqualVal () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadExtraCols");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 4 });
|
|
|
+ dtLoad.Rows.Add (new object[] { 5 });
|
|
|
+ dtLoad.Rows.Add (new object[] { 6 });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("NColumns", 2, dtLoad.Columns.Count);
|
|
|
+ AssertEquals ("NRows", 6, dtLoad.Rows.Count);
|
|
|
+ AssertEquals ("RowData0-0", 4, dtLoad.Rows[0][0]);
|
|
|
+ AssertEquals ("RowData1-0", 5, dtLoad.Rows[1][0]);
|
|
|
+ AssertEquals ("RowData2-0", 6, dtLoad.Rows[2][0]);
|
|
|
+ AssertEquals ("RowData3-0", 1, dtLoad.Rows[3][0]);
|
|
|
+ AssertEquals ("RowData3-1", "mono 1", dtLoad.Rows[3][1]);
|
|
|
+ AssertEquals ("RowData4-0", 2, dtLoad.Rows[4][0]);
|
|
|
+ AssertEquals ("RowData4-1", "mono 2", dtLoad.Rows[4][1]);
|
|
|
+ AssertEquals ("RowData5-0", 3, dtLoad.Rows[5][0]);
|
|
|
+ AssertEquals ("RowData5-1", "mono 3", dtLoad.Rows[5][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (ConstraintException))]
|
|
|
+ public void Load_MissingColsNonNullable () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadMissingCols");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.Columns.Add ("missing", typeof (string));
|
|
|
+ dtLoad.Columns["missing"].AllowDBNull = false;
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 4, "mono 4", "miss4" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 5, "mono 5", "miss5" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 6, "mono 6", "miss6" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_MissingColsDefault () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadMissingCols");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.Columns.Add ("missing", typeof (string));
|
|
|
+ dtLoad.Columns["missing"].AllowDBNull = false;
|
|
|
+ dtLoad.Columns["missing"].DefaultValue = "DefaultValue";
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 4, "mono 4", "miss4" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 5, "mono 5", "miss5" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 6, "mono 6", "miss6" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("NColumns", 3, dtLoad.Columns.Count);
|
|
|
+ AssertEquals ("NRows", 6, dtLoad.Rows.Count);
|
|
|
+ AssertEquals ("RowData0-0", 4, dtLoad.Rows[0][0]);
|
|
|
+ AssertEquals ("RowData0-1", "mono 4", dtLoad.Rows[0][1]);
|
|
|
+ AssertEquals ("RowData0-2", "miss4", dtLoad.Rows[0][2]);
|
|
|
+ AssertEquals ("RowData1-0", 5, dtLoad.Rows[1][0]);
|
|
|
+ AssertEquals ("RowData1-1", "mono 5", dtLoad.Rows[1][1]);
|
|
|
+ AssertEquals ("RowData1-2", "miss5", dtLoad.Rows[1][2]);
|
|
|
+ AssertEquals ("RowData2-0", 6, dtLoad.Rows[2][0]);
|
|
|
+ AssertEquals ("RowData2-1", "mono 6", dtLoad.Rows[2][1]);
|
|
|
+ AssertEquals ("RowData2-2", "miss6", dtLoad.Rows[2][2]);
|
|
|
+ AssertEquals ("RowData3-0", 1, dtLoad.Rows[3][0]);
|
|
|
+ AssertEquals ("RowData3-1", "mono 1", dtLoad.Rows[3][1]);
|
|
|
+ AssertEquals ("RowData3-2", "DefaultValue", dtLoad.Rows[3][2]);
|
|
|
+ AssertEquals ("RowData4-0", 2, dtLoad.Rows[4][0]);
|
|
|
+ AssertEquals ("RowData4-1", "mono 2", dtLoad.Rows[4][1]);
|
|
|
+ AssertEquals ("RowData4-2", "DefaultValue", dtLoad.Rows[4][2]);
|
|
|
+ AssertEquals ("RowData5-0", 3, dtLoad.Rows[5][0]);
|
|
|
+ AssertEquals ("RowData5-1", "mono 3", dtLoad.Rows[5][1]);
|
|
|
+ AssertEquals ("RowData5-2", "DefaultValue", dtLoad.Rows[5][2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_MissingColsNullable () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadMissingCols");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.Columns.Add ("missing", typeof (string));
|
|
|
+ dtLoad.Columns["missing"].AllowDBNull = true;
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 4, "mono 4", "miss4" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 5, "mono 5", "miss5" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 6, "mono 6", "miss6" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("NColumns", 3, dtLoad.Columns.Count);
|
|
|
+ AssertEquals ("NRows", 6, dtLoad.Rows.Count);
|
|
|
+ AssertEquals ("RowData0-0", 4, dtLoad.Rows[0][0]);
|
|
|
+ AssertEquals ("RowData0-1", "mono 4", dtLoad.Rows[0][1]);
|
|
|
+ AssertEquals ("RowData0-2", "miss4", dtLoad.Rows[0][2]);
|
|
|
+ AssertEquals ("RowData1-0", 5, dtLoad.Rows[1][0]);
|
|
|
+ AssertEquals ("RowData1-1", "mono 5", dtLoad.Rows[1][1]);
|
|
|
+ AssertEquals ("RowData1-2", "miss5", dtLoad.Rows[1][2]);
|
|
|
+ AssertEquals ("RowData2-0", 6, dtLoad.Rows[2][0]);
|
|
|
+ AssertEquals ("RowData2-1", "mono 6", dtLoad.Rows[2][1]);
|
|
|
+ AssertEquals ("RowData2-2", "miss6", dtLoad.Rows[2][2]);
|
|
|
+ AssertEquals ("RowData3-0", 1, dtLoad.Rows[3][0]);
|
|
|
+ AssertEquals ("RowData3-1", "mono 1", dtLoad.Rows[3][1]);
|
|
|
+ //AssertEquals ("RowData3-2", null, dtLoad.Rows[3][2]);
|
|
|
+ AssertEquals ("RowData4-0", 2, dtLoad.Rows[4][0]);
|
|
|
+ AssertEquals ("RowData4-1", "mono 2", dtLoad.Rows[4][1]);
|
|
|
+ //AssertEquals ("RowData4-2", null, dtLoad.Rows[4][2]);
|
|
|
+ AssertEquals ("RowData5-0", 3, dtLoad.Rows[5][0]);
|
|
|
+ AssertEquals ("RowData5-1", "mono 3", dtLoad.Rows[5][1]);
|
|
|
+ //AssertEquals ("RowData5-2", null, dtLoad.Rows[5][2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ private DataTable setupRowState () {
|
|
|
+ DataTable tbl = new DataTable ("LoadRowStateChanges");
|
|
|
+ tbl.RowChanged += new DataRowChangeEventHandler (dtLoad_RowChanged);
|
|
|
+ tbl.RowChanging += new DataRowChangeEventHandler (dtLoad_RowChanging);
|
|
|
+ tbl.Columns.Add ("id", typeof (int));
|
|
|
+ tbl.Columns.Add ("name", typeof (string));
|
|
|
+ tbl.PrimaryKey = new DataColumn[] { tbl.Columns["id"] };
|
|
|
+ tbl.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ tbl.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ tbl.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ tbl.AcceptChanges ();
|
|
|
+ // Update Table with following changes: Row0 unmodified,
|
|
|
+ // Row1 modified, Row2 deleted, Row3 added, Row4 not-present.
|
|
|
+ tbl.Rows[1]["name"] = "Modify 2";
|
|
|
+ tbl.Rows[2].Delete ();
|
|
|
+ DataRow row = tbl.NewRow ();
|
|
|
+ row["id"] = 4;
|
|
|
+ row["name"] = "Add 4";
|
|
|
+ tbl.Rows.Add (row);
|
|
|
+ return (tbl);
|
|
|
+ }
|
|
|
+
|
|
|
+ private DataRowAction[] rowChangeAction = new DataRowAction[5];
|
|
|
+ private bool checkAction = false;
|
|
|
+ private int rowChagedCounter, rowChangingCounter;
|
|
|
+ private void rowActionInit (DataRowAction[] act) {
|
|
|
+ checkAction = true;
|
|
|
+ rowChagedCounter = 0;
|
|
|
+ rowChangingCounter = 0;
|
|
|
+ for (int i = 0; i < 5; i++)
|
|
|
+ rowChangeAction[i] = act[i];
|
|
|
+ }
|
|
|
+ private void rowActionEnd () {
|
|
|
+ checkAction = false;
|
|
|
+ }
|
|
|
+ private void dtLoad_RowChanged (object sender, DataRowChangeEventArgs e) {
|
|
|
+ if (checkAction) {
|
|
|
+ AssertEquals ("RowChanged" + rowChagedCounter,
|
|
|
+ rowChangeAction[rowChagedCounter], e.Action);
|
|
|
+ rowChagedCounter++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void dtLoad_RowChanging (object sender, DataRowChangeEventArgs e) {
|
|
|
+ if (checkAction) {
|
|
|
+ AssertEquals ("RowChanging" + rowChangingCounter,
|
|
|
+ rowChangeAction[rowChangingCounter], e.Action);
|
|
|
+ rowChangingCounter++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateChangesDefault () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
+ dt.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ DataTable dtLoad = setupRowState ();
|
|
|
+ DataRowAction[] dra = new DataRowAction[] {
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal,
|
|
|
+ DataRowAction.ChangeOriginal,
|
|
|
+ DataRowAction.ChangeOriginal,
|
|
|
+ DataRowAction.ChangeOriginal,
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal};
|
|
|
+ rowActionInit (dra);
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ rowActionEnd ();
|
|
|
+ // asserting Unchanged Row0
|
|
|
+ AssertEquals ("RowData0-C", "mono 1",
|
|
|
+ dtLoad.Rows[0][1,DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData0-O", "mono 1",
|
|
|
+ dtLoad.Rows[0][1,DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[0].RowState);
|
|
|
+ // asserting Modified Row1
|
|
|
+ AssertEquals ("RowData1-C", "Modify 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData1-O", "mono 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState1", DataRowState.Modified,
|
|
|
+ dtLoad.Rows[1].RowState);
|
|
|
+ // asserting Deleted Row2
|
|
|
+ AssertEquals ("RowData1-O", "mono 3",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState2", DataRowState.Deleted,
|
|
|
+ dtLoad.Rows[2].RowState);
|
|
|
+ // asserting Added Row3
|
|
|
+ AssertEquals ("RowData3-C", "Add 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData3-O", "mono 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState3", DataRowState.Modified,
|
|
|
+ dtLoad.Rows[3].RowState);
|
|
|
+ // asserting Unpresent Row4
|
|
|
+ AssertEquals ("RowData4-C", "mono 5",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData4-O", "mono 5",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState4", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[4].RowState);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateChangesDefaultDelete () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ dtLoad.Rows[2].Delete ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr);
|
|
|
+ AssertEquals ("RowData2-C", " ",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStatePreserveChanges () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
+ dt.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ DataTable dtLoad = setupRowState ();
|
|
|
+ DataRowAction[] dra = new DataRowAction[] {
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal,
|
|
|
+ DataRowAction.ChangeOriginal,
|
|
|
+ DataRowAction.ChangeOriginal,
|
|
|
+ DataRowAction.ChangeOriginal,
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal};
|
|
|
+ rowActionInit (dra);
|
|
|
+ dtLoad.Load (dtr, LoadOption.PreserveChanges);
|
|
|
+ rowActionEnd ();
|
|
|
+ // asserting Unchanged Row0
|
|
|
+ AssertEquals ("RowData0-C", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData0-O", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[0].RowState);
|
|
|
+ // asserting Modified Row1
|
|
|
+ AssertEquals ("RowData1-C", "Modify 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData1-O", "mono 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState1", DataRowState.Modified,
|
|
|
+ dtLoad.Rows[1].RowState);
|
|
|
+ // asserting Deleted Row2
|
|
|
+ AssertEquals ("RowData1-O", "mono 3",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState2", DataRowState.Deleted,
|
|
|
+ dtLoad.Rows[2].RowState);
|
|
|
+ // asserting Added Row3
|
|
|
+ AssertEquals ("RowData3-C", "Add 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData3-O", "mono 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState3", DataRowState.Modified,
|
|
|
+ dtLoad.Rows[3].RowState);
|
|
|
+ // asserting Unpresent Row4
|
|
|
+ AssertEquals ("RowData4-C", "mono 5",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData4-O", "mono 5",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState4", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[4].RowState);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStatePreserveChangesDelete () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ dtLoad.Rows[2].Delete ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr,LoadOption.PreserveChanges);
|
|
|
+ AssertEquals ("RowData2-C", " ",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateOverwriteChanges () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
+ dt.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ DataTable dtLoad = setupRowState ();
|
|
|
+ DataRowAction[] dra = new DataRowAction[] {
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal,
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal,
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal,
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal,
|
|
|
+ DataRowAction.ChangeCurrentAndOriginal};
|
|
|
+ rowActionInit (dra);
|
|
|
+ dtLoad.Load (dtr, LoadOption.OverwriteChanges);
|
|
|
+ rowActionEnd ();
|
|
|
+ // asserting Unchanged Row0
|
|
|
+ AssertEquals ("RowData0-C", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData0-O", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[0].RowState);
|
|
|
+ // asserting Modified Row1
|
|
|
+ AssertEquals ("RowData1-C", "mono 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData1-O", "mono 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState1", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[1].RowState);
|
|
|
+ // asserting Deleted Row2
|
|
|
+ AssertEquals ("RowData1-C", "mono 3",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData1-O", "mono 3",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState2", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[2].RowState);
|
|
|
+ // asserting Added Row3
|
|
|
+ AssertEquals ("RowData3-C", "mono 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData3-O", "mono 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState3", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[3].RowState);
|
|
|
+ // asserting Unpresent Row4
|
|
|
+ AssertEquals ("RowData4-C", "mono 5",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData4-O", "mono 5",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState4", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[4].RowState);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateUpsert () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ dt.Rows.Add (new object[] { 5, "mono 5" });
|
|
|
+ dt.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ DataTable dtLoad = setupRowState ();
|
|
|
+ // Notice rowChange-Actions only occur 5 times, as number
|
|
|
+ // of actual rows, ignoring row duplication of the deleted row.
|
|
|
+ DataRowAction[] dra = new DataRowAction[] {
|
|
|
+ DataRowAction.Change,
|
|
|
+ DataRowAction.Change,
|
|
|
+ DataRowAction.Add,
|
|
|
+ DataRowAction.Change,
|
|
|
+ DataRowAction.Add};
|
|
|
+ rowActionInit (dra);
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ rowActionEnd ();
|
|
|
+ // asserting Unchanged Row0
|
|
|
+ AssertEquals ("RowData0-C", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData0-O", "RowState 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState0", DataRowState.Modified,
|
|
|
+ dtLoad.Rows[0].RowState);
|
|
|
+ // asserting Modified Row1
|
|
|
+ AssertEquals ("RowData1-C", "mono 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData1-O", "RowState 2",
|
|
|
+ dtLoad.Rows[1][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState1", DataRowState.Modified,
|
|
|
+ dtLoad.Rows[1].RowState);
|
|
|
+ // asserting Deleted Row2 and "Deleted-Added" Row4
|
|
|
+ AssertEquals ("RowData2-O", "RowState 3",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState2", DataRowState.Deleted,
|
|
|
+ dtLoad.Rows[2].RowState);
|
|
|
+ AssertEquals ("RowData4-C", "mono 3",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowState4", DataRowState.Added,
|
|
|
+ dtLoad.Rows[4].RowState);
|
|
|
+ // asserting Added Row3
|
|
|
+ AssertEquals ("RowData3-C", "mono 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowState3", DataRowState.Added,
|
|
|
+ dtLoad.Rows[3].RowState);
|
|
|
+ // asserting Unpresent Row5
|
|
|
+ // Notice row4 is used for added row of deleted row2 and so
|
|
|
+ // unpresent row4 moves to row5
|
|
|
+ AssertEquals ("RowData5-C", "mono 5",
|
|
|
+ dtLoad.Rows[5][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowState5", DataRowState.Added,
|
|
|
+ dtLoad.Rows[5].RowState);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateUpsertDuplicateKey1 () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ dtLoad.Rows[2].Delete ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ dtLoad.Rows[3][1] = "NEWVAL";
|
|
|
+ AssertEquals ("A-RowState2", DataRowState.Deleted,
|
|
|
+ dtLoad.Rows[2].RowState);
|
|
|
+ AssertEquals ("A-RowData2-id", 3,
|
|
|
+ dtLoad.Rows[2][0, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("A-RowData2-name", "RowState 3",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("A-RowState3", DataRowState.Added,
|
|
|
+ dtLoad.Rows[3].RowState);
|
|
|
+ AssertEquals ("A-RowData3-id", 3,
|
|
|
+ dtLoad.Rows[3][0, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("A-RowData3-name", "NEWVAL",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("A-RowState4", DataRowState.Added,
|
|
|
+ dtLoad.Rows[4].RowState);
|
|
|
+ AssertEquals ("A-RowData4-id", 4,
|
|
|
+ dtLoad.Rows[4][0, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("A-RowData4-name", "mono 4",
|
|
|
+ dtLoad.Rows[4][1, DataRowVersion.Current]);
|
|
|
+
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+
|
|
|
+ AssertEquals ("B-RowState2", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[2].RowState);
|
|
|
+ AssertEquals ("B-RowData2-id", 3,
|
|
|
+ dtLoad.Rows[2][0, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("B-RowData2-name", "NEWVAL",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("B-RowState3", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[3].RowState);
|
|
|
+ AssertEquals ("B-RowData3-id", 4,
|
|
|
+ dtLoad.Rows[3][0, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("B-RowData3-name", "mono 4",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Current]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (IndexOutOfRangeException))]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateUpsertDuplicateKey2 () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ dtLoad.Rows[2].Delete ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ AssertEquals ("RowData4", " ", dtLoad.Rows[4][1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateUpsertDelete1 () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ dtLoad.Rows[2].Delete ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ AssertEquals ("RowData2-C", " ",
|
|
|
+ dtLoad.Rows[2][1, DataRowVersion.Current]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void Load_RowStateUpsertDelete2 () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ dtLoad.Rows[2].Delete ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ AssertEquals ("RowData3-O", " ",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
+ public void Load_RowStateUpsertAdd () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataRow row = dtLoad.NewRow ();
|
|
|
+ row["id"] = 4;
|
|
|
+ row["name"] = "Add 4";
|
|
|
+ dtLoad.Rows.Add (row);
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ AssertEquals ("RowData3-O", " ",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (VersionNotFoundException))]
|
|
|
+ public void Load_RowStateUpsertUnpresent () {
|
|
|
+ localSetup ();
|
|
|
+ dt.Rows.Add (new object[] { 4, "mono 4" });
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "RowState 1" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 2, "RowState 2" });
|
|
|
+ dtLoad.Rows.Add (new object[] { 3, "RowState 3" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ AssertEquals ("RowData3-O", " ",
|
|
|
+ dtLoad.Rows[3][1, DataRowVersion.Original]);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void Load_RowStateUpsertUnchangedEqualVal () {
|
|
|
+ localSetup ();
|
|
|
+ DataTable dtLoad = new DataTable ("LoadRowStateChanges");
|
|
|
+ dtLoad.Columns.Add ("id", typeof (int));
|
|
|
+ dtLoad.Columns.Add ("name", typeof (string));
|
|
|
+ dtLoad.PrimaryKey = new DataColumn[] { dtLoad.Columns["id"] };
|
|
|
+ dtLoad.Rows.Add (new object[] { 1, "mono 1" });
|
|
|
+ dtLoad.AcceptChanges ();
|
|
|
+ DataTableReader dtr = dt.CreateDataReader ();
|
|
|
+ DataRowAction[] dra = new DataRowAction[] {
|
|
|
+ DataRowAction.Nothing,// REAL action
|
|
|
+ DataRowAction.Nothing,// dummy
|
|
|
+ DataRowAction.Nothing,// dummy
|
|
|
+ DataRowAction.Nothing,// dummy
|
|
|
+ DataRowAction.Nothing};// dummy
|
|
|
+ rowActionInit (dra);
|
|
|
+ dtLoad.Load (dtr, LoadOption.Upsert);
|
|
|
+ rowActionEnd ();
|
|
|
+ AssertEquals ("RowData0-C", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Current]);
|
|
|
+ AssertEquals ("RowData0-O", "mono 1",
|
|
|
+ dtLoad.Rows[0][1, DataRowVersion.Original]);
|
|
|
+ AssertEquals ("RowState0", DataRowState.Unchanged,
|
|
|
+ dtLoad.Rows[0].RowState);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void LoadDataRow_LoadOptions () {
|
|
|
+ // LoadDataRow is covered in detail (without LoadOptions) in DataTableTest2
|
|
|
+ // LoadOption tests are covered in detail in DataTable.Load().
|
|
|
+ // Therefore only minimal tests of LoadDataRow with LoadOptions are covered here.
|
|
|
+ DataTable dt;
|
|
|
+ DataRow dr;
|
|
|
+ dt = CreateDataTableExample ();
|
|
|
+ dt.PrimaryKey = new DataColumn[] { dt.Columns[0] }; //add ParentId as Primary Key
|
|
|
+ dt.Columns["String1"].DefaultValue = "Default";
|
|
|
+
|
|
|
+ dr = dt.Select ("ParentId=1")[0];
|
|
|
+
|
|
|
+ //Update existing row with LoadOptions = OverwriteChanges
|
|
|
+ dt.BeginLoadData ();
|
|
|
+ dt.LoadDataRow (new object[] { 1, null, "Changed" },
|
|
|
+ LoadOption.OverwriteChanges);
|
|
|
+ dt.EndLoadData ();
|
|
|
+
|
|
|
+ // LoadDataRow(update1) - check column String2
|
|
|
+ AssertEquals ("DT72-C", "Changed",
|
|
|
+ dr["String2", DataRowVersion.Current]);
|
|
|
+ AssertEquals ("DT72-O", "Changed",
|
|
|
+ dr["String2", DataRowVersion.Original]);
|
|
|
+
|
|
|
+ // LoadDataRow(update1) - check row state
|
|
|
+ AssertEquals ("DT73-LO", DataRowState.Unchanged, dr.RowState);
|
|
|
+
|
|
|
+ //Add New row with LoadOptions = Upsert
|
|
|
+ dt.BeginLoadData ();
|
|
|
+ dt.LoadDataRow (new object[] { 99, null, "Changed" },
|
|
|
+ LoadOption.Upsert);
|
|
|
+ dt.EndLoadData ();
|
|
|
+
|
|
|
+ // LoadDataRow(insert1) - check column String2
|
|
|
+ dr = dt.Select ("ParentId=99")[0];
|
|
|
+ AssertEquals ("DT75-C", "Changed",
|
|
|
+ dr["String2", DataRowVersion.Current]);
|
|
|
+
|
|
|
+ // LoadDataRow(insert1) - check row state
|
|
|
+ AssertEquals ("DT76-LO", DataRowState.Added, dr.RowState);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DataTable CreateDataTableExample () {
|
|
|
+ DataTable dtParent = new DataTable ("Parent");
|
|
|
+
|
|
|
+ dtParent.Columns.Add ("ParentId", typeof (int));
|
|
|
+ dtParent.Columns.Add ("String1", typeof (string));
|
|
|
+ dtParent.Columns.Add ("String2", typeof (string));
|
|
|
+
|
|
|
+ dtParent.Columns.Add ("ParentDateTime", typeof (DateTime));
|
|
|
+ dtParent.Columns.Add ("ParentDouble", typeof (double));
|
|
|
+ dtParent.Columns.Add ("ParentBool", typeof (bool));
|
|
|
+
|
|
|
+ dtParent.Rows.Add (new object[] { 1, "1-String1", "1-String2", new DateTime (2005, 1, 1, 0, 0, 0, 0), 1.534, true });
|
|
|
+ dtParent.Rows.Add (new object[] { 2, "2-String1", "2-String2", new DateTime (2004, 1, 1, 0, 0, 0, 1), -1.534, true });
|
|
|
+ dtParent.Rows.Add (new object[] { 3, "3-String1", "3-String2", new DateTime (2003, 1, 1, 0, 0, 1, 0), double.MinValue * 10000, false });
|
|
|
+ dtParent.Rows.Add (new object[] { 4, "4-String1", "4-String2", new DateTime (2002, 1, 1, 0, 1, 0, 0), double.MaxValue / 10000, true });
|
|
|
+ dtParent.Rows.Add (new object[] { 5, "5-String1", "5-String2", new DateTime (2001, 1, 1, 1, 0, 0, 0), 0.755, true });
|
|
|
+ dtParent.Rows.Add (new object[] { 6, "6-String1", "6-String2", new DateTime (2000, 1, 1, 0, 0, 0, 0), 0.001, false });
|
|
|
+ dtParent.AcceptChanges ();
|
|
|
+ return dtParent;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion // DataTable.Load Tests
|
|
|
+
|
|
|
+ #region Read/Write XML Tests
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void ReadXmlSchema () {
|
|
|
+ DataTable Table = new DataTable ();
|
|
|
+ Table.ReadXmlSchema ("Test/System.Data/own_schema1.xsd");
|
|
|
+
|
|
|
+ AssertEquals ("test#02", "test_table", Table.TableName);
|
|
|
+ AssertEquals ("test#03", "", Table.Namespace);
|
|
|
+ AssertEquals ("test#04", 2, Table.Columns.Count);
|
|
|
+ AssertEquals ("test#05", 0, Table.Rows.Count);
|
|
|
+ AssertEquals ("test#06", false, Table.CaseSensitive);
|
|
|
+ AssertEquals ("test#07", 1, Table.Constraints.Count);
|
|
|
+ AssertEquals ("test#08", "", Table.Prefix);
|
|
|
+
|
|
|
+ Constraint cons = Table.Constraints[0];
|
|
|
+ AssertEquals ("test#09", "Constraint1", cons.ConstraintName.ToString ());
|
|
|
+ AssertEquals ("test#10", "Constraint1", cons.ToString ());
|
|
|
+
|
|
|
+ DataColumn column = Table.Columns[0];
|
|
|
+ AssertEquals ("test#11", true, column.AllowDBNull);
|
|
|
+ AssertEquals ("test#12", false, column.AutoIncrement);
|
|
|
+ AssertEquals ("test#13", 0L, column.AutoIncrementSeed);
|
|
|
+ AssertEquals ("test#14", 1L, column.AutoIncrementStep);
|
|
|
+ AssertEquals ("test#15", "test", column.Caption);
|
|
|
+ AssertEquals ("test#16", "Element", column.ColumnMapping.ToString ());
|
|
|
+ AssertEquals ("test#17", "first", column.ColumnName);
|
|
|
+ AssertEquals ("test#18", "System.String", column.DataType.ToString ());
|
|
|
+ AssertEquals ("test#19", "test_default_value", column.DefaultValue.ToString ());
|
|
|
+ AssertEquals ("test#20", false, column.DesignMode);
|
|
|
+ AssertEquals ("test#21", "", column.Expression);
|
|
|
+ AssertEquals ("test#22", 100, column.MaxLength);
|
|
|
+ AssertEquals ("test#23", "", column.Namespace);
|
|
|
+ AssertEquals ("test#24", 0, column.Ordinal);
|
|
|
+ AssertEquals ("test#25", "", column.Prefix);
|
|
|
+ AssertEquals ("test#26", false, column.ReadOnly);
|
|
|
+ AssertEquals ("test#27", true, column.Unique);
|
|
|
+
|
|
|
+ DataColumn column2 = Table.Columns[1];
|
|
|
+ AssertEquals ("test#28", true, column2.AllowDBNull);
|
|
|
+ AssertEquals ("test#29", false, column2.AutoIncrement);
|
|
|
+ AssertEquals ("test#30", 0L, column2.AutoIncrementSeed);
|
|
|
+ AssertEquals ("test#31", 1L, column2.AutoIncrementStep);
|
|
|
+ AssertEquals ("test#32", "second", column2.Caption);
|
|
|
+ AssertEquals ("test#33", "Element", column2.ColumnMapping.ToString ());
|
|
|
+ AssertEquals ("test#34", "second", column2.ColumnName);
|
|
|
+ AssertEquals ("test#35", "System.Data.SqlTypes.SqlGuid", column2.DataType.ToString ());
|
|
|
+ AssertEquals ("test#36", "Null", column2.DefaultValue.ToString ());
|
|
|
+ AssertEquals ("test#37", false, column2.DesignMode);
|
|
|
+ AssertEquals ("test#38", "", column2.Expression);
|
|
|
+ AssertEquals ("test#39", -1, column2.MaxLength);
|
|
|
+ AssertEquals ("test#40", "", column2.Namespace);
|
|
|
+ AssertEquals ("test#41", 1, column2.Ordinal);
|
|
|
+ AssertEquals ("test#42", "", column2.Prefix);
|
|
|
+ AssertEquals ("test#43", false, column2.ReadOnly);
|
|
|
+ AssertEquals ("test#44", false, column2.Unique);
|
|
|
+
|
|
|
+ DataTable Table2 = new DataTable ();
|
|
|
+ Table2.ReadXmlSchema ("Test/System.Data/own_schema2.xsd");
|
|
|
+
|
|
|
+ AssertEquals ("test#45", "second_test_table", Table2.TableName);
|
|
|
+ AssertEquals ("test#46", "", Table2.Namespace);
|
|
|
+ AssertEquals ("test#47", 1, Table2.Columns.Count);
|
|
|
+ AssertEquals ("test#48", 0, Table2.Rows.Count);
|
|
|
+ AssertEquals ("test#49", false, Table2.CaseSensitive);
|
|
|
+ AssertEquals ("test#50", 1, Table2.Constraints.Count);
|
|
|
+ AssertEquals ("test#51", "", Table2.Prefix);
|
|
|
+
|
|
|
+ DataColumn column3 = Table2.Columns[0];
|
|
|
+ AssertEquals ("test#52", true, column3.AllowDBNull);
|
|
|
+ AssertEquals ("test#53", false, column3.AutoIncrement);
|
|
|
+ AssertEquals ("test#54", 0L, column3.AutoIncrementSeed);
|
|
|
+ AssertEquals ("test#55", 1L, column3.AutoIncrementStep);
|
|
|
+ AssertEquals ("test#56", "second_first", column3.Caption);
|
|
|
+ AssertEquals ("test#57", "Element", column3.ColumnMapping.ToString ());
|
|
|
+ AssertEquals ("test#58", "second_first", column3.ColumnName);
|
|
|
+ AssertEquals ("test#59", "System.String", column3.DataType.ToString ());
|
|
|
+ AssertEquals ("test#60", "default_value", column3.DefaultValue.ToString ());
|
|
|
+ AssertEquals ("test#61", false, column3.DesignMode);
|
|
|
+ AssertEquals ("test#62", "", column3.Expression);
|
|
|
+ AssertEquals ("test#63", 100, column3.MaxLength);
|
|
|
+ AssertEquals ("test#64", "", column3.Namespace);
|
|
|
+ AssertEquals ("test#65", 0, column3.Ordinal);
|
|
|
+ AssertEquals ("test#66", "", column3.Prefix);
|
|
|
+ AssertEquals ("test#67", false, column3.ReadOnly);
|
|
|
+ AssertEquals ("test#68", true, column3.Unique);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void ReadXmlSchema_2 () {
|
|
|
+ DataTable dt = new DataTable ();
|
|
|
+ string xmlData = string.Empty;
|
|
|
+ xmlData += "<?xml version=\"1.0\"?>";
|
|
|
+ xmlData += "<xs:schema id=\"SiteConfiguration\" targetNamespace=\"http://tempuri.org/PortalCfg.xsd\" xmlns:mstns=\"http://tempuri.org/PortalCfg.xsd\" xmlns=\"http://tempuri.org/PortalCfg.xsd\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" attributeFormDefault=\"qualified\" elementFormDefault=\"qualified\">";
|
|
|
+ xmlData += "<xs:element name=\"SiteConfiguration\" msdata:IsDataSet=\"true\" msdata:EnforceConstraints=\"False\">";
|
|
|
+ xmlData += "<xs:complexType>";
|
|
|
+ xmlData += "<xs:choice maxOccurs=\"unbounded\">";
|
|
|
+ xmlData += "<xs:element name=\"Tab\">";
|
|
|
+ xmlData += "<xs:complexType>";
|
|
|
+ xmlData += "<xs:sequence>";
|
|
|
+ xmlData += "<xs:element name=\"Module\" minOccurs=\"0\" maxOccurs=\"unbounded\">";
|
|
|
+ xmlData += "<xs:complexType>";
|
|
|
+ xmlData += "<xs:attribute name=\"ModuleId\" form=\"unqualified\" type=\"xs:int\" />";
|
|
|
+ xmlData += "</xs:complexType>";
|
|
|
+ xmlData += "</xs:element>";
|
|
|
+ xmlData += "</xs:sequence>";
|
|
|
+ xmlData += "<xs:attribute name=\"TabId\" form=\"unqualified\" type=\"xs:int\" />";
|
|
|
+ xmlData += "</xs:complexType>";
|
|
|
+ xmlData += "</xs:element>";
|
|
|
+ xmlData += "</xs:choice>";
|
|
|
+ xmlData += "</xs:complexType>";
|
|
|
+ xmlData += "<xs:key name=\"TabKey\" msdata:PrimaryKey=\"true\">";
|
|
|
+ xmlData += "<xs:selector xpath=\".//mstns:Tab\" />";
|
|
|
+ xmlData += "<xs:field xpath=\"@TabId\" />";
|
|
|
+ xmlData += "</xs:key>";
|
|
|
+ xmlData += "<xs:key name=\"ModuleKey\" msdata:PrimaryKey=\"true\">";
|
|
|
+ xmlData += "<xs:selector xpath=\".//mstns:Module\" />";
|
|
|
+ xmlData += "<xs:field xpath=\"@ModuleID\" />";
|
|
|
+ xmlData += "</xs:key>";
|
|
|
+ xmlData += "</xs:element>";
|
|
|
+ xmlData += "</xs:schema>";
|
|
|
+ dt.ReadXmlSchema (new StringReader (xmlData));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void ReadXmlSchema_ByStream () {
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+ ds1.Tables.Add (DataProvider.CreateParentDataTable ());
|
|
|
+ ds1.Tables.Add (DataProvider.CreateChildDataTable ());
|
|
|
+
|
|
|
+ MemoryStream ms1 = new MemoryStream ();
|
|
|
+ MemoryStream ms2 = new MemoryStream ();
|
|
|
+ //write xml schema only
|
|
|
+ //ds1.WriteXmlSchema (ms);
|
|
|
+ ds1.Tables[0].WriteXmlSchema (ms1);
|
|
|
+ ds1.Tables[1].WriteXmlSchema (ms2);
|
|
|
+
|
|
|
+ MemoryStream ms11 = new MemoryStream (ms1.GetBuffer ());
|
|
|
+ MemoryStream ms22 = new MemoryStream (ms2.GetBuffer ());
|
|
|
+ //copy schema
|
|
|
+ //DataSet ds2 = new DataSet ();
|
|
|
+ DataTable dt1 = new DataTable ();
|
|
|
+ DataTable dt2 = new DataTable ();
|
|
|
+
|
|
|
+ //ds2.ReadXmlSchema (ms1);
|
|
|
+ dt1.ReadXmlSchema (ms11);
|
|
|
+ dt2.ReadXmlSchema (ms22);
|
|
|
+
|
|
|
+ //check xml schema
|
|
|
+ // ReadXmlSchema - Tables count
|
|
|
+ //Assert.AreEqual (ds2.Tables.Count, ds1.Tables.Count, "DS269");
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 0 Col count
|
|
|
+ AssertEquals ("DS270", ds1.Tables[0].Columns.Count, dt1.Columns.Count);
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 1 Col count
|
|
|
+ AssertEquals ("DS271", ds1.Tables[1].Columns.Count, dt2.Columns.Count);
|
|
|
+
|
|
|
+ //check some colummns types
|
|
|
+ // ReadXmlSchema - Tables 0 Col type
|
|
|
+ AssertEquals ("DS272", ds1.Tables[0].Columns[0].GetType (), dt1.Columns[0].GetType ());
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 1 Col type
|
|
|
+ AssertEquals ("DS273", ds1.Tables[1].Columns[3].GetType (), dt2.Columns[3].GetType ());
|
|
|
+
|
|
|
+ //check that no data exists
|
|
|
+ // ReadXmlSchema - Table 1 row count
|
|
|
+ AssertEquals ("DS274",0, dt1.Rows.Count);
|
|
|
+
|
|
|
+ // ReadXmlSchema - Table 2 row count
|
|
|
+ AssertEquals ("DS275",0, dt2.Rows.Count);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void ReadWriteXmlSchema_ByFileName () {
|
|
|
+ string sTempFileName1 = "tmpDataSet_ReadWriteXml_43899-1.xml";
|
|
|
+ string sTempFileName2 = "tmpDataSet_ReadWriteXml_43899-2.xml";
|
|
|
+
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+ ds1.Tables.Add (DataProvider.CreateParentDataTable ());
|
|
|
+ ds1.Tables.Add (DataProvider.CreateChildDataTable ());
|
|
|
+
|
|
|
+ ds1.Tables[0].WriteXmlSchema (sTempFileName1);
|
|
|
+ ds1.Tables[1].WriteXmlSchema (sTempFileName2);
|
|
|
+
|
|
|
+ DataTable dt1 = new DataTable ();
|
|
|
+ DataTable dt2 = new DataTable ();
|
|
|
+
|
|
|
+ dt1.ReadXmlSchema (sTempFileName1);
|
|
|
+ dt2.ReadXmlSchema (sTempFileName2);
|
|
|
+
|
|
|
+ AssertEquals ("DS277", ds1.Tables[0].Columns.Count, dt1.Columns.Count);
|
|
|
+ AssertEquals ("DS278", ds1.Tables[1].Columns.Count, dt2.Columns.Count);
|
|
|
+ AssertEquals ("DS279", ds1.Tables[0].Columns[0].GetType (), dt1.Columns[0].GetType ());
|
|
|
+ AssertEquals ("DS280", ds1.Tables[1].Columns[3].GetType (), dt2.Columns[3].GetType ());
|
|
|
+ AssertEquals ("DS281", 0, dt1.Rows.Count);
|
|
|
+ AssertEquals ("DS282", 0, dt2.Rows.Count);
|
|
|
+
|
|
|
+ File.Delete (sTempFileName1);
|
|
|
+ File.Delete (sTempFileName2);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void ReadXmlSchema_ByTextReader () {
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+ ds1.Tables.Add (DataProvider.CreateParentDataTable ());
|
|
|
+ ds1.Tables.Add (DataProvider.CreateChildDataTable ());
|
|
|
+
|
|
|
+ StringWriter sw1 = new StringWriter ();
|
|
|
+ StringWriter sw2 = new StringWriter ();
|
|
|
+ //write xml file, schema only
|
|
|
+ //ds1.WriteXmlSchema (sw);
|
|
|
+ ds1.Tables[0].WriteXmlSchema (sw1);
|
|
|
+ ds1.Tables[1].WriteXmlSchema (sw2);
|
|
|
+
|
|
|
+ StringReader sr1 = new StringReader (sw1.GetStringBuilder ().ToString ());
|
|
|
+ StringReader sr2 = new StringReader (sw2.GetStringBuilder ().ToString ());
|
|
|
+ //copy both data and schema
|
|
|
+ //DataSet ds2 = new DataSet ();
|
|
|
+ DataTable dt1 = new DataTable ();
|
|
|
+ DataTable dt2 = new DataTable ();
|
|
|
+
|
|
|
+ //ds2.ReadXmlSchema (sr);
|
|
|
+ dt1.ReadXmlSchema (sr1);
|
|
|
+ dt2.ReadXmlSchema (sr2);
|
|
|
+
|
|
|
+ //check xml schema
|
|
|
+ // ReadXmlSchema - Tables count
|
|
|
+ //Assert.AreEqual (ds2.Tables.Count, ds1.Tables.Count, "DS283");
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 0 Col count
|
|
|
+ AssertEquals ("DS284", ds1.Tables[0].Columns.Count, dt1.Columns.Count);
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 1 Col count
|
|
|
+ AssertEquals ("DS285", ds1.Tables[1].Columns.Count, dt2.Columns.Count);
|
|
|
+
|
|
|
+ //check some colummns types
|
|
|
+ // ReadXmlSchema - Tables 0 Col type
|
|
|
+ AssertEquals ("DS286", ds1.Tables[0].Columns[0].GetType (), dt1.Columns[0].GetType ());
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 1 Col type
|
|
|
+ AssertEquals ("DS287", ds1.Tables[1].Columns[3].GetType (), dt2.Columns[3].GetType ());
|
|
|
+
|
|
|
+ //check that no data exists
|
|
|
+ // ReadXmlSchema - Table 1 row count
|
|
|
+ AssertEquals ("DS288", 0, dt1.Rows.Count);
|
|
|
+
|
|
|
+ // ReadXmlSchema - Table 2 row count
|
|
|
+ AssertEquals ("DS289", 0, dt2.Rows.Count);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void ReadXmlSchema_ByXmlReader () {
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+ ds1.Tables.Add (DataProvider.CreateParentDataTable ());
|
|
|
+ ds1.Tables.Add (DataProvider.CreateChildDataTable ());
|
|
|
+
|
|
|
+ StringWriter sw1 = new StringWriter ();
|
|
|
+ XmlTextWriter xmlTW1 = new XmlTextWriter (sw1);
|
|
|
+ StringWriter sw2 = new StringWriter ();
|
|
|
+ XmlTextWriter xmlTW2 = new XmlTextWriter (sw2);
|
|
|
+
|
|
|
+ //write xml file, schema only
|
|
|
+ ds1.Tables[0].WriteXmlSchema (xmlTW1);
|
|
|
+ xmlTW1.Flush ();
|
|
|
+ ds1.Tables[1].WriteXmlSchema (xmlTW2);
|
|
|
+ xmlTW2.Flush ();
|
|
|
+
|
|
|
+ StringReader sr1 = new StringReader (sw1.ToString ());
|
|
|
+ XmlTextReader xmlTR1 = new XmlTextReader (sr1);
|
|
|
+ StringReader sr2 = new StringReader (sw2.ToString ());
|
|
|
+ XmlTextReader xmlTR2 = new XmlTextReader (sr2);
|
|
|
+
|
|
|
+ //copy both data and schema
|
|
|
+ //DataSet ds2 = new DataSet ();
|
|
|
+ DataTable dt1 = new DataTable ();
|
|
|
+ DataTable dt2 = new DataTable ();
|
|
|
+
|
|
|
+ //ds2.ReadXmlSchema (xmlTR);
|
|
|
+ dt1.ReadXmlSchema (xmlTR1);
|
|
|
+ dt2.ReadXmlSchema (xmlTR2);
|
|
|
+
|
|
|
+ //check xml schema
|
|
|
+ // ReadXmlSchema - Tables count
|
|
|
+ //Assert.AreEqual (ds2.Tables.Count, ds1.Tables.Count, "DS290");
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 0 Col count
|
|
|
+ AssertEquals ("DS291", ds1.Tables[0].Columns.Count, dt1.Columns.Count);
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 1 Col count
|
|
|
+ AssertEquals ("DS292", ds1.Tables[1].Columns.Count, dt2.Columns.Count);
|
|
|
+
|
|
|
+ //check some colummns types
|
|
|
+ // ReadXmlSchema - Tables 0 Col type
|
|
|
+ AssertEquals ("DS293", ds1.Tables[0].Columns[0].GetType (), dt1.Columns[0].GetType ());
|
|
|
+
|
|
|
+ // ReadXmlSchema - Tables 1 Col type
|
|
|
+ AssertEquals ("DS294", ds1.Tables[1].Columns[3].GetType (), dt2.Columns[3].GetType ());
|
|
|
+
|
|
|
+ //check that no data exists
|
|
|
+ // ReadXmlSchema - Table 1 row count
|
|
|
+ AssertEquals ("DS295", 0, dt1.Rows.Count);
|
|
|
+
|
|
|
+ // ReadXmlSchema - Table 2 row count
|
|
|
+ AssertEquals ("DS296", 0, dt2.Rows.Count);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema () {
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ ds.ReadXml ("Test/System.Data/region.xml");
|
|
|
+ TextWriter writer = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (writer);
|
|
|
+
|
|
|
+
|
|
|
+ string TextString = GetNormalizedSchema (writer.ToString ());
|
|
|
+ //string TextString = writer.ToString ();
|
|
|
+
|
|
|
+ string substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#01", "<?xml version=\"1.0\" encoding=\"utf-16\"?>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#02", "<xs:schema id=\"Root\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#03", " <xs:element msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Region\" msdata:UseCurrentLocale=\"true\" name=\"Root\">", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#04", " <xs:complexType>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#05", " <xs:choice maxOccurs=\"unbounded\" minOccurs=\"0\">", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#06", " <xs:element name=\"Region\">", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#07", " <xs:complexType>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#08", " <xs:sequence>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#09", " <xs:element minOccurs=\"0\" name=\"RegionID\" type=\"xs:string\" />", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#10", " <xs:element minOccurs=\"0\" name=\"RegionDescription\" type=\"xs:string\" />", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#11", " </xs:sequence>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#12", " </xs:complexType>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#13", " </xs:element>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#14", " </xs:choice>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#15", " </xs:complexType>", substring);
|
|
|
+
|
|
|
+ substring = TextString.Substring (0, TextString.IndexOf (EOL));
|
|
|
+ TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
|
|
|
+ AssertEquals ("test#16", " </xs:element>", substring);
|
|
|
+
|
|
|
+ AssertEquals ("test#17", "</xs:schema>", TextString);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema2 () {
|
|
|
+ string xml = @"<myDataSet xmlns='NetFrameWork'><myTable><id>0</id><item>item 0</item></myTable><myTable><id>1</id><item>item 1</item></myTable><myTable><id>2</id><item>item 2</item></myTable><myTable><id>3</id><item>item 3</item></myTable><myTable><id>4</id><item>item 4</item></myTable><myTable><id>5</id><item>item 5</item></myTable><myTable><id>6</id><item>item 6</item></myTable><myTable><id>7</id><item>item 7</item></myTable><myTable><id>8</id><item>item 8</item></myTable><myTable><id>9</id><item>item 9</item></myTable></myDataSet>";
|
|
|
+ string schema = @"<?xml version='1.0' encoding='utf-16'?>
|
|
|
+<xs:schema id='myDataSet' targetNamespace='NetFrameWork' xmlns:mstns='NetFrameWork' xmlns='NetFrameWork' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' attributeFormDefault='qualified' elementFormDefault='qualified'>
|
|
|
+ <xs:element name='myDataSet' msdata:IsDataSet='true' msdata:MainDataTable='NetFrameWork_x003A_myTable' msdata:UseCurrentLocale='true'>
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs='0' maxOccurs='unbounded'>
|
|
|
+ <xs:element name='myTable'>
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:sequence>
|
|
|
+ <xs:element name='id' msdata:AutoIncrement='true' type='xs:int' minOccurs='0' />
|
|
|
+ <xs:element name='item' type='xs:string' minOccurs='0' />
|
|
|
+ </xs:sequence>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ DataSet OriginalDataSet = new DataSet ("myDataSet");
|
|
|
+ OriginalDataSet.Namespace = "NetFrameWork";
|
|
|
+ DataTable myTable = new DataTable ("myTable");
|
|
|
+ DataColumn c1 = new DataColumn ("id", typeof (int));
|
|
|
+ c1.AutoIncrement = true;
|
|
|
+ DataColumn c2 = new DataColumn ("item");
|
|
|
+ myTable.Columns.Add (c1);
|
|
|
+ myTable.Columns.Add (c2);
|
|
|
+ OriginalDataSet.Tables.Add (myTable);
|
|
|
+ // Add ten rows.
|
|
|
+ DataRow newRow;
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
+ newRow = myTable.NewRow ();
|
|
|
+ newRow["item"] = "item " + i;
|
|
|
+ myTable.Rows.Add (newRow);
|
|
|
+ }
|
|
|
+ OriginalDataSet.AcceptChanges ();
|
|
|
+
|
|
|
+ StringWriter sw = new StringWriter ();
|
|
|
+ XmlTextWriter xtw = new XmlTextWriter (sw);
|
|
|
+ xtw.QuoteChar = '\'';
|
|
|
+ OriginalDataSet.WriteXml (xtw);
|
|
|
+ string result = sw.ToString ();
|
|
|
+
|
|
|
+ AssertEquals (xml, result);
|
|
|
+
|
|
|
+ sw = new StringWriter ();
|
|
|
+ xtw = new XmlTextWriter (sw);
|
|
|
+ xtw.Formatting = Formatting.Indented;
|
|
|
+ OriginalDataSet.Tables[0].WriteXmlSchema (xtw);
|
|
|
+ result = sw.ToString ();
|
|
|
+
|
|
|
+ result = result.Replace ("\r\n", "\n").Replace ('"', '\'');
|
|
|
+ AssertEquals (schema.Replace ("\r\n", "\n"), result);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema3 () {
|
|
|
+ string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
|
|
|
+<xs:schema id=""ExampleDataSet"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
|
|
|
+ <xs:element name=""ExampleDataSet"" msdata:IsDataSet=""true"" msdata:MainDataTable=""ExampleDataTable"" msdata:UseCurrentLocale=""true"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
|
|
|
+ <xs:element name=""ExampleDataTable"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:attribute name=""PrimaryKeyColumn"" type=""xs:int"" use=""required"" />
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ <xs:unique name=""PK_ExampleDataTable"" msdata:PrimaryKey=""true"">
|
|
|
+ <xs:selector xpath="".//ExampleDataTable"" />
|
|
|
+ <xs:field xpath=""@PrimaryKeyColumn"" />
|
|
|
+ </xs:unique>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ DataSet ds = new DataSet ("ExampleDataSet");
|
|
|
+
|
|
|
+ ds.Tables.Add (new DataTable ("ExampleDataTable"));
|
|
|
+ ds.Tables["ExampleDataTable"].Columns.Add (
|
|
|
+ new DataColumn ("PrimaryKeyColumn", typeof (int), "", MappingType.Attribute));
|
|
|
+ ds.Tables["ExampleDataTable"].Columns["PrimaryKeyColumn"].AllowDBNull = false;
|
|
|
+
|
|
|
+ ds.Tables["ExampleDataTable"].Constraints.Add (
|
|
|
+ "PK_ExampleDataTable",
|
|
|
+ ds.Tables["ExampleDataTable"].Columns["PrimaryKeyColumn"],
|
|
|
+ true);
|
|
|
+
|
|
|
+ ds.AcceptChanges ();
|
|
|
+ StringWriter sw = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (sw);
|
|
|
+
|
|
|
+ string result = sw.ToString ();
|
|
|
+
|
|
|
+ AssertEquals (xmlschema.Replace ("\r\n", "\n"), result.Replace ("\r\n", "\n"));
|
|
|
+ //AssertEquals (xmlschema, result.Replace ("\r\n", "\n"));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema4 () {
|
|
|
+ string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
|
|
|
+<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
|
|
|
+ <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:MainDataTable=""MyType"" msdata:UseCurrentLocale=""true"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
|
|
|
+ <xs:element name=""MyType"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:attribute name=""ID"" type=""xs:int"" use=""required"" />
|
|
|
+ <xs:attribute name=""Desc"" type=""xs:string"" />
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ DataSet ds = new DataSet ("Example");
|
|
|
+
|
|
|
+ // Add MyType DataTable
|
|
|
+ DataTable dt = new DataTable ("MyType");
|
|
|
+ ds.Tables.Add (dt);
|
|
|
+
|
|
|
+ dt.Columns.Add (new DataColumn ("ID", typeof (int), "",
|
|
|
+ MappingType.Attribute));
|
|
|
+ dt.Columns["ID"].AllowDBNull = false;
|
|
|
+
|
|
|
+ dt.Columns.Add (new DataColumn ("Desc", typeof
|
|
|
+ (string), "", MappingType.Attribute));
|
|
|
+
|
|
|
+ ds.AcceptChanges ();
|
|
|
+
|
|
|
+ StringWriter sw = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (sw);
|
|
|
+
|
|
|
+ string result = sw.ToString ();
|
|
|
+
|
|
|
+ AssertEquals (xmlschema.Replace ("\r\n", "\n"), result.Replace ("\r\n", "\n"));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema5 () {
|
|
|
+ string xmlschema1 = @"<?xml version=""1.0"" encoding=""utf-16""?>
|
|
|
+<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
|
|
|
+ <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:MainDataTable=""StandAlone"" msdata:UseCurrentLocale=""true"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
|
|
|
+ <xs:element name=""StandAlone"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:attribute name=""ID"" type=""xs:int"" use=""required"" />
|
|
|
+ <xs:attribute name=""Desc"" type=""xs:string"" use=""required"" />
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ string xmlschema2 = @"<?xml version=""1.0"" encoding=""utf-16""?>
|
|
|
+<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
|
|
|
+ <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:MainDataTable=""Dimension"" msdata:UseCurrentLocale=""true"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
|
|
|
+ <xs:element name=""Dimension"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:attribute name=""Number"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
|
|
|
+ <xs:attribute name=""Title"" type=""xs:string"" use=""required"" />
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ <xs:unique name=""PK_Dimension"" msdata:PrimaryKey=""true"">
|
|
|
+ <xs:selector xpath="".//Dimension"" />
|
|
|
+ <xs:field xpath=""@Number"" />
|
|
|
+ </xs:unique>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ string xmlschema3 = @"<?xml version=""1.0"" encoding=""utf-16""?>
|
|
|
+<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
|
|
|
+ <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:MainDataTable=""Element"" msdata:UseCurrentLocale=""true"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
|
|
|
+ <xs:element name=""Element"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:attribute name=""Dimension"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
|
|
|
+ <xs:attribute name=""Number"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
|
|
|
+ <xs:attribute name=""Title"" type=""xs:string"" use=""required"" />
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ <xs:unique name=""PK_Element"" msdata:PrimaryKey=""true"">
|
|
|
+ <xs:selector xpath="".//Element"" />
|
|
|
+ <xs:field xpath=""@Dimension"" />
|
|
|
+ <xs:field xpath=""@Number"" />
|
|
|
+ </xs:unique>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ DataSet ds = new DataSet ("Example");
|
|
|
+
|
|
|
+ // Add a DataTable with no ReadOnly columns
|
|
|
+ DataTable dt1 = new DataTable ("StandAlone");
|
|
|
+ ds.Tables.Add (dt1);
|
|
|
+
|
|
|
+ // Add a ReadOnly column
|
|
|
+ dt1.Columns.Add (new DataColumn ("ID", typeof (int), "",
|
|
|
+ MappingType.Attribute));
|
|
|
+ dt1.Columns["ID"].AllowDBNull = false;
|
|
|
+
|
|
|
+ dt1.Columns.Add (new DataColumn ("Desc", typeof
|
|
|
+ (string), "", MappingType.Attribute));
|
|
|
+ dt1.Columns["Desc"].AllowDBNull = false;
|
|
|
+
|
|
|
+ // Add related DataTables with ReadOnly columns
|
|
|
+ DataTable dt2 = new DataTable ("Dimension");
|
|
|
+ ds.Tables.Add (dt2);
|
|
|
+ dt2.Columns.Add (new DataColumn ("Number", typeof
|
|
|
+ (int), "", MappingType.Attribute));
|
|
|
+ dt2.Columns["Number"].AllowDBNull = false;
|
|
|
+ dt2.Columns["Number"].ReadOnly = true;
|
|
|
+
|
|
|
+ dt2.Columns.Add (new DataColumn ("Title", typeof
|
|
|
+ (string), "", MappingType.Attribute));
|
|
|
+ dt2.Columns["Title"].AllowDBNull = false;
|
|
|
+
|
|
|
+ dt2.Constraints.Add ("PK_Dimension", dt2.Columns["Number"], true);
|
|
|
+
|
|
|
+ DataTable dt3 = new DataTable ("Element");
|
|
|
+ ds.Tables.Add (dt3);
|
|
|
+
|
|
|
+ dt3.Columns.Add (new DataColumn ("Dimension", typeof
|
|
|
+ (int), "", MappingType.Attribute));
|
|
|
+ dt3.Columns["Dimension"].AllowDBNull = false;
|
|
|
+ dt3.Columns["Dimension"].ReadOnly = true;
|
|
|
+
|
|
|
+ dt3.Columns.Add (new DataColumn ("Number", typeof
|
|
|
+ (int), "", MappingType.Attribute));
|
|
|
+ dt3.Columns["Number"].AllowDBNull = false;
|
|
|
+ dt3.Columns["Number"].ReadOnly = true;
|
|
|
+
|
|
|
+ dt3.Columns.Add (new DataColumn ("Title", typeof
|
|
|
+ (string), "", MappingType.Attribute));
|
|
|
+ dt3.Columns["Title"].AllowDBNull = false;
|
|
|
+
|
|
|
+ dt3.Constraints.Add ("PK_Element", new DataColumn[] {
|
|
|
+ dt3.Columns ["Dimension"],
|
|
|
+ dt3.Columns ["Number"] }, true);
|
|
|
+
|
|
|
+ ds.AcceptChanges ();
|
|
|
+
|
|
|
+ StringWriter sw1 = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (sw1);
|
|
|
+ string result1 = sw1.ToString ();
|
|
|
+ AssertEquals (xmlschema1.Replace ("\r\n", "\n"), result1.Replace ("\r\n", "\n"));
|
|
|
+
|
|
|
+ StringWriter sw2 = new StringWriter ();
|
|
|
+ ds.Tables[1].WriteXmlSchema (sw2);
|
|
|
+ string result2 = sw2.ToString ();
|
|
|
+ AssertEquals (xmlschema2.Replace ("\r\n", "\n"), result2.Replace ("\r\n", "\n"));
|
|
|
+
|
|
|
+ StringWriter sw3 = new StringWriter ();
|
|
|
+ ds.Tables[2].WriteXmlSchema (sw3);
|
|
|
+ string result3 = sw3.ToString ();
|
|
|
+ AssertEquals (xmlschema3.Replace ("\r\n", "\n"), result3.Replace ("\r\n", "\n"));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema6 () {
|
|
|
+ string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
|
|
|
+<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
|
|
|
+ <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:MainDataTable=""MyType"" msdata:UseCurrentLocale=""true"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
|
|
|
+ <xs:element name=""MyType"">
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:attribute name=""Desc"">
|
|
|
+ <xs:simpleType>
|
|
|
+ <xs:restriction base=""xs:string"">
|
|
|
+ <xs:maxLength value=""32"" />
|
|
|
+ </xs:restriction>
|
|
|
+ </xs:simpleType>
|
|
|
+ </xs:attribute>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ DataSet ds = new DataSet ("Example");
|
|
|
+
|
|
|
+ // Add MyType DataTable
|
|
|
+ ds.Tables.Add ("MyType");
|
|
|
+
|
|
|
+ ds.Tables["MyType"].Columns.Add (new DataColumn (
|
|
|
+ "Desc", typeof (string), "", MappingType.Attribute));
|
|
|
+ ds.Tables["MyType"].Columns["Desc"].MaxLength = 32;
|
|
|
+
|
|
|
+ ds.AcceptChanges ();
|
|
|
+
|
|
|
+ StringWriter sw = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (sw);
|
|
|
+
|
|
|
+ string result = sw.ToString ();
|
|
|
+
|
|
|
+ AssertEquals (xmlschema.Replace ("\r\n", "\n"), result.Replace ("\r\n", "\n"));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void WriteXmlSchema7 () {
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ DataTable dt = new DataTable ("table");
|
|
|
+ dt.Columns.Add ("col1");
|
|
|
+ dt.Columns.Add ("col2");
|
|
|
+ ds.Tables.Add (dt);
|
|
|
+ dt.Rows.Add (new object[] { "foo", "bar" });
|
|
|
+ StringWriter sw = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (sw);
|
|
|
+ Assert (sw.ToString ().IndexOf ("xmlns=\"\"") > 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void WriteXmlSchema_ConstraintNameWithSpaces () {
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ DataTable table1 = ds.Tables.Add ("table1");
|
|
|
+ DataTable table2 = ds.Tables.Add ("table2");
|
|
|
+
|
|
|
+ table1.Columns.Add ("col1", typeof (int));
|
|
|
+ table2.Columns.Add ("col1", typeof (int));
|
|
|
+
|
|
|
+ table1.Constraints.Add ("uc 1", table1.Columns[0], false);
|
|
|
+ table2.Constraints.Add ("fc 1", table1.Columns[0], table2.Columns[0]);
|
|
|
+
|
|
|
+ StringWriter sw1 = new StringWriter ();
|
|
|
+ StringWriter sw2 = new StringWriter ();
|
|
|
+
|
|
|
+ //should not throw an exception
|
|
|
+ ds.Tables[0].WriteXmlSchema (sw1);
|
|
|
+ ds.Tables[1].WriteXmlSchema (sw2);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ public void WriteXmlSchema_ForignKeyConstraint () {
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+
|
|
|
+ DataTable table1 = ds1.Tables.Add ();
|
|
|
+ DataTable table2 = ds1.Tables.Add ();
|
|
|
+
|
|
|
+ DataColumn col1_1 = table1.Columns.Add ("col1", typeof (int));
|
|
|
+ DataColumn col2_1 = table2.Columns.Add ("col1", typeof (int));
|
|
|
+
|
|
|
+ table2.Constraints.Add ("fk", col1_1, col2_1);
|
|
|
+
|
|
|
+ StringWriter sw1 = new StringWriter ();
|
|
|
+ ds1.Tables[0].WriteXmlSchema (sw1);
|
|
|
+ String xml1 = sw1.ToString ();
|
|
|
+ Assert ("#1", xml1.IndexOf (@"<xs:unique name=""Constraint1"">") != -1);
|
|
|
+
|
|
|
+ StringWriter sw2 = new StringWriter ();
|
|
|
+ ds1.Tables[1].WriteXmlSchema (sw2);
|
|
|
+ String xml2 = sw2.ToString ();
|
|
|
+ Assert ("#2", xml2.IndexOf (@"<xs:unique name=""Constraint1"">") == -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema_Relations_ForeignKeys () {
|
|
|
+ MemoryStream ms1 = null;
|
|
|
+ MemoryStream ms2 = null;
|
|
|
+ MemoryStream msA = null;
|
|
|
+ MemoryStream msB = null;
|
|
|
+
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+
|
|
|
+ DataTable table1 = ds1.Tables.Add ("Table 1");
|
|
|
+ DataTable table2 = ds1.Tables.Add ("Table 2");
|
|
|
+
|
|
|
+ DataColumn col1_1 = table1.Columns.Add ("col 1", typeof (int));
|
|
|
+ DataColumn col1_2 = table1.Columns.Add ("col 2", typeof (int));
|
|
|
+ DataColumn col1_3 = table1.Columns.Add ("col 3", typeof (int));
|
|
|
+ DataColumn col1_4 = table1.Columns.Add ("col 4", typeof (int));
|
|
|
+ DataColumn col1_5 = table1.Columns.Add ("col 5", typeof (int));
|
|
|
+ DataColumn col1_6 = table1.Columns.Add ("col 6", typeof (int));
|
|
|
+ DataColumn col1_7 = table1.Columns.Add ("col 7", typeof (int));
|
|
|
+
|
|
|
+ DataColumn col2_1 = table2.Columns.Add ("col 1", typeof (int));
|
|
|
+ DataColumn col2_2 = table2.Columns.Add ("col 2", typeof (int));
|
|
|
+ DataColumn col2_3 = table2.Columns.Add ("col 3", typeof (int));
|
|
|
+ DataColumn col2_4 = table2.Columns.Add ("col 4", typeof (int));
|
|
|
+ DataColumn col2_5 = table2.Columns.Add ("col 5", typeof (int));
|
|
|
+ DataColumn col2_6 = table2.Columns.Add ("col 6", typeof (int));
|
|
|
+ DataColumn col2_7 = table2.Columns.Add ("col 7", typeof (int));
|
|
|
+
|
|
|
+ ds1.Relations.Add ("rel 1",
|
|
|
+ new DataColumn[] { col1_1, col1_2 },
|
|
|
+ new DataColumn[] { col2_1, col2_2 },
|
|
|
+ false);
|
|
|
+ ds1.Relations.Add ("rel 2",
|
|
|
+ new DataColumn[] { col1_3, col1_4 },
|
|
|
+ new DataColumn[] { col2_3, col2_4 },
|
|
|
+ true);
|
|
|
+ table2.Constraints.Add ("fk 1",
|
|
|
+ new DataColumn[] { col1_5, col1_6 },
|
|
|
+ new DataColumn[] { col2_5, col2_6 });
|
|
|
+ table1.Constraints.Add ("fk 2",
|
|
|
+ new DataColumn[] { col2_5, col2_6 },
|
|
|
+ new DataColumn[] { col1_5, col1_6 });
|
|
|
+
|
|
|
+ table1.Constraints.Add ("pk 1", col1_7, true);
|
|
|
+ table2.Constraints.Add ("pk 2", col2_7, true);
|
|
|
+
|
|
|
+ ms1 = new MemoryStream ();
|
|
|
+ ds1.Tables[0].WriteXmlSchema (ms1);
|
|
|
+ ms2 = new MemoryStream ();
|
|
|
+ ds1.Tables[1].WriteXmlSchema (ms2);
|
|
|
+
|
|
|
+ msA = new MemoryStream (ms1.GetBuffer ());
|
|
|
+ DataTable dtA = new DataTable ();
|
|
|
+ dtA.ReadXmlSchema (msA);
|
|
|
+
|
|
|
+ msB = new MemoryStream (ms2.GetBuffer ());
|
|
|
+ DataTable dtB = new DataTable ();
|
|
|
+ dtB.ReadXmlSchema (msB);
|
|
|
+
|
|
|
+ AssertEquals ("#2", 3, dtA.Constraints.Count);
|
|
|
+ AssertEquals ("#3", 2, dtB.Constraints.Count);
|
|
|
+
|
|
|
+ Assert ("#5", dtA.Constraints.Contains ("pk 1"));
|
|
|
+ Assert ("#6", dtA.Constraints.Contains ("Constraint1"));
|
|
|
+ Assert ("#7", dtA.Constraints.Contains ("Constraint2"));
|
|
|
+ Assert ("#9", dtB.Constraints.Contains ("pk 2"));
|
|
|
+ Assert ("#10", dtB.Constraints.Contains ("Constraint1"));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void WriteXmlSchema_DifferentNamespace () {
|
|
|
+ string schema = @"<xs:schema id='NewDataSet' targetNamespace='urn:bar' xmlns:mstns='urn:bar' xmlns='urn:bar' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' attributeFormDefault='qualified' elementFormDefault='qualified' xmlns:app1='urn:baz' xmlns:app2='urn:foo' msdata:schemafragmentcount='3'>
|
|
|
+ <xs:import namespace='urn:foo' />
|
|
|
+ <xs:import namespace='urn:baz' />
|
|
|
+ <xs:element name='NewDataSet' msdata:IsDataSet='true' msdata:MainDataTable='urn_x003A_foo_x003A_NS1Table' msdata:UseCurrentLocale='true'>
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:choice minOccurs='0' maxOccurs='unbounded'>
|
|
|
+ <xs:element ref='app2:NS1Table' />
|
|
|
+ </xs:choice>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>
|
|
|
+<xs:schema targetNamespace='urn:baz' xmlns:mstns='urn:bar' xmlns='urn:baz' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' attributeFormDefault='qualified' elementFormDefault='qualified' xmlns:app1='urn:baz' xmlns:app2='urn:foo'>
|
|
|
+ <xs:import namespace='urn:foo' />
|
|
|
+ <xs:import namespace='urn:bar' />
|
|
|
+ <xs:element name='column2' type='xs:string' />
|
|
|
+</xs:schema>
|
|
|
+<xs:schema targetNamespace='urn:foo' xmlns:mstns='urn:bar' xmlns='urn:foo' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' attributeFormDefault='qualified' elementFormDefault='qualified' xmlns:app2='urn:foo' xmlns:app1='urn:baz'>
|
|
|
+ <xs:import namespace='urn:bar' />
|
|
|
+ <xs:import namespace='urn:baz' />
|
|
|
+ <xs:element name='NS1Table'>
|
|
|
+ <xs:complexType>
|
|
|
+ <xs:sequence>
|
|
|
+ <xs:element name='column1' type='xs:string' minOccurs='0' />
|
|
|
+ <xs:element ref='app1:column2' minOccurs='0' />
|
|
|
+ </xs:sequence>
|
|
|
+ </xs:complexType>
|
|
|
+ </xs:element>
|
|
|
+</xs:schema>";
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ DataTable dt = new DataTable ();
|
|
|
+ dt.TableName = "NS1Table";
|
|
|
+ dt.Namespace = "urn:foo";
|
|
|
+ dt.Columns.Add ("column1");
|
|
|
+ dt.Columns.Add ("column2");
|
|
|
+ dt.Columns[1].Namespace = "urn:baz";
|
|
|
+ ds.Tables.Add (dt);
|
|
|
+ DataTable dt2 = new DataTable ();
|
|
|
+ dt2.TableName = "NS2Table";
|
|
|
+ dt2.Namespace = "urn:bar";
|
|
|
+ ds.Tables.Add (dt2);
|
|
|
+ ds.Namespace = "urn:bar";
|
|
|
+
|
|
|
+ StringWriter sw1 = new StringWriter ();
|
|
|
+ XmlTextWriter xw1 = new XmlTextWriter (sw1);
|
|
|
+ xw1.Formatting = Formatting.Indented;
|
|
|
+ xw1.QuoteChar = '\'';
|
|
|
+ ds.Tables[0].WriteXmlSchema (xw1);
|
|
|
+ string result1 = sw1.ToString ();
|
|
|
+ AssertEquals ("#1", schema, result1);
|
|
|
+
|
|
|
+ StringWriter sw2 = new StringWriter ();
|
|
|
+ XmlTextWriter xw2 = new XmlTextWriter (sw2);
|
|
|
+ xw2.Formatting = Formatting.Indented;
|
|
|
+ xw2.QuoteChar = '\'';
|
|
|
+ ds.Tables[0].WriteXmlSchema (xw2);
|
|
|
+ string result2 = sw2.ToString ();
|
|
|
+ AssertEquals ("#2", schema, result2);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ // WriteXmlSchema doesn't have overload wityh 2 parameters in System.Data
|
|
|
+ // and is commented-out TWICE below
|
|
|
+ public void WriteXmlSchema_Hierarchy () {
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ DataTable table1 = new DataTable ();
|
|
|
+ DataColumn idColumn = table1.Columns.Add ("ID", typeof (Int32));
|
|
|
+ table1.Columns.Add ("Name", typeof (String));
|
|
|
+ table1.PrimaryKey = new DataColumn[] { idColumn };
|
|
|
+ DataTable table2 = new DataTable ();
|
|
|
+ table2.Columns.Add (new DataColumn ("OrderID", typeof (Int32)));
|
|
|
+ table2.Columns.Add (new DataColumn ("CustomerID", typeof (Int32)));
|
|
|
+ table2.Columns.Add (new DataColumn ("OrderDate", typeof (DateTime)));
|
|
|
+ table2.PrimaryKey = new DataColumn[] { table2.Columns[0] };
|
|
|
+ ds.Tables.Add (table1);
|
|
|
+ ds.Tables.Add (table2);
|
|
|
+ ds.Relations.Add ("CustomerOrder",
|
|
|
+ new DataColumn[] { table1.Columns[0] },
|
|
|
+ new DataColumn[] { table2.Columns[1] }, true);
|
|
|
+
|
|
|
+ StringWriter writer1 = new StringWriter ();
|
|
|
+ //table1.WriteXmlSchema (writer1, false);
|
|
|
+ string expected1 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\r\n <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table1\" msdata:UseCurrentLocale=\"true\">\r\n <xs:complexType>\r\n <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n <xs:element name=\"Table1\">\r\n <xs:complexType>\r\n <xs:sequence>\r\n <xs:element name=\"ID\" type=\"xs:int\" />\r\n <xs:element name=\"Name\" type=\"xs:string\" minOccurs=\"0\" />\r\n </xs:sequence>\r\n </xs:complexType>\r\n </xs:element>\r\n </xs:choice>\r\n </xs:complexType>\r\n <xs:unique name=\"Constraint1\" msdata:PrimaryKey=\"true\">\r\n <xs:selector xpath=\".//Table1\" />\r\n <xs:field xpath=\"ID\" />\r\n </xs:unique>\r\n </xs:element>\r\n</xs:schema>";
|
|
|
+ AssertEquals ("#1", expected1, writer1.ToString());
|
|
|
+
|
|
|
+ StringWriter writer2 = new StringWriter ();
|
|
|
+ //table1.WriteXmlSchema (writer2, true);
|
|
|
+ string expected2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<xs:schema id=\"NewDataSet\" xmlns=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\r\n <xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:MainDataTable=\"Table1\" msdata:UseCurrentLocale=\"true\">\r\n <xs:complexType>\r\n <xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">\r\n <xs:element name=\"Table1\">\r\n <xs:complexType>\r\n <xs:sequence>\r\n <xs:element name=\"ID\" type=\"xs:int\" />\r\n <xs:element name=\"Name\" type=\"xs:string\" minOccurs=\"0\" />\r\n </xs:sequence>\r\n </xs:complexType>\r\n </xs:element>\r\n <xs:element name=\"Table2\">\r\n <xs:complexType>\r\n <xs:sequence>\r\n <xs:element name=\"OrderID\" type=\"xs:int\" />\r\n <xs:element name=\"CustomerID\" type=\"xs:int\" minOccurs=\"0\" />\r\n <xs:element name=\"OrderDate\" type=\"xs:dateTime\" minOccurs=\"0\" />\r\n </xs:sequence>\r\n </xs:complexType>\r\n </xs:element>\r\n </xs:choice>\r\n </xs:complexType>\r\n <xs:unique name=\"Constraint1\" msdata:PrimaryKey=\"true\">\r\n <xs:selector xpath=\".//Table1\" />\r\n <xs:field xpath=\"ID\" />\r\n </xs:unique>\r\n <xs:unique name=\"Table2_Constraint1\" msdata:ConstraintName=\"Constraint1\" msdata:PrimaryKey=\"true\">\r\n <xs:selector xpath=\".//Table2\" />\r\n <xs:field xpath=\"OrderID\" />\r\n </xs:unique>\r\n <xs:keyref name=\"CustomerOrder\" refer=\"Constraint1\">\r\n <xs:selector xpath=\".//Table2\" />\r\n <xs:field xpath=\"CustomerID\" />\r\n </xs:keyref>\r\n </xs:element>\r\n</xs:schema>";
|
|
|
+ AssertEquals ("#2", expected2, writer2.ToString ());
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ // WriteXmlSchema doesn't have overload wityh 2 parameters in System.Data
|
|
|
+ // and is commented-out TWICE below
|
|
|
+ public void ReadWriteXmlSchema () {
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ ds.ReadXmlSchema ("Test/System.Data/store.xsd");
|
|
|
+ // check dataset properties before testing write
|
|
|
+ AssertDataSet ("ds", ds, "NewDataSet", 3, 2);
|
|
|
+ AssertDataTable ("tab1", ds.Tables[0], "bookstore", 1, 0, 0, 1, 1, 1);
|
|
|
+ AssertDataTable ("tab2", ds.Tables[1], "book", 5, 0, 1, 1, 2, 1);
|
|
|
+ AssertDataTable ("tab3", ds.Tables[2], "author", 3, 0, 1, 0, 1, 0);
|
|
|
+ // FIXME: currently order is not compatible. Use name as index
|
|
|
+ AssertDataRelation ("rel1", ds.Relations["book_author"], "book_author", true, new string[] { "book_Id" }, new string[] { "book_Id" }, true, true);
|
|
|
+ AssertDataRelation ("rel2", ds.Relations["bookstore_book"], "bookstore_book", true, new string[] { "bookstore_Id" }, new string[] { "bookstore_Id" }, true, true);
|
|
|
+
|
|
|
+ ds.ReadXml ("Test/System.Data/region.xml", XmlReadMode.InferSchema);
|
|
|
+ ds.Relations.Clear (); // because can not call WriteXmlSchema with nested relations.
|
|
|
+
|
|
|
+ TextWriter writer1 = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (writer1);
|
|
|
+ string TextString1 = GetNormalizedSchema (writer1.ToString ());
|
|
|
+ string expected1 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:complexType name=""bookstoreType"">" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"<xs:element name=""bookstore"" type=""bookstoreType"" />" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""bookstore"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element ref=""bookstore"" />" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#1", expected1, TextString1.Replace("\r\n","").Replace(" ",""));
|
|
|
+
|
|
|
+ TextWriter writer2 = new StringWriter ();
|
|
|
+ //ds.Tables[1].WriteXmlSchema (writer2,false);
|
|
|
+ string TextString2 = GetNormalizedSchema (writer2.ToString ());
|
|
|
+ string expected2 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:complexType name=""bookType"">" +
|
|
|
+ @"<xs:sequence>" +
|
|
|
+ @"<xs:element msdata:Ordinal=""1"" name=""title"" type=""xs:string"" />" +
|
|
|
+ @"<xs:element msdata:Ordinal=""2"" name=""price"" type=""xs:decimal"" />" +
|
|
|
+ @"</xs:sequence>" +
|
|
|
+ @"<xs:attribute name=""genre"" type=""xs:string"" />" +
|
|
|
+ @"<xs:attribute name=""bookstore_Id"" type=""xs:int"" use=""prohibited"" />" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"<xs:element name=""book"" type=""bookType"" />" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""book"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element ref=""book"" />" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#2", expected2, TextString2.Replace ("\r\n", "").Replace (" ", ""));
|
|
|
+
|
|
|
+ TextWriter writer3 = new StringWriter ();
|
|
|
+ ds.Tables[2].WriteXmlSchema (writer3);
|
|
|
+ string TextString3 = GetNormalizedSchema (writer3.ToString ());
|
|
|
+ string expected3 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:complexType name=""authorName"">" +
|
|
|
+ @"<xs:sequence>" +
|
|
|
+ @"<xs:element msdata:Ordinal=""0"" name=""first-name"" type=""xs:string"" />" +
|
|
|
+ @"<xs:element msdata:Ordinal=""1"" name=""last-name"" type=""xs:string"" />" +
|
|
|
+ @"</xs:sequence>" +
|
|
|
+ @"<xs:attribute name=""book_Id"" type=""xs:int"" use=""prohibited"" />" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"<xs:element name=""author"" type=""authorName"" />" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""author"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element ref=""author"" />" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#3", expected3, TextString3.Replace ("\r\n", "").Replace (" ", ""));
|
|
|
+
|
|
|
+ TextWriter writer4 = new StringWriter ();
|
|
|
+ ds.Tables[3].WriteXmlSchema (writer4);
|
|
|
+ string TextString4 = GetNormalizedSchema (writer4.ToString ());
|
|
|
+ string expected4 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""Region"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element name=""Region"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:sequence>" +
|
|
|
+ @"<xs:element minOccurs=""0"" name=""RegionID"" type=""xs:string"" />" +
|
|
|
+ @"<xs:element minOccurs=""0"" name=""RegionDescription"" type=""xs:string"" />" +
|
|
|
+ @"</xs:sequence>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#4", expected4, TextString4.Replace ("\r\n", "").Replace (" ", ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void ReadWriteXmlSchema_IgnoreSchema () {
|
|
|
+ DataSet ds = new DataSet ();
|
|
|
+ ds.ReadXmlSchema ("Test/System.Data/store.xsd");
|
|
|
+ // check dataset properties before testing write
|
|
|
+ AssertDataSet ("ds", ds, "NewDataSet", 3, 2);
|
|
|
+ AssertDataTable ("tab1", ds.Tables[0], "bookstore", 1, 0, 0, 1, 1, 1);
|
|
|
+ AssertDataTable ("tab2", ds.Tables[1], "book", 5, 0, 1, 1, 2, 1);
|
|
|
+ AssertDataTable ("tab3", ds.Tables[2], "author", 3, 0, 1, 0, 1, 0);
|
|
|
+ // FIXME: currently order is not compatible. Use name as index
|
|
|
+ AssertDataRelation ("rel1", ds.Relations["book_author"], "book_author", true, new string[] { "book_Id" }, new string[] { "book_Id" }, true, true);
|
|
|
+ AssertDataRelation ("rel2", ds.Relations["bookstore_book"], "bookstore_book", true, new string[] { "bookstore_Id" }, new string[] { "bookstore_Id" }, true, true);
|
|
|
+
|
|
|
+ ds.ReadXml ("Test/System.Data/region.xml", XmlReadMode.IgnoreSchema);
|
|
|
+ ds.Relations.Clear (); // because can not call WriteXmlSchema with nested relations.
|
|
|
+
|
|
|
+ TextWriter writer1 = new StringWriter ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (writer1);
|
|
|
+ string TextString1 = GetNormalizedSchema (writer1.ToString ());
|
|
|
+ string expected1 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""NewDataSet"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:complexType name=""bookstoreType"">" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"<xs:element name=""bookstore"" type=""bookstoreType"" />" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""bookstore"" msdata:UseCurrentLocale=""true"" name=""NewDataSet"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element ref=""bookstore"" />" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#1", expected1, TextString1.Replace ("\r\n", "").Replace (" ", ""));
|
|
|
+
|
|
|
+ TextWriter writer2 = new StringWriter ();
|
|
|
+ //ds.Tables[1].WriteXmlSchema (writer2, false);
|
|
|
+ string TextString2 = GetNormalizedSchema (writer2.ToString ());
|
|
|
+ string expected2 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""NewDataSet"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:complexType name=""bookType"">" +
|
|
|
+ @"<xs:sequence>" +
|
|
|
+ @"<xs:element msdata:Ordinal=""1"" name=""title"" type=""xs:string"" />" +
|
|
|
+ @"<xs:element msdata:Ordinal=""2"" name=""price"" type=""xs:decimal"" />" +
|
|
|
+ @"</xs:sequence>" +
|
|
|
+ @"<xs:attribute name=""genre"" type=""xs:string"" />" +
|
|
|
+ @"<xs:attribute name=""bookstore_Id"" type=""xs:int"" use=""prohibited"" />" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"<xs:element name=""book"" type=""bookType"" />" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""book"" msdata:UseCurrentLocale=""true"" name=""NewDataSet"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element ref=""book"" />" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#2", expected2, TextString2.Replace ("\r\n", "").Replace (" ", ""));
|
|
|
+
|
|
|
+ TextWriter writer3 = new StringWriter ();
|
|
|
+ ds.Tables[2].WriteXmlSchema (writer3);
|
|
|
+ string TextString3 = GetNormalizedSchema (writer3.ToString ());
|
|
|
+ string expected3 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
|
|
|
+@"<xs:schema id=""NewDataSet"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
|
|
|
+ @"<xs:complexType name=""authorName"">" +
|
|
|
+ @"<xs:sequence>" +
|
|
|
+ @"<xs:element msdata:Ordinal=""0"" name=""first-name"" type=""xs:string"" />" +
|
|
|
+ @"<xs:element msdata:Ordinal=""1"" name=""last-name"" type=""xs:string"" />" +
|
|
|
+ @"</xs:sequence>" +
|
|
|
+ @"<xs:attribute name=""book_Id"" type=""xs:int"" use=""prohibited"" />" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"<xs:element name=""author"" type=""authorName"" />" +
|
|
|
+ @"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""author"" msdata:UseCurrentLocale=""true"" name=""NewDataSet"">" +
|
|
|
+ @"<xs:complexType>" +
|
|
|
+ @"<xs:choice maxOccurs=""unbounded"" minOccurs=""0"">" +
|
|
|
+ @"<xs:element ref=""author"" />" +
|
|
|
+ @"</xs:choice>" +
|
|
|
+ @"</xs:complexType>" +
|
|
|
+ @"</xs:element>" +
|
|
|
+@"</xs:schema>";
|
|
|
+ AssertEquals ("#3", expected3, TextString3.Replace ("\r\n", "").Replace (" ", ""));
|
|
|
+
|
|
|
+ TextWriter writer4 = new StringWriter ();
|
|
|
+ string expStr = "";
|
|
|
+ try {
|
|
|
+ ds.Tables[3].WriteXmlSchema (writer4);
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ expStr = ex.Message;
|
|
|
+ }
|
|
|
+ AssertEquals ("#4", "Cannot find table 3.", expStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ public void ReadWriteXmlSchema_2 () {
|
|
|
+ DataSet ds = new DataSet ("dataset");
|
|
|
+ ds.Tables.Add ("table1");
|
|
|
+ ds.Tables.Add ("table2");
|
|
|
+ ds.Tables[0].Columns.Add ("col");
|
|
|
+ ds.Tables[1].Columns.Add ("col");
|
|
|
+ ds.Relations.Add ("rel", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0], true);
|
|
|
+
|
|
|
+ MemoryStream ms1 = new MemoryStream ();
|
|
|
+ ds.Tables[0].WriteXmlSchema (ms1);
|
|
|
+ MemoryStream ms2 = new MemoryStream ();
|
|
|
+ ds.Tables[1].WriteXmlSchema (ms2);
|
|
|
+
|
|
|
+ DataSet ds1 = new DataSet ();
|
|
|
+ ds1.Tables.Add ();
|
|
|
+ ds1.Tables.Add ();
|
|
|
+ ds1.Tables[0].ReadXmlSchema (new MemoryStream (ms1.GetBuffer ()));
|
|
|
+ ds1.Tables[1].ReadXmlSchema (new MemoryStream (ms2.GetBuffer ()));
|
|
|
+
|
|
|
+ AssertEquals ("#1", 0, ds1.Relations.Count);
|
|
|
+ AssertEquals ("#2", 1, ds1.Tables[0].Columns.Count);
|
|
|
+ AssertEquals ("#3", 1, ds1.Tables[1].Columns.Count);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (XmlException))]
|
|
|
+ public void ReadWriteXmlSchemaExp_NoRootElmnt () {
|
|
|
+ MemoryStream ms = new MemoryStream ();
|
|
|
+ DataTable dtr = new DataTable ();
|
|
|
+ dtr.ReadXmlSchema (ms);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [Category ("NotWorking")]
|
|
|
+ [ExpectedException (typeof (InvalidOperationException))]
|
|
|
+ public void ReadWriteXmlSchemaExp_NoTableName () {
|
|
|
+ DataTable dtw = new DataTable ();
|
|
|
+ MemoryStream ms = new MemoryStream ();
|
|
|
+ dtw.WriteXmlSchema (ms);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Test]
|
|
|
+ [ExpectedException (typeof (ArgumentException))]
|
|
|
+ public void ReadWriteXmlSchemaExp_TableNameConflict () {
|
|
|
+ DataTable dtw = new DataTable ("Table1");
|
|
|
+ StringWriter writer1 = new StringWriter ();
|
|
|
+ dtw.WriteXmlSchema (writer1);
|
|
|
+ DataTable dtr = new DataTable ("Table2");
|
|
|
+ StringReader reader1 = new StringReader (writer1.ToString());
|
|
|
+ dtr.ReadXmlSchema (reader1);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion // Read/Write XML Tests
|
|
|
+
|
|
|
+#endif // NET_2_0
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|