+2005-07-12 Eyal Alalouf <eyala@mainsoft.com>
+ * System.Data_tests.dll.sources:
+ Unified Mainsoft DataRelation tests into one test in Test/System.Data
+ Unified Mainsoft DataRow tests into one test in Test/System.Data
+ Unified Mainsoft DataRowCollection tests into one test in Test/System.Data
+ Unified Mainsoft DataRowView tests into one test in Test/System.Data
+ Unified Mainsoft DataTableCollection tests into one test in Test/System.Data
+ Unified Mainsoft DataTable tests into one test in Test/System.Data
+ Unified Mainsoft DataView tests into one test in Test/System.Data
+ Unified Mainsoft ForeignKeyConstraint tests into one test in Test/System.Data
+ Unified Mainsoft UniqueConstraint tests into one test in Test/System.Data
+
2005-07-12 Eyal Alalouf <eyala@mainsoft.com>
* System.Data_tests.dll.sources: Unified Mainsoft DataRelationCollection tests into one test in Test/System.Data
System.Data/DataColumnTest.cs
System.Data/DataColumnTest2.cs
System.Data/DataRelationTest.cs
+System.Data/DataRelationTest2.cs
System.Data/DataRowCollectionTest.cs
+System.Data/DataRowCollectionTest2.cs
System.Data/DataRowTest.cs
+System.Data/DataRowTest2.cs
System.Data/DataRowViewTest.cs
+System.Data/DataRowViewTest2.cs
System.Data/DataSetAssertion.cs
System.Data/DataSetTest.cs
System.Data/DataSetTest2.cs
System.Data/DataSetReadXmlSchemaTest.cs
System.Data/DataSetInferXmlSchemaTest.cs
System.Data/DataTableTest.cs
+System.Data/DataTableTest2.cs
System.Data/DataTableLoadRowTest.cs
System.Data/DataTableReaderTest.cs
System.Data/DataViewManagerTest.cs
System.Data/DataViewTest.cs
+System.Data/DataViewTest2.cs
System.Data/ForeignKeyConstraintTest.cs
+System.Data/ForeignKeyConstraintTest2.cs
System.Data/TypedDataSetGeneratorTest.cs
System.Data/UniqueConstraintTest.cs
+System.Data/UniqueConstraintTest2.cs
System.Data/DataRelationCollectionTest.cs
System.Data/DataRelationCollectionTest2.cs
System.Data/DataTableCollectionTest.cs
+System.Data/DataTableCollectionTest2.cs
System.Data.Common/DbProviderFactoriesConfigurationHandlerTest.cs
System.Data.Common/ConnectionStringsSectionTest.cs
System.Data.Common/DataColumnMappingCollectionTest.cs
System.Data.Tests.Mainsoft/GHTUtils/ObjectTester.cs
System.Data.Tests.Mainsoft/GHTUtils/XmlUtils.cs
System.Data.Tests.Mainsoft/System.Data/ConstraintException/ConstraintException_Generate.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ChildColumns.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ChildKeyConstraint.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ChildTable.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ctor_SDclmDclm.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ctor_SDclmDclmB.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ctor_SDclmsDclms.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ctor_SDclmsDclmsB.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_DataSet.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_extendedProperties.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_nested.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ParentColumns.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ParentKeyConstraint.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ParentTable.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_relationName.cs
-System.Data.Tests.Mainsoft/System.Data/DataRelation/DataRelation_ToString.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_AcceptChanges.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_CancelEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_ClearErrors.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_Delete.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_EndEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_Equals_O.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetChildRows_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetChildRows_DD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetChildRows_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetChildRows_SD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetColumnError_I.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetColumnError_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetColumnsInError.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetHashCode.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRows_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRows_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRows_SD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRow_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRow_DD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRow_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetParentRow_SD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_GetType.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_HasErrors.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_HasVersion_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_IsNull_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_IsNull_DD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_IsNull_I.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_IsNull_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_Item.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_RejectChanges.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_RowState.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_SetColumnError_DS.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_SetColumnError_IS.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_SetColumnError_SS.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_SetParentRow_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_SetParentRow_DD.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_Table.cs
-System.Data.Tests.Mainsoft/System.Data/DataRow/DataRow_ToString.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowCollection/DataRowCollection_CopyTo_AI.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowCollection/DataRowCollection_Count.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowCollection/DataRowCollection_GetEnumerator.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowCollection/DataRowCollection_RemoveAt_I.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowCollection/DataRowCollection_Remove_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_BeginEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_CancelEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_CreateChildView_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_CreateChildView_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_DataView.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_Delete.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_EndEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_Equals_O.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_IsEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_IsNew.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_Item.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_Item_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_Row.cs
-System.Data.Tests.Mainsoft/System.Data/DataRowView/DataRowView_RowVersion.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_AcceptChanges.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_caseSensitive.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ChildRelations.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Clear.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Clone.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ColumnChanged.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ColumnChanging.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Columns.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Compute_SS.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Constraints.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Copy.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_CreateInstance.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ctor.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ctor_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_DataSet.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_DefaultView.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_displayExpression.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_EndLoadData.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_extendedProperties.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_GetChanges.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_GetChanges_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_GetErrors.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_GetHashCode.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_GetType.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_HasErrors.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ImportRow_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_LoadDataRow_OB.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Locale.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_MinimumCapacity.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Namespace.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_NewRow.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_OnColumnChanged_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_OnColumnChanging_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_OnRemoveColumn_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ParentRelations.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Prefix.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_primaryKey.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_RejectChanges.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Reset.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_RowChanged.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_RowChanging.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_RowDeleted.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_RowDeleting.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Rows.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Select.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Select_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_Select_SSD.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_TableName.cs
-System.Data.Tests.Mainsoft/System.Data/DataTable/DataTable_ToString.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_Add.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_AddRange_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_CanRemove_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_CollectionChanged.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_CollectionChanging.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_Contains_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_CopyTo_AI.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_Count.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_GetEnumerator.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_IndexOf_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_IndexOf_S.cs
-System.Data.Tests.Mainsoft/System.Data/DataTableCollection/DataTableCollection_Item.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_AddNew.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_AllowDelete.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_AllowEdit.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_AllowNew.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_ApplyDefaultSort.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_CopyTo_AI.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_ctor.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_ctor_D.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_ctor_DSSD.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Delete_I.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Equals_O.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_FindRows_arrO.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_FindRows_O.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Find_arrO.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Find_O.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_GetEnumerator.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Item.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_ListChanged.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_RowFilter.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_RowStateFilter.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Sort.cs
-System.Data.Tests.Mainsoft/System.Data/DataView/DataView_Table.cs
System.Data.Tests.Mainsoft/System.Data/DeletedRowInaccessibleException/DeletedRowInaccessibleException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/DuplicateNameException/DuplicateNameException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/EvaluateException/EvaluateException_Generate.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_acceptRejectRule.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_Columns.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_constraintName.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_ctor_DclmsDclms.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_ctor_SDclmDclm.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_ctor_SDclmsDclms.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_deleteRule.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_Equals_O.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_extendedProperties.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_RelatedColumns.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_RelatedTable.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_Table.cs
-System.Data.Tests.Mainsoft/System.Data/ForeignKeyConstraint/ForeignKeyConstraint_ToString.cs
System.Data.Tests.Mainsoft/System.Data/InRowChangingEventException/InRowChangingEventException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/InvalidConstraintException/InvalidConstraintException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/NoNullAllowedException/NoNullAllowedException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/ReadOnlyException/ReadOnlyException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/RowNotInTableException/RowNotInTableException_Generate.cs
System.Data.Tests.Mainsoft/System.Data/SyntaxErrorException/SyntaxErrorException_Generate.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_Columns.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_constraintName.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_Dclm.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_DclmB.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_Dclms.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_DclmsB.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_SDclm.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_SDclmB.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_SDclms.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ctor_SDclmsB.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_Equals_O.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_extendedProperties.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_IsPrimaryKey.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_Table.cs
-System.Data.Tests.Mainsoft/System.Data/UniqueConstraint/UniqueConstraint_ToString.cs
+2005-07-12 Eyal Alalouf <eyala@mainsoft.com>
+
+ * DataRelationTest2.cs: Added file
+ * DataRowTest2.cs: Added file
+ * DataRowCollectionTest2.cs: Added file
+ * DataRowViewTest2.cs: Added file
+ * DataTableCollectionTest2.cs: Added file
+ * DataTableTest2.cs: Added file
+ * DataViewTest2.cs: Added file
+ * ForeignKeyConstraintTest2.cs: Added file
+ * UniqueConstraintTest2.cs: Added file
+
2005-07-12 Eyal Alalouf <eyala@mainsoft.com>
* DataRelationCollectionTest2.cs: Added file
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.ComponentModel;
+using System.Data;
+
+namespace MonoTests.System.Data
+{
+ [TestFixture] public class DataRelationTest2
+ {
+ [Test] public void ChildColumns()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // ChildColumns 1
+ Assert.AreEqual(1 , dRel.ChildColumns.Length , "DR1");
+
+ // ChildColumns 2
+ Assert.AreEqual(dtChild.Columns[0] , dRel.ChildColumns[0] , "DR2");
+ }
+
+ [Test] public void ChildKeyConstraint()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // ChildKeyConstraint 1
+ Assert.AreEqual(dtChild.Constraints[0] , dRel.ChildKeyConstraint, "DR3");
+ }
+
+ [Test] public void ChildTable()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // ChildTable
+ Assert.AreEqual(dtChild , dRel.ChildTable , "DR4");
+ }
+
+ [Test] public void DataSet()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // DataSet
+ Assert.AreEqual(ds , dRel.DataSet , "DR5");
+ }
+
+ [Test] public void ParentColumns()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // ParentColumns 1
+ Assert.AreEqual(1 , dRel.ParentColumns.Length , "DR6");
+
+ // ParentColumns 2
+ Assert.AreEqual(dtParent.Columns[0] , dRel.ParentColumns[0] , "DR7");
+ }
+
+ [Test] public void ParentKeyConstraint()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // ChildKeyConstraint 1
+ Assert.AreEqual(dtParent.Constraints[0] , dRel.ParentKeyConstraint , "DR8");
+ }
+
+ [Test] public void ParentTable()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // ParentTable
+ Assert.AreEqual(dtParent , dRel.ParentTable , "DR9");
+ }
+
+ [Test] public new void ToString()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation(null,dtParent.Columns[0],dtChild.Columns[0]);
+
+ // ToString 1
+ Assert.AreEqual(string.Empty , dRel.ToString() , "DR10");
+
+ ds.Relations.Add(dRel);
+
+ // ToString 2
+ Assert.AreEqual("Relation1", dRel.ToString() , "DR11");
+
+ dRel.RelationName = "myRelation";
+
+ // ToString 3
+ Assert.AreEqual("myRelation", dRel.ToString() , "DR12");
+ }
+
+ [Test] public void ctor_ByNameDataColumns()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // DataRelation - CTor
+ Assert.AreEqual(false , dRel == null , "DR13");
+
+ // DataRelation - parent Constraints
+ Assert.AreEqual(1, dtParent.Constraints.Count , "DR14");
+
+ // DataRelation - child Constraints
+ Assert.AreEqual(1, dtChild.Constraints.Count , "DR15");
+
+ // DataRelation - child relations
+ Assert.AreEqual(dRel, dtParent.ChildRelations[0] , "DR16");
+
+ // DataRelation - parent relations
+ Assert.AreEqual(dRel , dtChild.ParentRelations[0], "DR17");
+
+ // DataRelation - name
+ Assert.AreEqual("MyRelation" , dRel.RelationName , "DR18");
+
+ // DataRelation - parent UniqueConstraint
+ Assert.AreEqual(typeof(UniqueConstraint), dtParent.Constraints[0].GetType() , "DR19");
+
+ // DataRelation - Child ForeignKeyConstraint
+ Assert.AreEqual(typeof(ForeignKeyConstraint), dtChild.Constraints[0].GetType() , "DR20");
+
+ ds.Relations.Clear();
+ // Remove DataRelation - Parent Constraints
+ Assert.AreEqual(1, dtParent.Constraints.Count , "DR21");
+
+ // Remove DataRelation - Child Constraints
+ Assert.AreEqual(1, dtChild.Constraints.Count , "DR22");
+
+ // Remove DataRelation - child relations
+ Assert.AreEqual(0, dtParent.ChildRelations.Count , "DR23");
+
+ // Remove DataRelation - parent relations
+ Assert.AreEqual(0, dtChild.ParentRelations.Count , "DR24");
+
+ //add relation which will create invalid constraint
+ dtChild.Constraints.Clear();
+ dtParent.Constraints.Clear();
+ //add duplicated row
+ dtParent.Rows.Add(dtParent.Rows[0].ItemArray);
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+
+ // Add relation which will create invalid constraint
+ try {
+ ds.Relations.Add(dRel);
+ Assert.Fail("DR25: Add failed to throw ArgmentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DR26: Add. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void ctor_ByNameDataColumnsCreateConstraints()
+ {
+ DataRelation dRel;
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+
+ DataSet ds = new DataSet();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ //parameter createConstraints = true
+
+ bool createConstraints = true;
+ for (int i=0; i<=1; i++)
+ {
+ if (i==0)
+ createConstraints = false;
+ else
+ createConstraints = true;
+
+ ds.Relations.Clear();
+ dtParent.Constraints.Clear();
+ dtChild.Constraints.Clear();
+
+ //add duplicated row
+ dtParent.Rows.Add(dtParent.Rows[0].ItemArray);
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0],createConstraints);
+ // Add relation which will create invalid constraint
+ if (createConstraints==true)
+ {
+ try {
+ ds.Relations.Add(dRel);
+ Assert.Fail("DR27: Add failed to throw ArgmentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DR28: Add. Wrong exception type. Got:" + exc);
+ }
+ }
+ else
+ ds.Relations.Add(dRel);
+
+ dtParent.Rows.Remove(dtParent.Rows[dtParent.Rows.Count-1]);
+ ds.Relations.Clear();
+ dtParent.Constraints.Clear();
+ dtChild.Constraints.Clear();
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0],createConstraints);
+ ds.Relations.Add(dRel);
+
+ // DataRelation - CTor,createConstraints=
+ Assert.AreEqual(false , dRel == null , "DR29:" + createConstraints.ToString());
+
+ // DataRelation - parent Constraints,createConstraints=
+ Assert.AreEqual(i, dtParent.Constraints.Count , "DR30:" + createConstraints.ToString());
+
+ // DataRelation - child Constraints,createConstraints=
+ Assert.AreEqual(i, dtChild.Constraints.Count , "DR31:" + createConstraints.ToString());
+
+ // DataRelation - child relations,createConstraints=
+ Assert.AreEqual(dRel, dtParent.ChildRelations[0] , "DR32:" + createConstraints.ToString());
+
+ // DataRelation - parent relations,createConstraints=
+ Assert.AreEqual(dRel , dtChild.ParentRelations[0], "DR33:" + createConstraints.ToString());
+
+ // DataRelation - name
+ Assert.AreEqual("MyRelation" , dRel.RelationName , "DR34");
+ }
+ }
+
+ [Test] public void ctor_ByNameDataColumnsArrays()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+
+ //check some exception
+ // DataRelation - CTor ArgumentException, two columns child
+ try {
+ dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0]},new DataColumn[] {dtChild.Columns[0],dtChild.Columns[2]});
+ Assert.Fail("DR35: ctor failed to throw ArgmentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DR36: ctor. Wrong exception type. Got:" + exc);
+ }
+
+ dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0],dtParent.Columns[1]},new DataColumn[] {dtChild.Columns[0],dtChild.Columns[2]});
+ // DataRelation - Add Relation ArgumentException, fail on creating child Constraints
+ try {
+ ds.Relations.Add(dRel);
+ Assert.Fail("DR37: Add failed to throw ArgmentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DR38: Add. Wrong exception type. Got:" + exc);
+ }
+
+ // DataRelation ArgumentException - parent Constraints
+ Assert.AreEqual(1, dtParent.Constraints.Count , "DR39");
+
+ // DataRelation ArgumentException - child Constraints
+ Assert.AreEqual(0, dtChild.Constraints.Count , "DR40");
+
+ // DataRelation ArgumentException - DataSet.Relation count
+ Assert.AreEqual(1, ds.Relations.Count , "DR41");
+
+ //begin to check the relation ctor
+ dtParent.Constraints.Clear();
+ dtChild.Constraints.Clear();
+ ds.Relations.Clear();
+ dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0]},new DataColumn[] {dtChild.Columns[0]});
+ ds.Relations.Add(dRel);
+
+ // DataSet DataRelation count
+ Assert.AreEqual(1, ds.Relations.Count , "DR42");
+
+ // DataRelation - CTor
+ Assert.AreEqual(false , dRel == null , "DR43");
+
+ // DataRelation - parent Constraints
+ Assert.AreEqual(1, dtParent.Constraints.Count , "DR44");
+
+ // DataRelation - child Constraints
+ Assert.AreEqual(1, dtChild.Constraints.Count , "DR45");
+
+ // DataRelation - child relations
+ Assert.AreEqual(dRel, dtParent.ChildRelations[0] , "DR46");
+
+ // DataRelation - parent relations
+ Assert.AreEqual(dRel , dtChild.ParentRelations[0], "DR47");
+
+ // DataRelation - name
+ Assert.AreEqual("MyRelation" , dRel.RelationName , "DR48");
+ }
+
+ [Test] public void ctor_ByNameDataColumnsArraysCreateConstraints()
+ {
+ DataRelation dRel;
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+
+ DataSet ds = new DataSet();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ //parameter createConstraints = true
+
+ bool createConstraints = true;
+ for (int i=0; i<=1; i++)
+ {
+ if (i==0)
+ createConstraints = false;
+ else
+ createConstraints = true;
+
+ ds.Relations.Clear();
+ dtParent.Constraints.Clear();
+ dtChild.Constraints.Clear();
+
+ //add duplicated row
+ dtParent.Rows.Add(dtParent.Rows[0].ItemArray);
+ dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0]},new DataColumn[] {dtChild.Columns[0]},createConstraints);
+ // Add relation which will create invalid constraint
+ if (createConstraints==true)
+ {
+ try {
+ ds.Relations.Add(dRel);
+ Assert.Fail("DR49: Add failed to throw ArgmentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DR50: Add. Wrong exception type. Got:" + exc);
+ }
+ }
+ else
+ ds.Relations.Add(dRel);
+
+ ds.Relations.Clear();
+ dtParent.Constraints.Clear();
+ dtChild.Constraints.Clear();
+ dtParent.Rows.Remove(dtParent.Rows[dtParent.Rows.Count-1]);
+
+ dRel = new DataRelation("MyRelation",new DataColumn[] {dtParent.Columns[0]},new DataColumn[] {dtChild.Columns[0]},createConstraints);
+ ds.Relations.Add(dRel);
+
+ // DataRelation - CTor,createConstraints=
+ Assert.AreEqual(false, dRel == null, "DR51:" + createConstraints.ToString());
+
+ // DataRelation - parent Constraints,createConstraints=
+ Assert.AreEqual(i, dtParent.Constraints.Count , "DR52:" + createConstraints.ToString());
+
+ // DataRelation - child Constraints,createConstraints=
+ Assert.AreEqual(i, dtChild.Constraints.Count , "DR53:" + createConstraints.ToString());
+
+ // DataRelation - child relations,createConstraints=
+ Assert.AreEqual(dRel, dtParent.ChildRelations[0] , "DR54:" + createConstraints.ToString());
+
+ // DataRelation - parent relations,createConstraints=
+ Assert.AreEqual(dRel , dtChild.ParentRelations[0], "DR55:" + createConstraints.ToString());
+
+ // DataRelation - name
+ Assert.AreEqual("MyRelation" , dRel.RelationName , "DR56");
+ }
+ }
+
+ [Test] public void extendedProperties()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation("MyRelation",dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ PropertyCollection pc;
+ pc = dRel.ExtendedProperties ;
+
+ // Checking ExtendedProperties default
+ Assert.AreEqual(true, pc != null, "DR57");
+
+ // Checking ExtendedProperties count
+ Assert.AreEqual(0, pc.Count , "DR58");
+ }
+
+ [Test] public void nested()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation(null,dtParent.Columns[0],dtChild.Columns[0]);
+ ds.Relations.Add(dRel);
+
+ // Nested default
+ Assert.AreEqual(false, dRel.Nested , "DR59");
+
+ dRel.Nested = true;
+
+ // Nested get/set
+ Assert.AreEqual(true, dRel.Nested , "DR60");
+ }
+
+ [Test] public void relationName()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtChild = GHTUtils.DataProvider.CreateChildDataTable();
+ DataTable dtParent = GHTUtils.DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ DataRelation dRel;
+ dRel = new DataRelation(null,dtParent.Columns[0],dtChild.Columns[0]);
+
+ // RelationName default 1
+ Assert.AreEqual(string.Empty , dRel.RelationName , "DR61");
+
+ ds.Relations.Add(dRel);
+
+ // RelationName default 2
+ Assert.AreEqual("Relation1", dRel.RelationName , "DR62");
+
+ dRel.RelationName = "myRelation";
+
+ // RelationName get/set
+ Assert.AreEqual("myRelation", dRel.RelationName , "DR63");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.Collections;
+using System.ComponentModel;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests.System.Data
+{
+ [TestFixture] public class DataRowCollectionTest2
+ {
+ [Test] public void CopyTo()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataRow[] arr = new DataRow[dt.Rows.Count];
+ dt.Rows.CopyTo(arr,0);
+ Assert.AreEqual(dt.Rows.Count, arr.Length, "DRWC1");
+
+ int index=0;
+ foreach (DataRow dr in dt.Rows)
+ {
+ Assert.AreEqual(dr, arr[index], "DRWC2");
+ index++;
+ }
+ }
+
+ [Test] public void Count()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ Assert.AreEqual(6, dt.Rows.Count, "DRWC3");
+ dt.Rows.Remove(dt.Rows[0]);
+ Assert.AreEqual(5, dt.Rows.Count, "DRWC4");
+ dt.Rows.Add(new object[] {1,"1-String1","1-String2",new DateTime(2005,1,1,0,0,0,0),1.534,true});
+ Assert.AreEqual(6, dt.Rows.Count, "DRWC5");
+ }
+
+ [Test] public void GetEnumerator()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ IEnumerator myEnumerator = dt.Rows.GetEnumerator();
+ int index=0;
+ while (myEnumerator.MoveNext())
+ {
+ Assert.AreEqual(dt.Rows[index], (DataRow)myEnumerator.Current, "DRWC6");
+ index++;
+ }
+ Assert.AreEqual(index, dt.Rows.Count, "DRWC7");
+ }
+
+ [Test] public void RemoveAt_ByIndex()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ int counter = dt.Rows.Count;
+ dt.PrimaryKey= new DataColumn[] {dt.Columns[0]};
+ dt.Rows.RemoveAt(3);
+ Assert.AreEqual(counter-1, dt.Rows.Count, "DRWC8");
+ Assert.AreEqual(null, dt.Rows.Find(4), "DRWC9");
+ }
+
+ [Test] public void Remove_ByDataRow()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ int counter = dt.Rows.Count;
+ dt.PrimaryKey= new DataColumn[] {dt.Columns[0]};
+ Assert.AreEqual(dt.Rows[0], dt.Rows.Find(1), "DRWC10");
+ dt.Rows.Remove(dt.Rows[0]);
+ Assert.AreEqual(counter-1, dt.Rows.Count, "DRWC11");
+ Assert.AreEqual(null, dt.Rows.Find(1), "DRWC12");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.ComponentModel;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests.System.Data
+{
+ [TestFixture] public class DataRowTest2
+ {
+ [Test] public void AcceptChanges()
+ {
+ DataTable myTable = new DataTable("myTable");
+ DataRow myRow;
+ myRow = myTable.NewRow();
+ myTable.Rows.Add(myRow);
+
+ // DataRow AcceptChanges
+ // DataRowState.Added -> DataRowState.Unchanged
+ myTable.AcceptChanges();
+ Assert.AreEqual(DataRowState.Unchanged , myRow.RowState , "DRW1");
+ }
+
+ [Test] public void CancelEdit()
+ {
+ DataTable myTable = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Id",typeof(int));
+ dc.Unique=true;
+ myTable.Columns.Add(dc);
+ myTable.Rows.Add(new object[] {1});
+ myTable.Rows.Add(new object[] {2});
+ myTable.Rows.Add(new object[] {3});
+
+ DataRow myRow = myTable.Rows[0];
+ myRow.BeginEdit();
+ myRow[0] = 7;
+ myRow.CancelEdit();
+
+ // DataRow CancelEdit
+ Assert.AreEqual(true , (int)myRow[0] == 1, "DRW2");
+ }
+
+ [Test] public void ClearErrors()
+ {
+ DataTable dt = new DataTable("myTable");
+ DataRow dr = dt.NewRow();
+ dr.RowError = "err";
+
+ // DataRow ClearErrors
+ Assert.AreEqual(true , dr.HasErrors , "DRW3");
+
+ // DataRow ClearErrors
+ dr.ClearErrors();
+ Assert.AreEqual(false , dr.HasErrors , "DRW4");
+ }
+
+ [Test] public void Delete()
+ {
+ DataTable myTable = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Id",typeof(int));
+ dc.Unique=true;
+ myTable.Columns.Add(dc);
+ myTable.Rows.Add(new object[] {1});
+ myTable.Rows.Add(new object[] {2});
+ myTable.Rows.Add(new object[] {3});
+ myTable.AcceptChanges();
+
+ DataRow myRow = myTable.Rows[0];
+ myRow.Delete();
+
+ // Delete1
+ Assert.AreEqual(DataRowState.Deleted , myRow.RowState , "DRW5");
+
+ // Delete2
+ myTable.AcceptChanges();
+ Assert.AreEqual(DataRowState.Detached , myRow.RowState , "DRW6");
+ }
+
+ [Test] public void EndEdit()
+ {
+ DataTable myTable = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Id",typeof(int));
+ dc.Unique=true;
+ myTable.Columns.Add(dc);
+ myTable.Rows.Add(new object[] {1});
+ myTable.Rows.Add(new object[] {2});
+ myTable.Rows.Add(new object[] {3});
+
+ DataRow myRow = myTable.Rows[0];
+
+ int iProposed;
+ //After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available
+ myRow.BeginEdit();
+ myRow[0] = 7;
+ iProposed = (int)myRow[0,DataRowVersion.Proposed];
+ myRow.EndEdit();
+
+ // EndEdit
+ Assert.AreEqual(iProposed , (int)myRow[0,DataRowVersion.Current] , "DRW7");
+ }
+
+ [Test] public void Equals()
+ {
+ DataTable myTable = new DataTable("myTable");
+ DataRow dr1,dr2;
+ dr1 = myTable.NewRow();
+ dr2 = myTable.NewRow();
+
+ // not equals
+ Assert.AreEqual(false , dr1.Equals(dr2), "DRW8");
+
+ dr1=dr2;
+ // equals
+ Assert.AreEqual(true , dr1.Equals(dr2), "DRW9");
+ }
+
+ [Test] public void GetChildRows_ByDataRealtion()
+ {
+ DataRow dr;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ dr = dtParent.Rows[0];
+
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);
+ //Get Result
+ drArrResult = dr.GetChildRows(dRel);
+
+ // GetChildRows_D
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW10");
+ }
+
+ [Test] public void GetChildRows_ByDataRealtionDataRowVersion()
+ {
+ DataRow drParent;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ drParent = dtParent.Rows[0];
+
+ // Teting: DateTime.Now.ToShortTimeString()
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Current);
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW11");
+
+ // Teting: DataRow.GetParentRows_D_D
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Original );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW12");
+
+ // Teting: DataRow.GetParentRows_D_D
+ //Get Excepted result, in this case Current = Default
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Default );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW13");
+
+ // Teting: DataRow.GetParentRows_D_D
+ drParent.BeginEdit();
+ drParent["String1"] = "Value";
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Proposed );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW14");
+ }
+
+ [Test] public void GetChildRows_ByName()
+ {
+ DataRow dr;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ dr = dtParent.Rows[0];
+
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);
+ //Get Result
+ drArrResult = dr.GetChildRows("Parent-Child");
+
+ // GetChildRows_S
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW15");
+ }
+
+ [Test] public void GetChildRows_ByNameDataRowVersion()
+ {
+ DataRow drParent;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ drParent = dtParent.Rows[0];
+
+ // GetChildRows_SD 1
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Current);
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW16");
+
+ // GetChildRows_SD 2
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Original );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW17");
+
+ // GetParentRows_SD 3
+ //Get Excepted result, in this case Current = Default
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Default );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW18");
+
+ // GetParentRows_SD 4
+ drParent.BeginEdit();
+ drParent["String1"] = "Value";
+ //Get Excepted result
+ drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
+ //Get Result DataRowVersion.Current
+ drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Proposed );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW19");
+ }
+
+ [Test] public void GetColumnError_ByIndex()
+ {
+ string sColErr = "Error!";
+ DataTable dt = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Column1");
+ dt.Columns.Add(dc);
+ DataRow dr = dt.NewRow();
+
+ // GetColumnError 1
+ Assert.AreEqual(String.Empty , dr.GetColumnError(0) , "DRW20");
+
+ dr.SetColumnError(0,sColErr );
+
+ // GetColumnError 2
+ Assert.AreEqual(sColErr , dr.GetColumnError(0) , "DRW21");
+ }
+
+ [Test] public void GetColumnError_ByName()
+ {
+ string sColErr = "Error!";
+ DataTable dt = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Column1");
+ dt.Columns.Add(dc);
+ DataRow dr = dt.NewRow();
+
+ // GetColumnError 1
+ Assert.AreEqual(String.Empty , dr.GetColumnError("Column1") , "DRW22");
+
+ dr.SetColumnError("Column1",sColErr );
+
+ // GetColumnError 2
+ Assert.AreEqual(sColErr , dr.GetColumnError("Column1") , "DRW23");
+ }
+
+ [Test] public void GetColumnsInError()
+ {
+ string sColErr = "Error!";
+ DataColumn[] dcArr;
+ DataTable dt = new DataTable("myTable");
+ //init some columns
+ dt.Columns.Add(new DataColumn());
+ dt.Columns.Add(new DataColumn());
+ dt.Columns.Add(new DataColumn());
+ dt.Columns.Add(new DataColumn());
+ dt.Columns.Add(new DataColumn());
+
+ //init some rows
+ dt.Rows.Add(new object[] {});
+ dt.Rows.Add(new object[] {});
+ dt.Rows.Add(new object[] {});
+
+ DataRow dr = dt.Rows[1];
+
+ dcArr = dr.GetColumnsInError();
+
+ // GetColumnsInError 1
+ Assert.AreEqual(0, dcArr.Length , "DRW24");
+
+ dr.SetColumnError(0,sColErr);
+ dr.SetColumnError(2,sColErr);
+ dr.SetColumnError(4,sColErr);
+
+ dcArr = dr.GetColumnsInError();
+
+ // GetColumnsInError 2
+ Assert.AreEqual(3, dcArr.Length , "DRW25");
+
+ //check that the right columns taken
+ // GetColumnsInError 3
+ Assert.AreEqual(dt.Columns[0], dcArr[0], "DRW26");
+
+ // GetColumnsInError 4
+ Assert.AreEqual(dt.Columns[2], dcArr[1], "DRW27");
+
+ // GetColumnsInError 5
+ Assert.AreEqual(dt.Columns[4], dcArr[2], "DRW28");
+ }
+
+ [Test] public new void GetHashCode()
+ {
+ int iHashCode;
+ DataRow dr;
+ DataTable dt = new DataTable();
+ dr = dt.NewRow();
+
+ iHashCode = dr.GetHashCode();
+ for (int i=0; i<10; i++)
+ { //must return the same value each time
+ // GetHashCode #" + i
+ Assert.AreEqual(dr.GetHashCode() , iHashCode , "DRW29");
+ }
+ }
+
+ [Test] public void GetParentRow_ByDataRelation()
+ {
+ DataRow drExcepted,drResult,drChild;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent = DataProvider.CreateParentDataTable();
+
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ //Excepted result
+ drExcepted = dtParent.Rows[0];
+
+ //Get Result
+ drChild = dtChild.Select("ParentId=" + drExcepted["ParentId"])[0];
+ drResult = drChild.GetParentRow(dRel);
+
+ // GetParentRow_D
+ Assert.AreEqual(drExcepted.ItemArray, drResult.ItemArray , "DRW30");
+ }
+
+ [Test] public void GetParentRow_ByDataRelationDataRowVersion()
+ {
+ DataRow drParent,drChild;
+ DataRow drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ drParent = dtParent.Rows[0];
+ drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
+
+ // GetParentRow_DD 1
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Current);
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW31");
+
+ // GetParentRow_DD 2
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Original );
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW32");
+
+ // GetParentRow_DD 3
+ //Get Excepted result, in this case Current = Default
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Default );
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW33");
+
+ // GetParentRow_DD 4
+ drChild.BeginEdit();
+ drChild["String1"] = "Value";
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Proposed );
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW34");
+ }
+
+ [Test] public void GetParentRow_ByName()
+ {
+ DataRow drExcepted,drResult,drChild;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent = DataProvider.CreateParentDataTable();
+
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ //Excepted result
+ drExcepted = dtParent.Rows[0];
+
+ //Get Result
+ drChild = dtChild.Select("ParentId=" + drExcepted["ParentId"])[0];
+ drResult = drChild.GetParentRow("Parent-Child");
+
+ // GetParentRow_S
+ Assert.AreEqual(drExcepted.ItemArray, drResult.ItemArray , "DRW35");
+ }
+
+ [Test] public void GetParentRow_ByNameDataRowVersion()
+ {
+ DataRow drParent,drChild;
+ DataRow drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ drParent = dtParent.Rows[0];
+ drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
+
+ // GetParentRow_SD 1
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW36");
+
+ // GetParentRow_SD 2
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Original );
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW37");
+
+ // GetParentRow_SD 3
+ //Get Excepted result, in this case Current = Default
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Default );
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW38");
+
+ // GetParentRow_SD 4
+ drChild.BeginEdit();
+ drChild["String1"] = "Value";
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Proposed );
+ Assert.AreEqual(drArrExcepted.ItemArray, drArrResult.ItemArray , "DRW39");
+ }
+
+ [Test] public void GetParentRows_ByDataRelation()
+ {
+ DataRow dr;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent = DataProvider.CreateParentDataTable();
+
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ dr = dtParent.Rows[0];
+
+ //Duplicate several rows in order to create Many to Many relation
+ dtParent.ImportRow(dr);
+ dtParent.ImportRow(dr);
+ dtParent.ImportRow(dr);
+
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
+ ds.Relations.Add(dRel);
+ //Get Excepted result
+ drArrExcepted = dtParent.Select("ParentId=" + dr["ParentId"]);
+ dr = dtChild.Select("ParentId=" + dr["ParentId"])[0];
+ //Get Result
+ drArrResult = dr.GetParentRows(dRel);
+
+ // GetParentRows_D
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW40");
+ }
+
+ [Test] public void GetParentRows_ByName()
+ {
+ DataRow dr;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent = DataProvider.CreateParentDataTable();
+
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ dr = dtParent.Rows[0];
+
+ //Duplicate several rows in order to create Many to Many relation
+ dtParent.ImportRow(dr);
+ dtParent.ImportRow(dr);
+ dtParent.ImportRow(dr);
+
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
+ ds.Relations.Add(dRel);
+ //Get Excepted result
+ drArrExcepted = dtParent.Select("ParentId=" + dr["ParentId"]);
+ dr = dtChild.Select("ParentId=" + dr["ParentId"])[0];
+ //Get Result
+ drArrResult = dr.GetParentRows("Parent-Child");
+
+ // GetParentRows_S
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW41");
+ }
+
+ [Test] public void GetParentRows_ByNameDataRowVersion()
+ {
+ DataRow drParent,drChild;
+ DataRow[] drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
+ ds.Relations.Add(dRel);
+
+ //Create several copies of the first row
+ drParent = dtParent.Rows[0]; //row[0] has versions: Default,Current,Original
+ dtParent.ImportRow(drParent); //row[1] has versions: Default,Current,Original
+ dtParent.ImportRow(drParent); //row[2] has versions: Default,Current,Original
+ dtParent.ImportRow(drParent); //row[3] has versions: Default,Current,Original
+ dtParent.ImportRow(drParent); //row[4] has versions: Default,Current,Original
+ dtParent.ImportRow(drParent); //row[5] has versions: Default,Current,Original
+ dtParent.AcceptChanges();
+
+ //Get the first child row for drParent
+ drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
+
+ DataRow[] drTemp = dtParent.Select("ParentId=" + drParent["ParentId"]);
+ // Console.WriteLine("********");
+ // foreach (DataRow d in drTemp)
+ // {
+ // CheckRowVersion(d);
+ // }
+ drTemp[0].BeginEdit();
+ drTemp[0]["String1"] = "NewValue"; //row now has versions: Proposed,Current,Original,Default
+ drTemp[1].BeginEdit();
+ drTemp[1]["String1"] = "NewValue"; //row now has versions: Proposed,Current,Original,Default
+
+ // Console.WriteLine("********");
+ // foreach (DataRow d in drTemp)
+ // {
+ // CheckRowVersion(d);
+ // }
+ // Console.WriteLine("********");
+
+ // Check DataRowVersion.Current
+ //Check DataRowVersion.Current
+ drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
+ drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Current);
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW42");
+
+ //Check DataRowVersion.Current
+ // Teting: DataRow.GetParentRows_D_D ,DataRowVersion.Original
+ drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
+ drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Original );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW43");
+
+ //Check DataRowVersion.Default
+ // Teting: DataRow.GetParentRows_D_D ,DataRowVersion.Default
+ drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
+ drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Default );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW44");
+
+ /* .Net don't work as expected
+ //Check DataRowVersion.Proposed
+ // Teting: DataRow.GetParentRows_D_D ,DataRowVersion.Proposed
+ drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.ModifiedCurrent);
+ //drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.ModifiedOriginal );
+
+ drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Proposed );
+ Assert.AreEqual(drArrExcepted, drArrResult, "DRW45");
+ */
+ }
+
+ private void CheckRowVersion(DataRow dr)
+ {
+ Console.WriteLine("");
+ if (dr.HasVersion(DataRowVersion.Current)) Console.WriteLine("Has " + DataRowVersion.Current.ToString());
+ if (dr.HasVersion(DataRowVersion.Default)) Console.WriteLine("Has " + DataRowVersion.Default.ToString());
+ if (dr.HasVersion(DataRowVersion.Original)) Console.WriteLine("Has " + DataRowVersion.Original.ToString());
+ if (dr.HasVersion(DataRowVersion.Proposed)) Console.WriteLine("Has " + DataRowVersion.Proposed.ToString());
+ }
+
+ [Test] public new void GetType()
+ {
+ Type myType;
+ DataTable dt = new DataTable();
+ DataRow dr = dt.NewRow();
+ myType = typeof(DataRow);
+
+ // GetType
+ Assert.AreEqual(typeof(DataRow), myType , "DRW46");
+ }
+
+ [Test] public void HasErrors()
+ {
+ DataTable dt = new DataTable("myTable");
+ DataRow dr = dt.NewRow();
+
+ // HasErrors (default)
+ Assert.AreEqual(false, dr.HasErrors, "DRW47");
+
+ dr.RowError = "Err";
+
+ // HasErrors (set/get)
+ Assert.AreEqual(true , dr.HasErrors , "DRW48");
+ }
+
+ [Test] public void HasVersion_ByDataRowVersion()
+ {
+ DataTable t = new DataTable("atable");
+ t.Columns.Add("id", typeof(int));
+ t.Columns.Add("name", typeof(string));
+ t.Columns[0].DefaultValue = 1;
+ t.Columns[1].DefaultValue = "something";
+
+ // row r is detached
+ DataRow r = t.NewRow();
+
+ // HasVersion Test #10
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW49");
+
+ // HasVersion Test #11
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW50");
+
+ // HasVersion Test #12
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW51");
+
+ // HasVersion Test #13
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Proposed) , "DRW52");
+
+ r[0] = 4;
+ r[1] = "four";
+
+ // HasVersion Test #20
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW53");
+
+ // HasVersion Test #21
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW54");
+
+ // HasVersion Test #22
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW55");
+
+ // HasVersion Test #23
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Proposed) , "DRW56");
+
+ t.Rows.Add(r);
+ // now it is "added"
+
+ // HasVersion Test #30
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW57");
+
+ // HasVersion Test #31
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW58");
+
+ // HasVersion Test #32
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW59");
+
+ // HasVersion Test #33
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW60");
+
+ t.AcceptChanges();
+ // now it is "unchanged"
+
+ // HasVersion Test #40
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW61");
+
+ // HasVersion Test #41
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW62");
+
+ // HasVersion Test #42
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW63");
+
+ // HasVersion Test #43
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW64");
+
+ r.BeginEdit();
+ r[1] = "newvalue";
+
+ // HasVersion Test #50
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW65");
+
+ // HasVersion Test #51
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW66");
+
+ // HasVersion Test #52
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW67");
+
+ // HasVersion Test #53
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Proposed) , "DRW68");
+
+ r.EndEdit();
+ // now it is "modified"
+ // HasVersion Test #60
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW69");
+
+ // HasVersion Test #61
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW70");
+
+ // HasVersion Test #62
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW71");
+
+ // HasVersion Test #63
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW72");
+
+ // this or t.AcceptChanges
+ r.AcceptChanges();
+ // now it is "unchanged" again
+ // HasVersion Test #70
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW73");
+
+ // HasVersion Test #71
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW74");
+
+ // HasVersion Test #72
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW75");
+
+ // HasVersion Test #73
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW76");
+
+ r.Delete();
+ // now it is "deleted"
+
+ // HasVersion Test #80
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW77");
+
+ // HasVersion Test #81
+ Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW78");
+
+ // HasVersion Test #82
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Default) , "DRW79");
+
+ // HasVersion Test #83
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW80");
+
+ r.AcceptChanges();
+ // back to detached
+ // HasVersion Test #90
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW81");
+
+ // HasVersion Test #91
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW82");
+
+ // HasVersion Test #92
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Default) , "DRW83");
+
+ // HasVersion Test #93
+ Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW84");
+ }
+
+ [Test] public void IsNull_ByDataColumn()
+ {
+ DataTable dt = new DataTable();
+ DataColumn dc0 = new DataColumn("Col0",typeof(int));
+ DataColumn dc1 = new DataColumn("Col1",typeof(int));
+ dt.Columns.Add(dc0);
+ dt.Columns.Add(dc1);
+ dt.Rows.Add(new object[] {1234});
+ DataRow dr = dt.Rows[0];
+
+ // IsNull_I 2
+ Assert.AreEqual(false , dr.IsNull(dc0) , "DRW85");
+
+ // IsNull_I 2
+ Assert.AreEqual(true , dr.IsNull(dc1) , "DRW86");
+ }
+
+ [Test] public void IsNull_ByDataColumnDataRowVersion()
+ {
+ DataTable dt = new DataTable();
+ DataColumn dc0 = new DataColumn("Col0",typeof(int));
+ DataColumn dc1 = new DataColumn("Col1",typeof(int));
+ dt.Columns.Add(dc0);
+ dt.Columns.Add(dc1);
+ dt.Rows.Add(new object[] {1234});
+ DataRow dr = dt.Rows[0];
+
+ // IsNull - col0 Current
+ Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Current) , "DRW87");
+
+ // IsNull - col1 Current
+ Assert.AreEqual(true, dr.IsNull(dc1,DataRowVersion.Current) , "DRW88");
+
+ // IsNull - col0 Default
+ Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Default) , "DRW89");
+ // IsNull - col1 Default
+ Assert.AreEqual(true, dr.IsNull(dc1,DataRowVersion.Default) , "DRW90");
+
+ dr.BeginEdit();
+ dr[0] = 9; //Change value, Create RowVersion Proposed
+
+ // IsNull - col0 Proposed
+ Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Proposed) , "DRW91");
+ // IsNull - col1 Proposed
+ Assert.AreEqual(true, dr.IsNull(dc1,DataRowVersion.Proposed) , "DRW92");
+
+ dr.AcceptChanges();
+ dr.Delete();
+
+ // IsNull - col0 Original
+ Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Original) , "DRW93");
+ }
+
+ [Test] public void IsNull_ByIndex()
+ {
+ DataTable dt = new DataTable();
+ DataColumn dc0 = new DataColumn("Col0",typeof(int));
+ DataColumn dc1 = new DataColumn("Col1",typeof(int));
+ dt.Columns.Add(dc0);
+ dt.Columns.Add(dc1);
+ dt.Rows.Add(new object[] {1234});
+ DataRow dr = dt.Rows[0];
+
+ // IsNull_I 2
+ Assert.AreEqual(false , dr.IsNull(0) , "DRW94");
+
+ // IsNull_I 2
+ Assert.AreEqual(true , dr.IsNull(1) , "DRW95");
+ }
+
+ [Test] public void IsNull_ByName()
+ {
+ DataTable dt = new DataTable();
+ DataColumn dc0 = new DataColumn("Col0",typeof(int));
+ DataColumn dc1 = new DataColumn("Col1",typeof(int));
+ dt.Columns.Add(dc0);
+ dt.Columns.Add(dc1);
+ dt.Rows.Add(new object[] {1234});
+ DataRow dr = dt.Rows[0];
+
+#region --- assignment ----
+ // IsNull_S 1
+ Assert.AreEqual(false, dr.IsNull("Col0"), "DRW96");
+
+ // IsNull_S 2
+ Assert.AreEqual(true, dr.IsNull("Col1"), "DRW97");
+#endregion
+
+#region --- bug 3124 ---
+
+ // IsNull_S 1
+ MemoryStream st = new MemoryStream();
+ StreamWriter sw = new StreamWriter(st);
+ sw.Write("<?xml version=\"1.0\" standalone=\"yes\"?><NewDataSet>");
+ sw.Write("<Table><EmployeeNo>9</EmployeeNo></Table>");
+ sw.Write("</NewDataSet>");
+ sw.Flush();
+ st.Position=0;
+ DataSet ds = new DataSet();
+ ds.ReadXml(st);
+ // Here we add the expression column
+ ds.Tables[0].Columns.Add("ValueListValueMember", typeof(object), "EmployeeNo");
+
+ foreach( DataRow row in ds.Tables[0].Rows )
+ {
+ // Console.WriteLine(row["ValueListValueMember"].ToString() + " " );
+ if( row.IsNull("ValueListValueMember") == true )
+ Assert.AreEqual("Failed", "SubTest", "DRW98");
+ else
+ Assert.AreEqual("Passed", "Passed", "DRW99");
+ }
+
+#endregion
+ }
+
+ [Test] public void Item()
+ {
+ // init table with columns
+ DataTable myTable = new DataTable("myTable");
+
+ myTable.Columns.Add(new DataColumn("Id",typeof(int)));
+ myTable.Columns.Add(new DataColumn("Name",typeof(string)));
+ DataColumn dc = myTable.Columns[0];
+
+ myTable.Rows.Add(new object[] {1,"Ofer"});
+ myTable.Rows.Add(new object[] {2,"Ofer"});
+
+ myTable.AcceptChanges();
+
+ DataRow myRow = myTable.Rows[0];
+
+ //Start checking
+
+ // Item - index
+ Assert.AreEqual(1 , (int)myRow[0] , "DRW100");
+
+ // Item - string
+ Assert.AreEqual(1 , (int)myRow["Id"] , "DRW101");
+
+ // Item - Column
+ Assert.AreEqual(1 , (int)myRow[dc] , "DRW102");
+
+ // Item - index,Current
+ Assert.AreEqual(1 , (int)myRow[0,DataRowVersion.Current ] , "DRW103");
+
+ // Item - string,Current
+ Assert.AreEqual(1 , (int)myRow["Id",DataRowVersion.Current] , "DRW104");
+
+ // Item - columnn,Current
+ Assert.AreEqual(1 , (int)myRow[dc,DataRowVersion.Current] , "DRW105");
+
+ // testMore();
+ }
+
+ /*public void testMore()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ dt.Rows[0].BeginEdit();
+ dt.Rows[0][0] = 10;
+ dt.Rows[0].EndEdit();
+ dt.AcceptChanges();
+ }*/
+
+ [Test] public void RejectChanges()
+ {
+ DataTable dt = new DataTable();
+ DataColumn dc0 = new DataColumn("Col0",typeof(int));
+ DataColumn dc1 = new DataColumn("Col1",typeof(int));
+ dt.Columns.Add(dc0);
+ dt.Columns.Add(dc1);
+ dt.Rows.Add(new object[] {1234});
+ dt.AcceptChanges();
+ DataRow dr = dt.Rows[0];
+
+ dr[0] = 567;
+ dr[1] = 789;
+ dr.RejectChanges();
+
+ // RejectChanges - row 0
+ Assert.AreEqual(1234 , (int)dr[0], "DRW106");
+
+ // RejectChanges - row 1
+ Assert.AreEqual(DBNull.Value , dr[1] , "DRW107");
+
+ dr.Delete();
+ dr.RejectChanges();
+
+ // RejectChanges - count
+ Assert.AreEqual(1 , dt.Rows.Count , "DRW108");
+ }
+
+ [Test] public void RowState()
+ {
+ DataTable myTable = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Name",typeof(string));
+ myTable.Columns.Add(dc);
+ DataRow myRow;
+
+ // Create a new DataRow.
+ myRow = myTable.NewRow();
+
+ // Detached row.
+
+ // Detached
+ Assert.AreEqual(DataRowState.Detached , myRow.RowState , "DRW109");
+
+ myTable.Rows.Add(myRow);
+ // New row.
+
+ // Added
+ Assert.AreEqual(DataRowState.Added , myRow.RowState , "DRW110");
+
+ myTable.AcceptChanges();
+ // Unchanged row.
+
+ // Unchanged
+ Assert.AreEqual(DataRowState.Unchanged , myRow.RowState , "DRW111");
+
+ myRow["Name"] = "Scott";
+ // Modified row.
+
+ // Modified
+ Assert.AreEqual(DataRowState.Modified , myRow.RowState , "DRW112");
+
+ myRow.Delete();
+ // Deleted row.
+
+ // Deleted
+ Assert.AreEqual(DataRowState.Deleted , myRow.RowState , "DRW113");
+ }
+
+ [Test] public void SetColumnError_ByDataColumnError()
+ {
+ string sColErr = "Error!";
+ DataTable dt = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Column1");
+ dt.Columns.Add(dc);
+ DataRow dr = dt.NewRow();
+
+ // empty string
+ Assert.AreEqual(String.Empty, dr.GetColumnError(dc) , "DRW114");
+
+ dr.SetColumnError(dc,sColErr );
+
+ // error string
+ Assert.AreEqual(sColErr, dr.GetColumnError(dc) , "DRW115");
+ }
+
+ [Test] public void SetColumnError_ByIndexError()
+ {
+ string sColErr = "Error!";
+ DataTable dt = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Column1");
+ dt.Columns.Add(dc);
+ DataRow dr = dt.NewRow();
+
+ // empty string
+ Assert.AreEqual(String.Empty , dr.GetColumnError(0) , "DRW116");
+
+ dr.SetColumnError(0,sColErr );
+
+ // error string
+ Assert.AreEqual(sColErr , dr.GetColumnError(0) , "DRW117");
+ }
+
+ [Test] public void SetColumnError_ByColumnNameError()
+ {
+ string sColErr = "Error!";
+ DataTable dt = new DataTable("myTable");
+ DataColumn dc = new DataColumn("Column1");
+ dt.Columns.Add(dc);
+ DataRow dr = dt.NewRow();
+
+ // empty string
+ Assert.AreEqual(String.Empty, dr.GetColumnError("Column1") , "DRW118");
+
+ dr.SetColumnError("Column1",sColErr );
+
+ // error string
+ Assert.AreEqual(sColErr, dr.GetColumnError("Column1") , "DRW119");
+ }
+
+ [Test] public void SetParentRow_ByDataRow()
+ {
+ DataRow drParent,drChild;
+ DataRow drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ drParent = dtParent.Rows[0];
+ drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
+
+ drChild.SetParentRow(drParent);
+
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
+
+ // SetParentRow
+ Assert.AreEqual(drArrExcepted , drArrResult, "DRW120");
+ }
+
+ public void testMore()
+ {
+ DataSet ds = DataProvider.CreateForigenConstraint();
+ DataRow drParent = ds.Tables[0].Rows[0];
+ //DataRow[] drArray = ds.Tables[1].Rows[0].GetParentRows(ds.Tables[1].ParentRelations[0]);
+ ds.Tables[1].Rows[0].SetParentRow(drParent);
+ }
+
+ public void test()
+ {
+ // test SetParentRow
+ DataTable parent = DataProvider.CreateParentDataTable();
+ DataTable child = DataProvider.CreateChildDataTable();
+ DataRow dr = parent.Rows[0];
+ dr.Delete();
+ parent.AcceptChanges();
+
+ child.Rows[0].SetParentRow(dr);
+ }
+
+ public void checkForLoops()
+ {
+ DataSet ds = new DataSet();
+ //Create tables
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ DataTable dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+
+ dtChild.Rows.Clear();
+ dtParent.Rows.Clear();
+
+ dtParent.ChildRelations.Add(dtParent.Columns[0],dtChild.Columns[0]);
+ dtChild.ChildRelations.Add(dtChild.Columns[0],dtParent.Columns[0]);
+
+ dtChild.Rows[0].SetParentRow(dtParent.Rows[0]);
+ dtParent.Rows[0].SetParentRow(dtChild.Rows[0]);
+ }
+
+ public void checkForLoopsAdvenced()
+ {
+ //Create tables
+ DataTable dtChild = new DataTable();
+ dtChild.Columns.Add("Col1",typeof(int));
+ dtChild.Columns.Add("Col2",typeof(int));
+
+ DataRelation drl = new DataRelation("drl1",dtChild.Columns[0],dtChild.Columns[1]);
+ dtChild.ChildRelations.Add(drl);
+ dtChild.Rows[0].SetParentRow(dtChild.Rows[1]);
+ dtChild.Rows[1].SetParentRow(dtChild.Rows[0]);
+ }
+
+ [Test] public void SetParentRow_ByDataRowDataRelation()
+ {
+ DataRow drParent,drChild;
+ DataRow drArrExcepted,drArrResult;
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+ //Add Relation
+ DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(dRel);
+
+ drParent = dtParent.Rows[0];
+ drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
+
+ drChild.SetParentRow(drParent ,dRel);
+
+ //Get Excepted result
+ drArrExcepted = drParent;
+ //Get Result DataRowVersion.Current
+ drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
+
+ // SetParentRow
+ Assert.AreEqual(drArrExcepted , drArrResult, "DRW121");
+ }
+
+ [Test] public void Table()
+ {
+ DataTable dt1,dt2;
+ dt2 = new DataTable("myTable");
+ DataRow dr = dt2.NewRow();
+ dt1 = dr.Table;
+
+ // ctor
+ Assert.AreEqual(dt2, dt1 , "DRW122");
+ }
+
+ [Test] public new void ToString()
+ {
+ DataRow dr;
+ DataTable dtParent;
+ dtParent= DataProvider.CreateParentDataTable();
+ dr = dtParent.Rows[0];
+
+ // ToString
+ Assert.AreEqual(true, dr.ToString().ToLower().StartsWith("system.data.datarow") , "DRW123");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.ComponentModel;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests.System.Data
+{
+ [TestFixture] public class DataRowViewTest2
+ {
+ [Test] public void BeginEdit()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ drv.BeginEdit();
+ drv["String1"] = "ChangeValue";
+
+ // check Proposed value
+ Assert.AreEqual("ChangeValue" , dt.Rows[0]["String1",DataRowVersion.Proposed] , "DRV1");
+
+ // check Original value
+ Assert.AreEqual("1-String1" , dt.Rows[0]["String1",DataRowVersion.Original ] , "DRV2");
+
+ // check IsEdit
+ Assert.AreEqual(true, drv.IsEdit , "DRV3");
+
+ // check IsEdit - change another row
+ dv[1]["String1"] = "something";
+ Assert.AreEqual(true, drv.IsEdit , "DRV4");
+ }
+
+ [Test] public void CancelEdit()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ drv.BeginEdit();
+ drv["String1"] = "ChangeValue";
+
+ // check Proposed value
+ Assert.AreEqual("ChangeValue" , dt.Rows[0]["String1",DataRowVersion.Proposed] , "DRV5");
+
+ // check IsEdit
+ Assert.AreEqual(true, drv.IsEdit , "DRV6");
+
+ // check Proposed value
+ drv.CancelEdit();
+ Assert.AreEqual(false, dt.Rows[0].HasVersion(DataRowVersion.Proposed) , "DRV7");
+
+ // check current value
+ Assert.AreEqual("1-String1" , dt.Rows[0]["String1",DataRowVersion.Current ] , "DRV8");
+
+ // check IsEdit after cancel edit
+ Assert.AreEqual(false, drv.IsEdit , "DRV9");
+ }
+
+ [Test] public void CreateChildView_ByDataRelation()
+ {
+ //create a dataset with two tables, with a DataRelation between them
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ DataSet ds = new DataSet();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ DataRelation drel = new DataRelation("ParentChild",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(drel);
+
+ //DataView dvChild = null;
+ DataView dvParent = new DataView(dtParent);
+
+ DataView dvTmp1 = dvParent[0].CreateChildView(drel);
+ DataView dvTmp2 = dvParent[3].CreateChildView(drel);
+
+ // ChildView != null
+ Assert.AreEqual(true, dvTmp1!=null, "DRV10");
+
+ // Child view table = ChildTable
+ Assert.AreEqual(dtChild , dvTmp1.Table , "DRV11");
+
+ // ChildView1.Table = ChildView2.Table
+ Assert.AreEqual(dvTmp2.Table, dvTmp1.Table , "DRV12");
+
+ //the child dataview are different
+ // Child DataViews different
+ Assert.AreEqual(false, dvTmp1.Equals(dvTmp2), "DRV13");
+ }
+
+ [Test] public void CreateChildView_ByName()
+ {
+ //create a dataset with two tables, with a DataRelation between them
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ DataSet ds = new DataSet();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ DataRelation drel = new DataRelation("ParentChild",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+ ds.Relations.Add(drel);
+
+ //DataView dvChild = null;
+ DataView dvParent = new DataView(dtParent);
+
+ DataView dvTmp1 = dvParent[0].CreateChildView("ParentChild");
+ DataView dvTmp2 = dvParent[3].CreateChildView("ParentChild");
+
+ // ChildView != null
+ Assert.AreEqual(true, dvTmp1!=null, "DRV14");
+
+ // Child view table = ChildTable
+ Assert.AreEqual(dtChild , dvTmp1.Table , "DRV15");
+
+ // ChildView1.Table = ChildView2.Table
+ Assert.AreEqual(dvTmp2.Table, dvTmp1.Table , "DRV16");
+
+ //the child dataview are different
+ // Child DataViews different
+ Assert.AreEqual(false, dvTmp1.Equals(dvTmp2), "DRV17");
+ }
+
+ [Test] public void DataView()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv1 = dv[0];
+ DataRowView drv2 = dv[4];
+
+ // check DataRowView.DataView
+ Assert.AreEqual(dv, drv1.DataView , "DRV18");
+
+ // compare DataRowView.DataView
+ Assert.AreEqual(drv2.DataView, drv1.DataView , "DRV19");
+
+ //check that the DataRowView still has the same DataView even when the source table changed
+ // check that the DataRowView still has the same DataView
+ dv.Table = null;
+
+ // Console.WriteLine("*********" + (drv1.DataView == null));
+ Assert.AreEqual(true, drv1.DataView == dv , "DRV20");
+
+ //check that the DataRowView has a new DataView
+ // check that the DataRowView has a new DataView
+ dv = new DataView();
+ Assert.AreEqual(false, drv1.DataView.Equals(dv) , "DRV21");
+ }
+
+ [Test] public void Delete()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+ int TableRowsCount = dt.Rows.Count;
+ int ViewRowCount = dv.Count;
+
+ // DataView Count
+ drv.Delete();
+ Assert.AreEqual(dv.Count, ViewRowCount-1, "DRV22");
+
+ //the table count should stay the same until EndEdit is invoked
+ // Table Count
+ Assert.AreEqual(TableRowsCount, dt.Rows.Count, "DRV23");
+
+ // DataRowState deleted
+ Assert.AreEqual(DataRowState.Deleted , drv.Row.RowState , "DRV24");
+ }
+
+ [Test] public void EndEdit()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ drv.BeginEdit();
+ drv["String1"] = "ChangeValue";
+
+ //the row should be stay in edit mode event if changing other rows
+ // check IsEdit - change another row
+ dv[1]["String1"] = "something";
+ Assert.AreEqual(true, drv.IsEdit , "DRV25");
+
+ // check if has Proposed version
+ drv.EndEdit();
+ Assert.AreEqual(false, dt.Rows[0].HasVersion(DataRowVersion.Proposed) , "DRV26");
+
+ // check Current value
+ Assert.AreEqual("ChangeValue" , dt.Rows[0]["String1",DataRowVersion.Current] , "DRV27");
+
+ // check IsEdit
+ Assert.AreEqual(false, drv.IsEdit , "DRV28");
+ }
+
+ [Test] public void Equals()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView d1 = dv[0];
+ DataRowView d2 = dv[0];
+
+ // DataRowView.Equals
+ Assert.AreEqual(d2, d1, "DRV29");
+ }
+
+ [Test] public void IsEdit()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ // default value
+ Assert.AreEqual(false, drv.IsEdit, "DRV30");
+
+ // after BeginEdit
+ drv.BeginEdit();
+ Assert.AreEqual(true, drv.IsEdit, "DRV31");
+
+ // after CancelEdit
+ drv.CancelEdit();
+ Assert.AreEqual(false, drv.IsEdit, "DRV32");
+
+ // after BeginEdit again
+ drv.BeginEdit();
+ Assert.AreEqual(true, drv.IsEdit, "DRV33");
+
+ // after EndEdit
+ drv.EndEdit();
+ Assert.AreEqual(false, drv.IsEdit, "DRV34");
+ }
+
+ [Test] public void IsNew()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ // existing row
+ Assert.AreEqual(false, drv.IsNew , "DRV35");
+
+ // add new row
+ drv = dv.AddNew();
+ Assert.AreEqual(true, drv.IsNew , "DRV36");
+ }
+
+ [Test] public void Item()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ // Item 0
+ Assert.AreEqual(dt.Rows[0][0], drv[0], "DRV37");
+
+ // Item 4
+ Assert.AreEqual(dt.Rows[0][4], drv[4], "DRV38");
+
+ // Item -1 - excpetion
+ try {
+ object o = drv[-1];
+ Assert.Fail("DRV39: Indexer Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DRV40: Indexer. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void Item_Property()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ DataRowView drv = dv[0];
+
+ // Item 'ParentId'
+ Assert.AreEqual(dt.Rows[0]["ParentId"], drv["ParentId"], "DRV41");
+
+ // Item 'ParentDateTime'
+ Assert.AreEqual(dt.Rows[0]["ParentDateTime"], drv["ParentDateTime"], "DRV42");
+
+ // Item invalid - excpetion
+ try {
+ object o = drv["something"];
+ Assert.Fail("DRV43: Indexer Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DRV44: Indexer. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void Row()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+ DataRowView drv = null;
+
+ // Compare DataRowView.Row to table row
+ drv = dv[3];
+ Assert.AreEqual(dt.Rows[3], drv.Row, "DRV45");
+ }
+
+ [Test] public void RowVersion()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+ dt.Columns[1].DefaultValue = "default";
+ DataRowView drv = dv[0];
+
+ dt.Rows.Add(new object[] {99});
+ dt.Rows[1].Delete();
+ dt.Rows[2].BeginEdit();
+ dt.Rows[2][1] = "aaa";
+
+ dv.RowStateFilter=DataViewRowState.CurrentRows ;
+ // check Current
+ Assert.AreEqual(DataRowVersion.Current, drv.RowVersion, "DRV46");
+
+ dv.RowStateFilter=DataViewRowState.Deleted ;
+ // check Original
+ Assert.AreEqual(DataRowVersion.Original , drv.RowVersion, "DRV47");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests_System.Data
+{
+ [TestFixture] public class DataTableCollectionTest2
+ {
+ private int counter = 0;
+
+ [Test] public void Add()
+ {
+ // Adding computed column to a data set
+ DataSet ds = new DataSet();
+ ds.Tables.Add(new DataTable("Table"));
+ ds.Tables[0].Columns.Add(new DataColumn("EmployeeNo", typeof(string)));
+ ds.Tables[0].Rows.Add(new object[] {"Maciek"});
+ ds.Tables[0].Columns.Add("ComputedColumn", typeof(object), "EmployeeNo");
+
+ Assert.AreEqual("EmployeeNo", ds.Tables[0].Columns["ComputedColumn"].Expression, "DTC1");
+ }
+
+ [Test]
+ public void AddTwoTables()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add();
+ Assert.AreEqual("Table1", ds.Tables[0].TableName , "DTC2");
+ //Assert.AreEqual(ds.Tables[0].TableName,"Table1");
+ ds.Tables.Add();
+ Assert.AreEqual("Table2", ds.Tables[1].TableName , "DTC3");
+ //Assert.AreEqual(ds.Tables[1].TableName,"Table2");
+ }
+
+ [Test]
+ public void AddRange()
+ {
+ DataSet ds = new DataSet();
+
+ DataTable[] arr = new DataTable[2];
+
+ arr[0] = new DataTable("NewTable1");
+ arr[1] = new DataTable("NewTable2");
+
+ ds.Tables.AddRange(arr);
+ Assert.AreEqual("NewTable1", ds.Tables[0].TableName, "DTC4");
+ Assert.AreEqual("NewTable2", ds.Tables[1].TableName, "DTC5");
+ }
+ [Test]
+ public void AddRange_NullValue()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.AddRange(null);
+ }
+
+ [Test]
+ public void AddRange_ArrayWithNull()
+ {
+ DataSet ds = new DataSet();
+ DataTable[] arr = new DataTable[2];
+ arr[0] = new DataTable("NewTable1");
+ arr[1] = (DataTable)null ;
+ ds.Tables.AddRange(arr);
+ Assert.AreEqual("NewTable1", ds.Tables[0].TableName, "DTC6");
+ Assert.AreEqual(1, ds.Tables.Count, "DTC7");
+ }
+
+ [Test]
+ public void CanRemove()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add();
+ Assert.AreEqual(true, ds.Tables.CanRemove(ds.Tables[0]), "DTC8");
+ }
+
+ [Test]
+ public void CanRemove_NullValue()
+ {
+ DataSet ds = new DataSet();
+ Assert.AreEqual(false, ds.Tables.CanRemove(null), "DTC9");
+ }
+
+ [Test]
+ public void CanRemove_TableDoesntBelong()
+ {
+ DataSet ds = new DataSet();
+ DataSet ds1 = new DataSet();
+ ds1.Tables.Add();
+ Assert.AreEqual(false, ds.Tables.CanRemove(ds1.Tables[0]), "DTC10");
+ }
+
+ [Test]
+ public void CanRemove_PartOfRelation()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add(DataProvider.CreateParentDataTable());
+ ds.Tables.Add(DataProvider.CreateChildDataTable());
+
+ ds.Relations.Add("rel",ds.Tables[0].Columns["ParentId"],ds.Tables[1].Columns["ParentId"],false);
+
+ Assert.AreEqual(false, ds.Tables.CanRemove(ds.Tables[0]), "DTC11");
+ Assert.AreEqual(false, ds.Tables.CanRemove(ds.Tables[1]), "DTC12");
+ }
+ [Test]
+ public void CanRemove_PartOfConstraint()
+ {
+ DataSet ds = DataProvider.CreateForigenConstraint();
+ Assert.AreEqual(false, ds.Tables.CanRemove(ds.Tables[0]), "DTC13"); //Unique
+ Assert.AreEqual(false, ds.Tables.CanRemove(ds.Tables[1]), "DTC14"); //Foreign
+ }
+
+ [Test]
+ public void CollectionChanged()
+ {
+ counter = 0;
+ DataSet ds = new DataSet();
+ ds.Tables.CollectionChanged+=new System.ComponentModel.CollectionChangeEventHandler(Tables_CollectionChanged);
+ ds.Tables.Add();
+ ds.Tables.Add();
+ Assert.AreEqual(2, counter, "DTC15");
+
+ ds.Tables.Remove(ds.Tables[0]);
+ ds.Tables.Remove(ds.Tables[0]);
+ Assert.AreEqual(4, counter, "DTC16");
+ }
+
+ private void Tables_CollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e)
+ {
+ counter++;
+ }
+
+ [Test]
+ public void CollectionChanging()
+ {
+ counter = 0;
+ DataSet ds = new DataSet();
+ ds.Tables.CollectionChanging+=new System.ComponentModel.CollectionChangeEventHandler(Tables_CollectionChanging);
+ ds.Tables.Add();
+ ds.Tables.Add();
+ Assert.AreEqual(2, counter, "DTC17");
+
+ ds.Tables.Remove(ds.Tables[0]);
+ ds.Tables.Remove(ds.Tables[0]);
+ Assert.AreEqual(4, counter, "DTC18");
+ }
+
+ private void Tables_CollectionChanging(object sender, System.ComponentModel.CollectionChangeEventArgs e)
+ {
+ counter++;
+ }
+
+ [Test]
+ public void Contains()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add("NewTable1");
+ ds.Tables.Add("NewTable2");
+
+ Assert.AreEqual(true, ds.Tables.Contains("NewTable1"), "DTC19");
+ Assert.AreEqual(true, ds.Tables.Contains("NewTable2"), "DTC20");
+ Assert.AreEqual(false, ds.Tables.Contains("NewTable3"), "DTC21");
+
+ ds.Tables["NewTable1"].TableName = "Tbl1";
+ Assert.AreEqual(false, ds.Tables.Contains("NewTable1"), "DTC22");
+ Assert.AreEqual(true, ds.Tables.Contains("Tbl1"), "DTC23");
+ }
+
+ [Test]
+ public void CopyTo()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add();
+ ds.Tables.Add();
+ DataTable[] arr = new DataTable[2];
+ ds.Tables.CopyTo(arr,0);
+ Assert.AreEqual("Table1", ((DataTable)arr[0]).TableName, "DTC24");
+ Assert.AreEqual("Table2", ((DataTable)arr[1]).TableName, "DTC25");
+ }
+
+ [Test]
+ public void Count()
+ {
+ DataSet ds = new DataSet();
+ Assert.AreEqual(0, ds.Tables.Count, "DTC26");
+
+ ds.Tables.Add();
+ Assert.AreEqual(1, ds.Tables.Count, "DTC27");
+
+ ds.Tables.Add();
+ Assert.AreEqual(2, ds.Tables.Count, "DTC28");
+
+ ds.Tables.Remove("Table1");
+ Assert.AreEqual(1, ds.Tables.Count, "DTC29");
+
+ ds.Tables.Remove("Table2");
+ Assert.AreEqual(0, ds.Tables.Count, "DTC30");
+ }
+
+ [Test]
+ public void GetEnumerator()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add();
+ ds.Tables.Add();
+ int count=0;
+
+ System.Collections.IEnumerator myEnumerator = ds.Tables.GetEnumerator();
+
+ while (myEnumerator.MoveNext())
+ {
+ Assert.AreEqual("Table", ((DataTable) myEnumerator.Current).TableName.Substring(0,5), "DTC31");
+ count++;
+ }
+ Assert.AreEqual(2, count, "DTC32");
+ }
+ public void IndexOf_ByDataTable()
+ {
+ DataSet ds = new DataSet();
+ DataTable dt = new DataTable("NewTable1");
+ DataTable dt1 = new DataTable("NewTable2");
+ ds.Tables.AddRange(new DataTable[] {dt,dt1});
+
+ Assert.AreEqual(0, ds.Tables.IndexOf(dt), "DTC33");
+ Assert.AreEqual(1, ds.Tables.IndexOf(dt1), "DTC34");
+
+ ds.Tables.IndexOf((DataTable)null);
+
+ DataTable dt2 = new DataTable("NewTable2");
+
+ Assert.AreEqual(-1, ds.Tables.IndexOf(dt2), "DTC35");
+ }
+
+ public void IndexOf_ByName()
+ {
+ DataSet ds = new DataSet();
+ DataTable dt = new DataTable("NewTable1");
+ DataTable dt1 = new DataTable("NewTable2");
+ ds.Tables.AddRange(new DataTable[] {dt,dt1});
+
+ Assert.AreEqual(0, ds.Tables.IndexOf("NewTable1"), "DTC36");
+ Assert.AreEqual(1, ds.Tables.IndexOf("NewTable2"), "DTC37");
+
+ ds.Tables.IndexOf((string)null);
+
+ Assert.AreEqual(-1, ds.Tables.IndexOf("NewTable3"), "DTC38");
+ }
+
+ [Test]
+ public void Item()
+ {
+ DataSet ds = new DataSet();
+ DataTable dt = new DataTable("NewTable1");
+ DataTable dt1 = new DataTable("NewTable2");
+ ds.Tables.AddRange(new DataTable[] {dt,dt1});
+
+ Assert.AreEqual(dt, ds.Tables[0], "DTC39");
+ Assert.AreEqual(dt1, ds.Tables[1], "DTC40");
+ Assert.AreEqual(dt, ds.Tables["NewTable1"], "DTC41");
+ Assert.AreEqual(dt1, ds.Tables["NewTable2"], "DTC42");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests_System.Data
+{
+ [TestFixture] public class DataTableTest2
+ {
+ private bool _EventTriggered = false;
+ private bool EventRaised = false;
+ private bool EventValues = false;
+
+ class ProtectedTestClass : DataTable
+ {
+ public ProtectedTestClass() : base()
+ {
+ this.Columns.Add("Id",typeof(int));
+ this.Columns.Add("Value",typeof(string));
+ this.Rows.Add(new object[] {1,"one"});
+ this.Rows.Add(new object[] {2,"two"});
+ this.AcceptChanges();
+ }
+
+ public void OnColumnChanged_Test()
+ {
+ OnColumnChanged(new DataColumnChangeEventArgs(this.Rows[0],this.Columns["Value"],"NewValue"));
+ }
+
+ public void OnColumnChanging_Test()
+ {
+ OnColumnChanging(new DataColumnChangeEventArgs(this.Rows[0],this.Columns["Value"],"NewValue"));
+ }
+
+ public void OnRemoveColumn_Test()
+ {
+ OnRemoveColumn(this.Columns[0]);
+ }
+
+ public DataTable CreateInstance_Test()
+ {
+ return CreateInstance();
+ }
+ }
+
+ [Test] public void AcceptChanges()
+ {
+ String sNewValue = "NewValue";
+ DataRow drModified,drDeleted,drAdded;
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ drModified = dt.Rows[0];
+ drModified[1] = sNewValue; //DataRowState = Modified ,DataRowVersion = Proposed
+
+ drDeleted = dt.Rows[1];
+ drDeleted.Delete(); //DataRowState = Deleted
+
+ drAdded = dt.NewRow();
+ dt.Rows.Add(drAdded); //DataRowState = Added
+
+ dt.AcceptChanges();
+
+ // AcceptChanges - Unchanged1
+ Assert.AreEqual(DataRowState.Unchanged , drModified.RowState , "DT1");
+
+ // AcceptChanges - Current
+ Assert.AreEqual(sNewValue , drModified[1,DataRowVersion.Current] , "DT2");
+
+ // AcceptChanges - Unchanged2
+ Assert.AreEqual(DataRowState.Unchanged , drAdded.RowState , "DT3");
+
+ // AcceptChanges - Detached
+ Assert.AreEqual(DataRowState.Detached , drDeleted.RowState , "DT4");
+ }
+
+ [Test] public void ChildRelations()
+ {
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+
+ DataRelationCollection drlCollection;
+ DataRelation drl = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+
+ // Checking ChildRelations - default value
+ //Check default
+ drlCollection = dtParent.ChildRelations;
+ Assert.AreEqual(0, drlCollection.Count , "DT5");
+
+ ds.Relations.Add(drl);
+ drlCollection = dtParent.ChildRelations;
+
+ // Checking ChildRelations Count
+ Assert.AreEqual(1, drlCollection.Count , "DT6");
+
+ // Checking ChildRelations Value
+ Assert.AreEqual(drl, drlCollection[0] , "DT7");
+ }
+
+ [Test] public void Clear()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ dt.Clear();
+ // Clear
+ Assert.AreEqual(0, dt.Rows.Count , "DT8");
+ }
+
+ [Test] public void Clone()
+ {
+ DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
+ dt2.Constraints.Add("Unique",dt2.Columns[0],true);
+ dt2.Columns[0].DefaultValue=7;
+
+ dt1 = dt2.Clone();
+
+ for (int i=0; i<dt2.Constraints.Count; i++)
+ {
+ // Clone - Constraints[{0}],i)
+ Assert.AreEqual(dt2.Constraints[i].ConstraintName , dt1.Constraints[i].ConstraintName , "DT9");
+ }
+
+ for (int i=0; i<dt2.Columns.Count; i++)
+ {
+ // Clone - Columns[{0}].ColumnName,i)
+ Assert.AreEqual(dt2.Columns[i].ColumnName , dt1.Columns[i].ColumnName , "DT10");
+
+ // Clone - Columns[{0}].DataType,i)
+ Assert.AreEqual(dt2.Columns[i].DataType , dt1.Columns[i].DataType , "DT11");
+ }
+ }
+
+ [Test] public void ColumnChanged()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ dt.ColumnChanged += new DataColumnChangeEventHandler( Column_Changed );
+
+ _EventTriggered=false;
+ // ColumnChanged - EventTriggered
+ dt.Rows[0][1] = "NewValue";
+ Assert.AreEqual(true , _EventTriggered , "DT12");
+
+ _EventTriggered=false;
+ dt.ColumnChanged -= new DataColumnChangeEventHandler( Column_Changed );
+ // ColumnChanged - NO EventTriggered
+ dt.Rows[0][1] = "VeryNewValue";
+ Assert.AreEqual(false , _EventTriggered , "DT13");
+ }
+
+ private void Column_Changed( object sender, DataColumnChangeEventArgs e )
+ {
+ _EventTriggered = true;
+ }
+
+ [Test] public void ColumnChanging()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ dt.ColumnChanging += new DataColumnChangeEventHandler( Column_Changeding );
+
+ _EventTriggered=false;
+ // ColumnChanged - EventTriggered
+ dt.Rows[0][1] = "NewValue";
+ Assert.AreEqual(true , _EventTriggered , "DT14");
+
+ _EventTriggered=false;
+ dt.ColumnChanging -= new DataColumnChangeEventHandler( Column_Changeding );
+ // ColumnChanged - NO EventTriggered
+ dt.Rows[0][1] = "VeryNewValue";
+ Assert.AreEqual(false , _EventTriggered , "DT15");
+ }
+
+ private void Column_Changeding( object sender, DataColumnChangeEventArgs e )
+ {
+ _EventTriggered = true;
+ }
+
+ [Test] public void Columns()
+ {
+ DataTable dtParent;
+ DataColumnCollection dcl;
+ dtParent= DataProvider.CreateParentDataTable();
+
+ dcl = dtParent.Columns;
+
+ // Checking ColumnsCollection != null
+ Assert.AreEqual(false, dcl == null , "DT16");
+
+ // Checking ColumnCollection Count 1
+ Assert.AreEqual(6, dcl.Count , "DT17");
+
+ // Checking ColumnCollection Count 2
+ dtParent.Columns.Add(new DataColumn("Test"));
+ Assert.AreEqual(7, dcl.Count , "DT18");
+
+ // Checking ColumnCollection - get columnn by different case
+ DataColumn tmp = dtParent.Columns["TEST"];
+ Assert.AreEqual(dtParent.Columns["Test"], tmp , "DT19");
+
+ // Checking ColumnCollection colummn name case sensetive
+ dtParent.Columns.Add(new DataColumn("test"));
+ Assert.AreEqual(8, dcl.Count , "DT20");
+
+ // Checking ColumnCollection - get columnn by different case,ArgumentException
+ try
+ {
+ DataColumn tmp1 = dtParent.Columns["TEST"];
+ Assert.Fail("DT21: indexer Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT22: Indexer. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void Compute()
+ {
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //Get expected
+ DataRow[] drArr = dt.Select("ParentId=1");
+ Int64 iExSum = 0;
+ foreach (DataRow dr in drArr)
+ {
+ iExSum += (int)dr["ChildId"];
+ }
+ object objCompute=null;
+ // Compute - sum values
+ objCompute = dt.Compute("Sum(ChildId)","ParentId=1");
+ Assert.AreEqual(Int64.Parse(objCompute.ToString()) , Int64.Parse(iExSum.ToString()), "DT23");
+
+ // Compute - sum type
+ Assert.AreEqual(typeof(Int64).FullName , objCompute.GetType().FullName, "DT24");
+
+ //get expected
+ double iExAvg = 0;
+ drArr = dt.Select("ParentId=5");
+ foreach (DataRow dr in drArr)
+ {
+ iExAvg += (double)dr["ChildDouble"];
+ }
+ iExAvg = iExAvg / drArr.Length;
+
+ // Compute - Avg value
+ objCompute = dt.Compute("Avg(ChildDouble)","ParentId=5");
+ Assert.AreEqual(double.Parse(objCompute.ToString()) , double.Parse(iExAvg.ToString()), "DT25");
+
+ // Compute - Avg type
+ Assert.AreEqual(typeof(double).FullName , objCompute.GetType().FullName, "DT26");
+ }
+
+ [Test] public void Constraints()
+ {
+ DataTable dtParent;
+ ConstraintCollection consColl;
+ dtParent= DataProvider.CreateParentDataTable();
+
+ consColl = dtParent.Constraints;
+ // Checking Constraints != null
+ Assert.AreEqual(false, consColl == null , "DT27");
+
+ // Checking Constraints Count
+ Assert.AreEqual(0, consColl.Count , "DT28");
+
+ // Checking Constraints Count
+ //Add primary key
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
+ Assert.AreEqual(1, consColl.Count , "DT29");
+ }
+
+ [Test] public void Copy()
+ {
+ DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
+ dt2.Constraints.Add("Unique",dt2.Columns[0],true);
+ dt2.Columns[0].DefaultValue=7;
+
+ dt1 = dt2.Copy();
+
+ for (int i=0; i<dt2.Constraints.Count; i++)
+ {
+ // Copy - Constraints[{0}],i)
+ Assert.AreEqual(dt2.Constraints[i].ConstraintName , dt1.Constraints[i].ConstraintName , "DT30");
+ }
+
+ for (int i=0; i<dt2.Columns.Count; i++)
+ {
+ // Copy - Columns[{0}].ColumnName,i)
+ Assert.AreEqual(dt2.Columns[i].ColumnName , dt1.Columns[i].ColumnName , "DT31");
+
+ // Copy - Columns[{0}].DataType,i)
+ Assert.AreEqual(dt2.Columns[i].DataType , dt1.Columns[i].DataType , "DT32");
+ }
+
+ DataRow[] drArr1,drArr2;
+ drArr1 = dt1.Select("");
+ drArr2 = dt2.Select("");
+ for (int i=0; i<drArr1.Length ; i++)
+ {
+ // Copy - Data [ParentId]{0} ,i)
+ Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT33");
+ // Copy - Data [String1]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT34");
+ // Copy - Data [String2]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2"], "DT35");
+ }
+ }
+
+ [Test] public void CreateInstance()
+ {
+ // CreateInstance
+ ProtectedTestClass C = new ProtectedTestClass();
+ DataTable dt = C.CreateInstance_Test();
+ Assert.AreEqual(true , dt != null , "DT36");
+ }
+
+ [Test] public void DataSet()
+ {
+ DataTable dtParent;
+ DataSet ds;
+ dtParent= DataProvider.CreateParentDataTable();
+
+ ds = dtParent.DataSet;
+
+ // Checking DataSet == null
+ Assert.AreEqual(null, ds, "DT37");
+
+ // Checking DataSet != null
+ ds = new DataSet("MyDataSet");
+ ds.Tables.Add(dtParent);
+ Assert.AreEqual(true, dtParent.DataSet != null , "DT38");
+
+ // Checking DataSet Name
+ Assert.AreEqual("MyDataSet", dtParent.DataSet.DataSetName , "DT39");
+ }
+
+ [Test] public void DefaultView()
+ {
+ DataTable dtParent;
+ DataView dv;
+ dtParent= DataProvider.CreateParentDataTable();
+ dv = dtParent.DefaultView ;
+
+ // Checking DataView != null
+ Assert.AreEqual(true, dv != null, "DT40");
+ }
+
+ [Test] public void EndLoadData()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ dt.Columns[0].AllowDBNull = false;
+
+ // EndLoadData
+ dt.BeginLoadData();
+ dt.LoadDataRow(new object[] {null,"A","B"},false);
+
+ try
+ {
+ //ConstraintException will be throw
+ dt.EndLoadData();
+ Assert.Fail("DT41: EndLoadData Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT42: EndLoadData Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void GetChanges()
+ {
+ DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
+ dt2.Constraints.Add("Unique",dt2.Columns[0],true);
+ dt2.Columns[0].DefaultValue=7;
+
+ //make some changes
+ dt2.Rows[0].Delete();
+ dt2.Rows[1].Delete();
+ dt2.Rows[2].Delete();
+ dt2.Rows[3].Delete();
+
+ dt1 = dt2.GetChanges();
+
+ for (int i=0; i<dt2.Constraints.Count; i++)
+ {
+ // GetChanges - Constraints[{0}],i)
+ Assert.AreEqual(dt2.Constraints[i].ConstraintName , dt1.Constraints[i].ConstraintName , "DT43");
+ }
+
+ for (int i=0; i<dt2.Columns.Count; i++)
+ {
+ // GetChanges - Columns[{0}].ColumnName,i)
+ Assert.AreEqual(dt2.Columns[i].ColumnName , dt1.Columns[i].ColumnName , "DT44");
+
+ // GetChanges - Columns[{0}].DataType,i)
+ Assert.AreEqual(dt2.Columns[i].DataType , dt1.Columns[i].DataType , "DT45");
+ }
+
+ DataRow[] drArr1,drArr2;
+
+ drArr1 = dt1.Select("","",DataViewRowState.Deleted );
+ drArr2 = dt2.Select("","",DataViewRowState.Deleted );
+
+ for (int i=0; i<drArr1.Length ; i++)
+ {
+ // GetChanges - Data [ParentId]{0} ,i)
+ Assert.AreEqual(drArr1[i]["ParentId",DataRowVersion.Original ],drArr2[i]["ParentId",DataRowVersion.Original], "DT46");
+ // GetChanges - Data [String1]{0} ,i)
+ Assert.AreEqual(drArr1[i]["String1", DataRowVersion.Original],drArr2[i]["String1",DataRowVersion.Original], "DT47");
+ // GetChanges - Data [String2]{0} ,i)
+ Assert.AreEqual(drArr1[i]["String2", DataRowVersion.Original],drArr2[i]["String2",DataRowVersion.Original], "DT48");
+ }
+ }
+
+ [Test] public void GetChanges_ByDataRowState()
+ {
+ DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
+ dt2.Constraints.Add("Unique",dt2.Columns[0],true);
+ dt2.Columns[0].DefaultValue=7;
+
+ //make some changes
+ dt2.Rows[0].Delete(); //DataRowState.Deleted
+ dt2.Rows[1].Delete(); //DataRowState.Deleted
+ dt2.Rows[2].BeginEdit();
+ dt2.Rows[2]["String1"] = "Changed"; //DataRowState.Modified
+ dt2.Rows[2].EndEdit();
+
+ dt2.Rows.Add(new object[] {"99","Temp1","Temp2"}); //DataRowState.Added
+
+ // *********** Checking GetChanges - DataRowState.Deleted ************
+ dt1=null;
+ dt1 = dt2.GetChanges(DataRowState.Deleted);
+ CheckTableSchema (dt1,dt2,DataRowState.Deleted.ToString());
+ DataRow[] drArr1,drArr2;
+ drArr1 = dt1.Select("","",DataViewRowState.Deleted );
+ drArr2 = dt2.Select("","",DataViewRowState.Deleted );
+
+ for (int i=0; i<drArr1.Length ; i++)
+ {
+ // GetChanges(Deleted) - Data [ParentId]{0} ,i)
+ Assert.AreEqual(drArr1[i]["ParentId",DataRowVersion.Original ],drArr2[i]["ParentId",DataRowVersion.Original], "DT49");
+ // GetChanges(Deleted) - Data [String1]{0} ,i)
+ Assert.AreEqual(drArr1[i]["String1", DataRowVersion.Original],drArr2[i]["String1",DataRowVersion.Original], "DT50");
+ // GetChanges(Deleted) - Data [String2]{0} ,i)
+ Assert.AreEqual(drArr1[i]["String2", DataRowVersion.Original],drArr2[i]["String2",DataRowVersion.Original], "DT51");
+ }
+
+ // *********** Checking GetChanges - DataRowState.Modified ************
+ dt1=null;
+ dt1 = dt2.GetChanges(DataRowState.Modified);
+ CheckTableSchema (dt1,dt2,DataRowState.Modified.ToString());
+ drArr1 = dt1.Select("","");
+ drArr2 = dt2.Select("","",DataViewRowState.ModifiedCurrent);
+
+ for (int i=0; i<drArr1.Length ; i++)
+ {
+ // GetChanges(Modified) - Data [ParentId]{0} ,i)
+ Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT52");
+ // GetChanges(Modified) - Data [String1]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT53");
+ // GetChanges(Modified) - Data [String2]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2" ], "DT54");
+ }
+
+ // *********** Checking GetChanges - DataRowState.Added ************
+ dt1=null;
+ dt1 = dt2.GetChanges(DataRowState.Added);
+ CheckTableSchema (dt1,dt2,DataRowState.Added.ToString());
+ drArr1 = dt1.Select("","");
+ drArr2 = dt2.Select("","",DataViewRowState.Added );
+
+ for (int i=0; i<drArr1.Length ; i++)
+ {
+ // GetChanges(Added) - Data [ParentId]{0} ,i)
+ Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT55");
+ // GetChanges(Added) - Data [String1]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT56");
+ // GetChanges(Added) - Data [String2]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2" ], "DT57");
+ }
+
+ // *********** Checking GetChanges - DataRowState.Unchanged ************
+ dt1=null;
+ dt1 = dt2.GetChanges(DataRowState.Unchanged);
+ CheckTableSchema (dt1,dt2,DataRowState.Unchanged .ToString());
+ drArr1 = dt1.Select("","");
+ drArr2 = dt2.Select("","",DataViewRowState.Unchanged );
+
+ for (int i=0; i<drArr1.Length ; i++)
+ {
+ // GetChanges(Unchanged) - Data [ParentId]{0} ,i)
+ Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT58");
+ // GetChanges(Unchanged) - Data [String1]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT59");
+ // GetChanges(Unchanged) - Data [String2]{0} ,i)
+ Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2" ], "DT60");
+ }
+ }
+
+ private void CheckTableSchema(DataTable dt1, DataTable dt2,string Description)
+ {
+ for (int i=0; i<dt2.Constraints.Count; i++)
+ {
+ // GetChanges - Constraints[{0}] - {1},i,Description)
+ Assert.AreEqual(dt2.Constraints[i].ConstraintName , dt1.Constraints[i].ConstraintName , "DT61");
+ }
+
+ for (int i=0; i<dt2.Columns.Count; i++)
+ {
+ // GetChanges - Columns[{0}].ColumnName - {1},i,Description)
+ Assert.AreEqual(dt2.Columns[i].ColumnName , dt1.Columns[i].ColumnName , "DT62");
+
+ // GetChanges - Columns[{0}].DataType {1},i,Description)
+ Assert.AreEqual(dt2.Columns[i].DataType , dt1.Columns[i].DataType , "DT63");
+ }
+ }
+
+ [Test] public void GetErrors()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataRow[] drArr = new DataRow[3];
+ drArr[0] = dt.Rows[0];
+ drArr[1] = dt.Rows[2];
+ drArr[2] = dt.Rows[5];
+
+ drArr[0].RowError = "Error1";
+ drArr[1].RowError = "Error2";
+ drArr[2].RowError = "Error3";
+
+ // GetErrors
+ Assert.AreEqual(dt.GetErrors(), drArr , "DT64");
+ }
+
+ [Test] public new void GetHashCode()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ int iHashCode;
+ iHashCode = dt.GetHashCode();
+
+ for (int i=0; i<10 ;i++)
+ {
+ // HashCode - i= + i.ToString()
+ Assert.AreEqual(dt.GetHashCode() , iHashCode , "DT65");
+ }
+ }
+
+ [Test] public new void GetType()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ Type tmpType = typeof(DataTable);
+
+ // GetType
+ Assert.AreEqual(tmpType, dt.GetType() , "DT66");
+ }
+
+ [Test] public void HasErrors()
+ {
+ DataTable dtParent;
+ dtParent= DataProvider.CreateParentDataTable();
+
+ // Checking HasErrors default
+ Assert.AreEqual(false, dtParent.HasErrors , "DT67");
+
+ // Checking HasErrors Get
+ dtParent.Rows[0].RowError = "Error on row 0";
+ dtParent.Rows[2].RowError = "Error on row 2";
+ Assert.AreEqual(true, dtParent.HasErrors , "DT68");
+ }
+
+ [Test] public void ImportRow()
+ {
+ DataTable dt1,dt2;
+ dt1 = DataProvider.CreateParentDataTable();
+ dt2 = DataProvider.CreateParentDataTable();
+ DataRow dr = dt2.NewRow();
+ dr.ItemArray = new object[] {99,"",""};
+ dt2.Rows.Add(dr);
+
+ // ImportRow - Values
+ dt1.ImportRow(dr);
+ Assert.AreEqual(dr.ItemArray, dt1.Rows[dt1.Rows.Count-1].ItemArray , "DT69");
+
+ // ImportRow - DataRowState
+ Assert.AreEqual(dr.RowState , dt1.Rows[dt1.Rows.Count-1].RowState , "DT70");
+ }
+
+ [Test] public void LoadDataRow()
+ {
+ DataTable dt;
+ DataRow dr;
+ dt = DataProvider.CreateParentDataTable();
+ 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 without accept changes
+ dt.BeginLoadData();
+ dt.LoadDataRow(new object[] {1,null,"Changed"},false);
+ dt.EndLoadData();
+
+ // LoadDataRow(update1) - check column String1
+ Assert.AreEqual(dr["String1"], dt.Columns["String1"].DefaultValue , "DT71");
+
+ // LoadDataRow(update1) - check column String2
+ Assert.AreEqual(dr["String2"], "Changed", "DT72");
+
+ // LoadDataRow(update1) - check row state
+ Assert.AreEqual(DataRowState.Modified , dr.RowState , "DT73");
+
+ //Update existing row with accept changes
+ dr = dt.Select("ParentId=2")[0];
+
+ dt.BeginLoadData();
+ dt.LoadDataRow(new object[] {2,null,"Changed"},true);
+ dt.EndLoadData();
+
+ // LoadDataRow(update2) - check row state
+ Assert.AreEqual(DataRowState.Unchanged , dr.RowState , "DT74");
+
+ //Add New row without accept changes
+ dt.BeginLoadData();
+ dt.LoadDataRow(new object[] {99,null,"Changed"},false);
+ dt.EndLoadData();
+
+ // LoadDataRow(insert1) - check column String2
+ dr = dt.Select("ParentId=99")[0];
+ Assert.AreEqual("Changed" , dr["String2"] , "DT75");
+
+ // LoadDataRow(insert1) - check row state
+ Assert.AreEqual(DataRowState.Added , dr.RowState , "DT76");
+
+ //Add New row with accept changes
+ dt.BeginLoadData();
+ dt.LoadDataRow(new object[] {100,null,"Changed"},true);
+ dt.EndLoadData();
+
+ // LoadDataRow(insert2) - check row and values
+ dr = dt.Select("ParentId=100")[0];
+ Assert.AreEqual("Changed" , dr["String2"] , "DT77");
+
+ // LoadDataRow(insert2) - check row state
+ Assert.AreEqual(DataRowState.Unchanged , dr.RowState , "DT78");
+ }
+
+ [Test] public void Locale()
+ {
+ DataTable dtParent;
+ DataSet ds = new DataSet("MyDataSet");
+
+ dtParent= DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ System.Globalization.CultureInfo culInfo = System.Globalization.CultureInfo.CurrentCulture ;
+
+ // Checking Locale default from system
+ Assert.AreEqual(culInfo, dtParent.Locale , "DT79");
+
+ // Checking Locale default from dataset
+ culInfo = new System.Globalization.CultureInfo("fr"); // = French
+ ds.Locale = culInfo;
+ Assert.AreEqual(culInfo , dtParent.Locale , "DT80");
+
+ // Checking Locale get/set
+ culInfo = new System.Globalization.CultureInfo("fr"); // = French
+ dtParent.Locale = culInfo ;
+ Assert.AreEqual(culInfo , dtParent.Locale , "DT81");
+ }
+
+ [Test] public void MinimumCapacity()
+ {
+ // i get default=50, according to MSDN the value should be 25
+ // // Checking MinimumCapacity default = 25
+ // Assert.AreEqual(25, dtParent.MinimumCapacity , "DT82");
+ // EndCase(null);
+ DataTable dt = new DataTable();
+
+ // Checking MinimumCapacity get/set int.MaxValue
+ dt.MinimumCapacity = int.MaxValue;
+ Assert.AreEqual(int.MaxValue, dt.MinimumCapacity , "DT83");
+
+ // Checking MinimumCapacity get/set 0
+ dt.MinimumCapacity = 0;
+ Assert.AreEqual(0, dt.MinimumCapacity , "DT84");
+
+ // // Checking MinimumCapacity get/set int.MinValue
+ // dtParent.MinimumCapacity = int.MinValue ;
+ // Assert.AreEqual(int.MinValue, dtParent.MinimumCapacity , "DT85");
+ // EndCase(null);
+ }
+
+ [Test] public void Namespace()
+ {
+ DataTable dtParent = new DataTable();
+
+ // Checking Namespace default
+ Assert.AreEqual(String.Empty, dtParent.Namespace, "DT86");
+
+ // Checking Namespace set/get
+ String s = "MyNamespace";
+ dtParent.Namespace=s;
+ Assert.AreEqual(s, dtParent.Namespace, "DT87");
+ }
+
+ [Test] public void NewRow()
+ {
+ DataTable dt;
+ DataRow dr;
+ dt = DataProvider.CreateParentDataTable();
+
+ // NewRow
+ dr = dt.NewRow();
+ Assert.AreEqual(true , dr != null , "DT88");
+ }
+
+ [Test] public void OnColumnChanged()
+ {
+ ProtectedTestClass dt = new ProtectedTestClass();
+
+ EventRaised = false;
+ dt.OnColumnChanged_Test();
+ // OnColumnChanged Event 1
+ Assert.AreEqual(false , EventRaised , "DT89");
+ EventRaised = false;
+ EventValues = false;
+ dt.ColumnChanged += new DataColumnChangeEventHandler(OnColumnChanged_Handler);
+ dt.OnColumnChanged_Test();
+ // OnColumnChanged Event 2
+ Assert.AreEqual(true , EventRaised , "DT90");
+ // OnColumnChanged Values
+ Assert.AreEqual(true , EventValues , "DT91");
+ dt.ColumnChanged -= new DataColumnChangeEventHandler(OnColumnChanged_Handler);
+ }
+
+ private void OnColumnChanged_Handler(Object sender,DataColumnChangeEventArgs e)
+ {
+ DataTable dt = (DataTable)sender;
+ if ( (e.Column.Equals(dt.Columns["Value"]) ) &&
+ (e.Row.Equals(dt.Rows[0]) ) &&
+ (e.ProposedValue.Equals("NewValue")) )
+ {
+ EventValues = true;
+ }
+ else
+ {
+ EventValues = false;
+ }
+ EventRaised = true;
+ }
+
+ [Test] public void OnColumnChanging()
+ {
+ ProtectedTestClass dt = new ProtectedTestClass();
+
+ EventRaised = false;
+ dt.OnColumnChanging_Test();
+ // OnColumnChanging Event 1
+ Assert.AreEqual(false , EventRaised , "DT92");
+ EventRaised = false;
+ EventValues = false;
+ dt.ColumnChanging += new DataColumnChangeEventHandler(OnColumnChanging_Handler);
+ dt.OnColumnChanging_Test();
+ // OnColumnChanging Event 2
+ Assert.AreEqual(true , EventRaised , "DT93");
+ // OnColumnChanging Values
+ Assert.AreEqual(true , EventValues , "DT94");
+ dt.ColumnChanging -= new DataColumnChangeEventHandler(OnColumnChanging_Handler);
+ }
+
+ private void OnColumnChanging_Handler(Object sender,DataColumnChangeEventArgs e)
+ {
+ DataTable dt = (DataTable)sender;
+ if ( (e.Column.Equals(dt.Columns["Value"]) ) &&
+ (e.Row.Equals(dt.Rows[0]) ) &&
+ (e.ProposedValue.Equals("NewValue")) )
+ {
+ EventValues = true;
+ }
+ else
+ {
+ EventValues = false;
+ }
+ EventRaised = true;
+ }
+
+ [Test] public void OnRemoveColumn()
+ {
+ ProtectedTestClass dt = new ProtectedTestClass();
+
+ // OnRemoveColumn
+ dt.OnRemoveColumn_Test();
+ }
+
+ [Test] public void ParentRelations()
+ {
+ DataTable dtChild,dtParent;
+ DataSet ds = new DataSet();
+ //Create tables
+ dtChild = DataProvider.CreateChildDataTable();
+ dtParent= DataProvider.CreateParentDataTable();
+ //Add tables to dataset
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+
+ DataRelationCollection drlCollection;
+ DataRelation drl = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
+
+ // Checking ParentRelations - default value
+ //Check default
+ drlCollection = dtChild.ParentRelations;
+ Assert.AreEqual(0, drlCollection.Count , "DT96");
+
+ ds.Relations.Add(drl);
+ drlCollection = dtChild.ParentRelations;
+
+ // Checking ParentRelations Count
+ Assert.AreEqual(1, drlCollection.Count , "DT97");
+
+ // Checking ParentRelations Value
+ Assert.AreEqual(drl, drlCollection[0] , "DT98");
+ }
+
+ [Test] public void Prefix()
+ {
+ DataTable dtParent = new DataTable();
+
+ // Checking Prefix default
+ Assert.AreEqual(String.Empty, dtParent.Prefix , "DT99");
+
+ // Checking Prefix set/get
+ String s = "MyPrefix";
+ dtParent.Prefix=s;
+ Assert.AreEqual(s, dtParent.Prefix, "DT100");
+ }
+
+ [Test] public void RejectChanges()
+ {
+ String sNewValue = "NewValue";
+ DataRow drModified,drDeleted,drAdded;
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ drModified = dt.Rows[0];
+ drModified[1] = sNewValue; //DataRowState = Modified ,DataRowVersion = Proposed
+
+ drDeleted = dt.Rows[1];
+ drDeleted.Delete(); //DataRowState = Deleted
+
+ drAdded = dt.NewRow();
+ dt.Rows.Add(drAdded); //DataRowState = Added
+
+ dt.RejectChanges();
+
+ // RejectChanges - Unchanged1
+ Assert.AreEqual(DataRowState.Unchanged , drModified.RowState , "DT101");
+
+ // RejectChanges - Unchanged2
+ Assert.AreEqual(DataRowState.Detached , drAdded.RowState , "DT102");
+
+ // RejectChanges - Detached
+ Assert.AreEqual(DataRowState.Unchanged , drDeleted.RowState , "DT103");
+ }
+
+ [Test] public void Reset()
+ {
+ DataTable dt1 = DataProvider.CreateParentDataTable();
+ DataTable dt2 = DataProvider.CreateChildDataTable();
+ dt1.PrimaryKey = new DataColumn[] {dt1.Columns[0]};
+ dt2.PrimaryKey = new DataColumn[] {dt2.Columns[0],dt2.Columns[1]};
+ DataRelation rel = new DataRelation("Rel",dt1.Columns["ParentId"],dt2.Columns["ParentId"]);
+ DataSet ds = new DataSet();
+ ds.Tables.AddRange(new DataTable[] {dt1,dt2});
+ ds.Relations.Add(rel);
+
+ dt2.Reset();
+
+ // Reset - ParentRelations
+ Assert.AreEqual(0 , dt2.ParentRelations.Count , "DT104");
+ // Reset - Constraints
+ Assert.AreEqual(0 , dt2.Constraints.Count , "DT105");
+ // Reset - Rows
+ Assert.AreEqual(0 , dt2.Rows.Count , "DT106");
+ // Reset - Columns
+ Assert.AreEqual(0 , dt2.Columns.Count , "DT107");
+ }
+
+ [Test] public void RowChanged()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ dt.RowChanged += new DataRowChangeEventHandler ( Row_Changed );
+
+ _EventTriggered=false;
+ // RowChanged - 1
+ dt.Rows[0][1] = "NewValue";
+ Assert.AreEqual(true , _EventTriggered , "DT108");
+
+ _EventTriggered=false;
+ // RowChanged - 2
+ dt.Rows[0].BeginEdit();
+ dt.Rows[0][1] = "NewValue";
+ Assert.AreEqual(false , _EventTriggered , "DT109");
+
+ _EventTriggered=false;
+ // RowChanged - 3
+ dt.Rows[0].EndEdit();
+ Assert.AreEqual(true , _EventTriggered , "DT110");
+
+ _EventTriggered=false;
+ dt.RowChanged -= new DataRowChangeEventHandler ( Row_Changed );
+ // RowChanged - 4
+ dt.Rows[0][1] = "NewValue A";
+ Assert.AreEqual(false , _EventTriggered , "DT111");
+ }
+
+ private void Row_Changed( object sender, DataRowChangeEventArgs e )
+ {
+ _EventTriggered = true;
+ }
+
+ [Test] public void RowChanging()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ dt.RowChanging += new DataRowChangeEventHandler ( Row_Changing );
+
+ _EventTriggered=false;
+ // RowChanging - 1
+ dt.Rows[0][1] = "NewValue";
+ Assert.AreEqual(true , _EventTriggered , "DT112");
+
+ _EventTriggered=false;
+ // RowChanging - 2
+ dt.Rows[0].BeginEdit();
+ dt.Rows[0][1] = "NewValue";
+ Assert.AreEqual(false , _EventTriggered , "DT113");
+
+ _EventTriggered=false;
+ // RowChanging - 3
+ dt.Rows[0].EndEdit();
+ Assert.AreEqual(true , _EventTriggered , "DT114");
+
+ _EventTriggered=false;
+ dt.RowChanging -= new DataRowChangeEventHandler ( Row_Changing );
+ // RowChanging - 4
+ dt.Rows[0][1] = "NewValue A";
+ Assert.AreEqual(false , _EventTriggered , "DT115");
+ }
+
+ private void Row_Changing( object sender, DataRowChangeEventArgs e )
+ {
+ _EventTriggered = true;
+ }
+
+ [Test] public void RowDeleted()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ dt.RowDeleted += new DataRowChangeEventHandler ( Row_Deleted );
+
+ _EventTriggered=false;
+ // RowDeleted - 1
+ dt.Rows[0].Delete();
+ Assert.AreEqual(true , _EventTriggered , "DT116");
+
+ _EventTriggered=false;
+ dt.RowDeleted -= new DataRowChangeEventHandler ( Row_Deleted );
+ // RowDeleted - 2
+ dt.Rows[1].Delete();
+ Assert.AreEqual(false , _EventTriggered , "DT117");
+ }
+
+ private void Row_Deleted( object sender, DataRowChangeEventArgs e )
+ {
+ _EventTriggered = true;
+ }
+
+ [Test] public void RowDeleting()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ dt.RowDeleting += new DataRowChangeEventHandler ( Row_Deleting );
+
+ _EventTriggered=false;
+ // RowDeleting - 1
+ dt.Rows[0].Delete();
+ Assert.AreEqual(true , _EventTriggered , "DT118");
+
+ _EventTriggered=false;
+ dt.RowDeleting -= new DataRowChangeEventHandler ( Row_Deleting );
+ // RowDeleting - 2
+ dt.Rows[1].Delete();
+ Assert.AreEqual(false , _EventTriggered , "DT119");
+ }
+
+ private void Row_Deleting( object sender, DataRowChangeEventArgs e )
+ {
+ _EventTriggered = true;
+ }
+
+ [Test] public void Rows()
+ {
+ DataTable dtParent;
+ dtParent = DataProvider.CreateParentDataTable();
+
+ // Checking Rows
+ Assert.AreEqual(true, dtParent.Rows != null, "DT120");
+
+ // Checking rows count
+ Assert.AreEqual(true, dtParent.Rows.Count > 0 , "DT121");
+ }
+
+ [Test] public void Select()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ DataRow[] drSelect = dt.Select();
+ DataRow[] drResult = new DataRow[dt.Rows.Count] ;
+ dt.Rows.CopyTo(drResult,0);
+
+ // Select
+
+ Assert.AreEqual(drResult, drSelect , "DT122");
+ }
+
+ [Test] public void Select_ByFilter()
+ {
+ DataSet ds = new DataSet();
+ ds.Tables.Add(DataProvider.CreateParentDataTable());
+
+ DataTable dt = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dt);
+ DataRow[] drSelect = null;
+ System.Collections.ArrayList al = new System.Collections.ArrayList();
+
+ //add column with special name
+ DataColumn dc = new DataColumn("Column#",typeof(int));
+ dc.DefaultValue=-1;
+ dt.Columns.Add(dc);
+ //put some values
+ dt.Rows[0][dc] = 100;
+ dt.Rows[1][dc] = 200;
+ dt.Rows[2][dc] = 300;
+ dt.Rows[4][dc] = -400;
+
+ //for trim function
+ dt.Rows[0]["String1"] = dt.Rows[0]["String1"] + " \t\n ";
+ dt.Rows[0]["String1"] = " \t\n " + dt.Rows[0]["String1"] ;
+ dt.Rows[0]["String1"] = dt.Rows[0]["String1"] + " ";
+
+ ds.Tables[0].Rows[0]["ParentBool"] = DBNull.Value;
+ ds.Tables[0].Rows[2]["ParentBool"] = DBNull.Value;
+ ds.Tables[0].Rows[3]["ParentBool"] = DBNull.Value;
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows )
+ {
+ if ((int)dr["ChildId"] == 1)
+ {
+ al.Add(dr);
+ }
+ }
+ // Select_S - ChildId=1
+ drSelect = dt.Select("ChildId=1");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT123");
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows )
+ {
+ if ((int)dr["ChildId"] == 1)
+ {
+ al.Add(dr);
+ }
+ }
+ // Select_S - ChildId='1'
+ drSelect = dt.Select("ChildId='1'");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT124");
+ //-------------------------------------------------------------
+ // Select_S - ChildId= '1' (whitespace in filter string.
+ drSelect = dt.Select("ChildId= '1'");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT125");
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if (dr["String1"].ToString() == "1-String1") al.Add(dr);
+ // Select_S - String1='1-String1'
+ drSelect = dt.Select("String1='1-String1'");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT126");
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1" ) al.Add(dr);
+ // Select_S - ChildId=1 and String1='1-String1'
+ drSelect = dt.Select("ChildId=1 and String1='1-String1'");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT127");
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ((int)dr["ChildId"] + (int)dr["ParentId"] >= 4 ) al.Add(dr);
+ // Select_S - ChildId+ParentId >= 4
+ drSelect = dt.Select("ChildId+ParentId >= 4");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows )
+ {
+ if ((((int)dr["ChildId"] - (int)dr["ParentId"]) * -1) != 0 )
+ {
+ al.Add(dr);
+ }
+ }
+ // Select_S - ChildId-ParentId) * -1 <> 0
+ drSelect = dt.Select("(ChildId-ParentId) * -1 <> 0");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( (double)dr["ChildDouble"] < ((int)dr["ParentId"]) % 4 ) al.Add(dr);
+ // Select_S - ChildDouble < ParentId % 4
+ drSelect = dt.Select("ChildDouble < ParentId % 4");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( (double)dr["ChildDouble"] == 10 || (double)dr["ChildDouble"] == 20 || (double)dr["ChildDouble"] == 25 ) al.Add(dr);
+ // Select_S - ChildDouble in (10,20,25)
+ drSelect = dt.Select("ChildDouble in (10,20,25)");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( dr["String2"].ToString().IndexOf("1-S") >= 0 ) al.Add(dr);
+ // Select_S - String2 like '%1-S%'
+ drSelect = dt.Select("String2 like '%1-S%'");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT128");
+
+ //-------------------------------------------------------------
+ //If a column name contains one of the above characters,(ex. #\/=><+-*%&|^'" and so on) the name must be wrapped in brackets. For example to use a column named "Column#" in an expression, you would write "[Column#]":
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( (int)dr["Column#"] <= 0) al.Add(dr);
+ // Select_S - [Column#] <= 0
+ drSelect = dt.Select("[Column#] <= 0 ");
+ CompareUnSorted(drSelect ,al.ToArray());
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( (int)dr["Column#"] <= 0) al.Add(dr);
+ // Select_S - [Column#] <= 0
+ drSelect = dt.Select("[Column#] <= 0");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if (((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(2000,12,12)) > 0 ) al.Add(dr);
+ // Select_S - ChildDateTime > #12/12/2000#
+ drSelect = dt.Select("ChildDateTime > #12/12/2000# ");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( ((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(1999,1,12,12,06,30)) > 0 ) al.Add(dr);
+ // Select_S - ChildDateTime > #1/12/1999 12:06:30 PM#
+ drSelect = dt.Select("ChildDateTime > #1/12/1999 12:06:30 PM# ");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+ //-------------------------------------------------------------
+
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( ((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(2005,12,03,17,06,30)) >= 0 || ((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(1980,11,03)) <= 0 ) al.Add(dr);
+ // Select_S - ChildDateTime >= #12/3/2005 5:06:30 PM# or ChildDateTime <= #11/3/1980#
+ drSelect = dt.Select("ChildDateTime >= #12/3/2005 5:06:30 PM# or ChildDateTime <= #11/3/1980# ");
+ CompareUnSorted(drSelect ,al.ToArray());
+
+#if LATER
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( dr["ChildDouble"].ToString().Length > 10) al.Add(dr);
+ // Select_S - Len(Convert(ChildDouble,'System.String')) > 10
+ drSelect = dt.Select("Len(Convert(ChildDouble,'System.String')) > 10");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT129");
+#endif
+ //-------------------------------------------------------------
+ al.Clear();
+ foreach (DataRow dr in dt.Rows ) if ( dr["String1"].ToString().Trim().Substring(0,2) == "1-") al.Add(dr);
+ // Select_S - SubString(Trim(String1),1,2) = '1-'
+ drSelect = dt.Select("SubString(Trim(String1),1,2) = '1-'");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT130");
+ //-------------------------------------------------------------
+ /*
+ al.Clear();
+ foreach (DataRow dr in ds.Tables[0].Rows ) if ( dr.IsNull("ParentBool") || (bool)dr["ParentBool"]) al.Add(dr);
+ // Select_S - IsNull(ParentBool,true)
+ drSelect = ds.Tables[0].Select("IsNull(ParentBool,true) ");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT131");
+ */
+ //-------------------------------------------------------------
+ al.Clear();
+ // Select_S - Relation not exists, Exception
+ try
+ {
+ drSelect = dt.Select("Parent.ParentId = ChildId");
+ Assert.Fail("DT132: Select Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT133: Select. Wrong exception type. Got:" + exc);
+ }
+ //-------------------------------------------------------------
+ al.Clear();
+ ds.Relations.Add(new DataRelation("ParentChild",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));
+ foreach (DataRow dr in dt.Rows ) if ( (int)dr["ChildId"] == (int)dr.GetParentRow("ParentChild")["ParentId"]) al.Add(dr);
+ // Select_S - Parent.ParentId = ChildId
+ drSelect = dt.Select("Parent.ParentId = ChildId");
+ Assert.AreEqual(al.ToArray(), drSelect , "DT134");
+ }
+
+ private void CompareUnSorted(Array a, Array b)
+ {
+ string msg = string.Format("Failed while comparing(Array a ={0} ({1}), Array b = {2} ({3}))]", a.ToString(), a.GetType().FullName, b.ToString(), b.GetType().FullName);
+ foreach (object item in a)
+ {
+ if (Array.IndexOf(b, item) < 0) //b does not contain the current item.
+ {
+ Assert.Fail(msg);
+ }
+ }
+
+ foreach (object item in b)
+ {
+ if (Array.IndexOf(a, item) < 0) //a does not contain the current item.
+ {
+ Assert.Fail(msg);
+ return;
+ }
+ }
+ }
+
+ [Test] public void Select_ByFilterDataViewRowState()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataRow[] drSelect, drResult;
+
+ dt.Rows[0].Delete();
+ dt.Rows[1]["ParentId"] = 1;
+ dt.Rows[2]["ParentId"] = 1;
+ dt.Rows[3].Delete();
+ dt.Rows.Add(new object[] {1,"A","B"});
+ dt.Rows.Add(new object[] {1,"C","D"});
+ dt.Rows.Add(new object[] {1,"E","F"});
+
+ drSelect = dt.Select("ParentId=1","",DataViewRowState.Added );
+ drResult = GetResultRows(dt,DataRowState.Added);
+ // Select_SSD DataViewRowState.Added
+ Assert.AreEqual(drResult, drSelect , "DT135");
+
+ drSelect = dt.Select("ParentId=1","",DataViewRowState.CurrentRows );
+ drResult = GetResultRows(dt,DataRowState.Unchanged | DataRowState.Added | DataRowState.Modified );
+ // Select_SSD DataViewRowState.CurrentRows
+ Assert.AreEqual(drResult, drSelect , "DT136");
+
+ drSelect = dt.Select("ParentId=1","",DataViewRowState.Deleted );
+ drResult = GetResultRows(dt,DataRowState.Deleted );
+ // Select_SSD DataViewRowState.Deleted
+ Assert.AreEqual(drResult, drSelect , "DT137");
+
+ drSelect = dt.Select("ParentId=1","",DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal );
+ drResult = GetResultRows(dt,DataRowState.Modified );
+ // Select_SSD ModifiedCurrent or ModifiedOriginal
+ Assert.AreEqual(drResult, drSelect , "DT138");
+ }
+
+ private DataRow[] GetResultRows(DataTable dt,DataRowState State)
+ {
+ System.Collections.ArrayList al = new System.Collections.ArrayList();
+ DataRowVersion drVer = DataRowVersion.Current;
+
+ //From MSDN - The row the default version for the current DataRowState.
+ // For a DataRowState value of Added, Modified or Current,
+ // the default version is Current.
+ // For a DataRowState of Deleted, the version is Original.
+ // For a DataRowState value of Detached, the version is Proposed.
+
+ if ( ((State & DataRowState.Added) > 0)
+ | ((State & DataRowState.Modified) > 0)
+ | ((State & DataRowState.Unchanged) > 0) )
+ drVer = DataRowVersion.Current;
+ if ( (State & DataRowState.Deleted) > 0
+ | (State & DataRowState.Detached) > 0 )
+ drVer = DataRowVersion.Original;
+
+ foreach (DataRow dr in dt.Rows )
+ {
+ if ( dr.HasVersion(drVer)
+ && ((int)dr["ParentId", drVer] == 1)
+ && ((dr.RowState & State) > 0 )
+ )
+ al.Add(dr);
+ }
+ DataRow[] result = (DataRow[])al.ToArray((typeof(DataRow)));
+ return result;
+ }
+
+ [Test] public void TableName()
+ {
+ DataTable dtParent = new DataTable();
+
+ // Checking TableName default
+ Assert.AreEqual(String.Empty, dtParent.TableName, "DT139");
+
+ // Checking TableName set/get
+ String s = "MyTable";
+ dtParent.TableName=s;
+ Assert.AreEqual(s, dtParent.TableName, "DT140");
+ }
+
+ [Test] public new void ToString()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ dt.DisplayExpression = dt.Columns[0].ColumnName ;
+
+ string sToString = dt.TableName + " + " + dt.DisplayExpression;
+ // ToString
+ Assert.AreEqual(sToString , dt.ToString() , "DT141");
+ }
+
+ [Test] public void caseSensitive()
+ {
+ DataTable dtParent = new DataTable();
+
+ // Checking default
+ Assert.AreEqual(false, dtParent.CaseSensitive , "DT142");
+
+ // Checking set/get
+ dtParent.CaseSensitive = true;
+ Assert.AreEqual(true, dtParent.CaseSensitive , "DT143");
+ }
+
+ [Test] public void ctor()
+ {
+ DataTable dt;
+ dt = new DataTable();
+
+ // ctor
+ Assert.AreEqual(false, dt == null, "DT144");
+ }
+
+ [Test] public void ctor_ByName()
+ {
+ DataTable dt;
+ string sName = "MyName";
+
+ dt = new DataTable(sName);
+
+ // Ctor
+ Assert.AreEqual(false , dt == null , "DT145");
+
+ // Ctor TableName
+ Assert.AreEqual(sName , dt.TableName , "DT146");
+ }
+
+ [Test] public void displayExpression()
+ {
+ DataTable dtParent;
+ dtParent= DataProvider.CreateParentDataTable();
+
+ // Checking DisplayExpression default
+ Assert.AreEqual(String.Empty , dtParent.DisplayExpression , "DT147");
+
+ // Checking DisplayExpression Set/Get
+ dtParent.DisplayExpression = dtParent.Columns[0].ColumnName;
+ Assert.AreEqual(dtParent.Columns[0].ColumnName, dtParent.DisplayExpression , "DT148");
+ }
+
+ [Test] public void extendedProperties()
+ {
+ DataTable dtParent;
+ PropertyCollection pc;
+ dtParent= DataProvider.CreateParentDataTable();
+
+ pc = dtParent.ExtendedProperties ;
+
+ // Checking ExtendedProperties default
+ Assert.AreEqual(true, pc != null, "DT149");
+
+ // Checking ExtendedProperties count
+ Assert.AreEqual(0, pc.Count , "DT150");
+ }
+
+ [Test] public void primaryKey()
+ {
+ DataTable dtParent;
+ dtParent = DataProvider.CreateParentDataTable();
+
+ // Checking PrimaryKey default
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "DT151");
+
+ // Checking PrimaryKey set/get
+ DataColumn[] dcArr = new DataColumn[] {dtParent.Columns[0]};
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
+ Assert.AreEqual(dcArr, dtParent.PrimaryKey , "DT152");
+
+ dtParent.PrimaryKey=null;
+ DataSet ds = new DataSet();
+ DataRow dr = null;
+ ds.Tables.Add(dtParent);
+
+ //check primary key - ColumnType String, ds.CaseSensitive = false;
+ ds.CaseSensitive = false;
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["String1"]};
+ // check primary key - ColumnType String, ds.CaseSensitive = false;
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["String1"] = dr["String1"].ToString().ToUpper();
+ try
+ {
+ dtParent.Rows.Add(dr);
+ Assert.Fail("DT153: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT154: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ //check primary key - ColumnType String, ds.CaseSensitive = true;
+ ds.CaseSensitive = true;
+ // check primary key ConstraintException - ColumnType String, ds.CaseSensitive = true;
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["String1"] = dr["String1"].ToString();
+ try
+ {
+ dtParent.Rows.Add(dr);
+ Assert.Fail("DT155: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT156: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ //check primary key - ColumnType String, ds.CaseSensitive = true;
+ ds.CaseSensitive = true;
+
+ // check primary key - ColumnType String, ds.CaseSensitive = true;
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["String1"] = dr["String1"].ToString().ToUpper() ;
+ dtParent.Rows.Add(dr);
+ Assert.AreEqual(true, dtParent.Rows.Contains(dr["String1"]), "DT157");
+
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ dtParent.PrimaryKey=null;
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentDateTime"]};
+ // check primary key - ColumnType DateTime
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDateTime"] = DateTime.Now;
+ dtParent.Rows.Add(dr);
+ Assert.AreEqual(true, dtParent.Rows.Contains(dr["ParentDateTime"]), "DT158");
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ // check primary key ConstraintException- ColumnType DateTime
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDateTime"] = dtParent.Rows[0]["ParentDateTime"];
+ try
+ {
+ dtParent.Rows.Add(dr);
+ Assert.Fail("DT159: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT160: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ dtParent.PrimaryKey=null;
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentDouble"]};
+ // check primary key - ColumnType ParentDouble, value=Epsilon
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDouble"] = Double.Epsilon ;
+ dtParent.Rows.Add(dr);
+ Assert.AreEqual(true, dtParent.Rows.Contains(dr["ParentDouble"]), "DT161");
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ // check primary key ConstraintException - ColumnType ParentDouble
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDouble"] = dtParent.Rows[0]["ParentDouble"];
+ try
+ {
+ dtParent.Rows.Add(dr);
+ Assert.Fail("DT162: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT163: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ //
+ // SubTest
+ //
+ dtParent.PrimaryKey=null;
+ // check primary key ConstraintException - ColumnType ParentBool
+ try
+ {
+ //ParentBool is not unique, will raise exception
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentBool"]};
+ Assert.Fail("DT164: PrimaryKey Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT165: PrimaryKey. Wrong exception type. Got:" + exc);
+ }
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ //
+ // SubTest
+ //
+ dtParent.PrimaryKey=null;
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentDouble"],dtParent.Columns["ParentDateTime"]};
+ // check primary key - ColumnType Double,DateTime test1
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDouble"] = dtParent.Rows[0]["ParentDouble"];
+ dr["ParentDateTime"] = DateTime.Now;
+ dtParent.Rows.Add(dr);
+ Assert.AreEqual(true, dtParent.Rows.Contains(new object[] {dr["ParentDouble"],dr["ParentDateTime"]}), "DT166");
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ // check primary key - ColumnType Double,DateTime test2
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDateTime"] = dtParent.Rows[0]["ParentDateTime"];
+ dr["ParentDouble"] = 99.399;
+ dtParent.Rows.Add(dr);
+ Assert.AreEqual(true, dtParent.Rows.Contains(new object[] {dr["ParentDouble"],dr["ParentDateTime"]}), "DT167");
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ // check primary key ConstraintException - ColumnType Double,DateTime
+ dr = dtParent.NewRow();
+ dr.ItemArray = dtParent.Rows[0].ItemArray;
+ dr["ParentDouble"] = dtParent.Rows[0]["ParentDouble"];
+ dr["ParentDateTime"] = dtParent.Rows[0]["ParentDateTime"];
+ try
+ {
+ dtParent.Rows.Add(dr);
+ Assert.Fail("DT168: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DT169: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+ if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);
+
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtChild);
+ dtParent.PrimaryKey = null;
+ //this test was addedd to check java exception:
+ //System.ArgumentException: Cannot remove UniqueConstraint because the ForeignKeyConstraint myRelation exists.
+ // check add primary key with relation
+ ds.Relations.Add(new DataRelation("myRelation",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));
+ //the following line will cause java to fail
+ ds.Tables[0].PrimaryKey = new DataColumn[] {ds.Tables[0].Columns[0],ds.Tables[0].Columns[1]};
+ Assert.AreEqual(2, ds.Tables[0].PrimaryKey.Length , "DT170");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.ComponentModel;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests_System.Data
+{
+ [TestFixture] public class DataViewTest2
+ {
+ private EventProperties evProp = null;
+
+ class EventProperties //hold the event properties to be checked
+ {
+ public System.ComponentModel.ListChangedType lstType ;
+ public int NewIndex;
+ public int OldIndex;
+ }
+
+ [Test] public void AddNew()
+ {
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ int CountView = dv.Count ;
+ int CountTable= dt.Rows.Count ;
+
+ DataRowView drv = null;
+
+ // AddNew - DataView Row Count
+ drv = dv.AddNew();
+ Assert.AreEqual(dv.Count , CountView+1, "DV1");
+
+ // AddNew - Table Row Count
+ Assert.AreEqual(dt.Rows.Count , CountTable, "DV2");
+
+ // AddNew - new row in DataTable
+ drv.EndEdit();
+ Assert.AreEqual(dt.Rows.Count , CountTable+1, "DV3");
+
+ // AddNew - new row != null
+ Assert.AreEqual(true, drv!=null, "DV4");
+
+ // AddNew - check table
+ Assert.AreEqual(dt, drv.Row.Table, "DV5");
+ }
+
+ [Test] public void AllowDelete()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ // AllowDelete - default value
+ Assert.AreEqual(true , dv.AllowDelete , "DV6");
+
+ // AllowDelete - true
+ dv.AllowDelete = true;
+ Assert.AreEqual(true, dv.AllowDelete , "DV7");
+
+ // AllowDelete - false
+ dv.AllowDelete = false;
+ Assert.AreEqual(false, dv.AllowDelete , "DV8");
+
+ dv.AllowDelete = false;
+ // AllowDelete false- Exception
+ try
+ {
+ dv.Delete(0);
+ Assert.Fail("DV9: Delete Failed to throw DataException");
+ }
+ catch (DataException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV10: Delete. Wrong exception type. Got:" + exc);
+ }
+
+ dv.AllowDelete = true;
+ int RowsCount = dv.Count ;
+ // AllowDelete true- Exception
+ dv.Delete(0);
+ Assert.AreEqual(RowsCount-1, dv.Count , "DV11");
+ }
+
+ [Test] public void AllowEdit()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ // AllowEdit - default value
+ Assert.AreEqual(true , dv.AllowEdit , "DV12");
+
+ // AllowEdit - true
+ dv.AllowEdit = true;
+ Assert.AreEqual(true, dv.AllowEdit , "DV13");
+
+ // AllowEdit - false
+ dv.AllowEdit = false;
+ Assert.AreEqual(false, dv.AllowEdit , "DV14");
+
+ dv.AllowEdit=false;
+
+ // AllowEdit false - exception
+ try
+ {
+ dv[0][2] = "aaa";
+ Assert.Fail("DV15: Indexer Failed to throw DataException");
+ }
+ catch (DataException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV16: Indexer. Wrong exception type. Got:" + exc);
+ }
+
+ dv.AllowEdit=true;
+
+ // AllowEdit true- exception
+ dv[0][2] = "aaa";
+ Assert.AreEqual("aaa", dv[0][2] , "DV17");
+ }
+
+ [Test] public void AllowNew()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ // AllowNew - default value
+ Assert.AreEqual(true , dv.AllowNew , "DV18");
+
+ // AllowNew - true
+ dv.AllowNew = true;
+ Assert.AreEqual(true, dv.AllowNew , "DV19");
+
+ // AllowNew - false
+ dv.AllowNew = false;
+ Assert.AreEqual(false, dv.AllowNew , "DV20");
+
+ // AllowNew - exception
+ try
+ {
+ dv.AddNew();
+ Assert.Fail("DV21: AddNew Failed to throw DataException");
+ }
+ catch (DataException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV22: AddNew. Wrong exception type. Got:" + exc);
+ }
+
+ dv.AllowNew=true;
+ int RowsCount = dv.Count ;
+
+ // AllowNew - exception
+ dv.AddNew();
+ Assert.AreEqual(RowsCount+1, dv.Count , "DV23");
+ }
+
+ [Test] public void ApplyDefaultSort()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ // ApplyDefaultSort - default value
+ Assert.AreEqual(false , dv.ApplyDefaultSort , "DV24");
+
+ // ApplyDefaultSort - true
+ dv.ApplyDefaultSort = true;
+ Assert.AreEqual(true, dv.ApplyDefaultSort , "DV25");
+
+ // ApplyDefaultSort - false
+ dv.ApplyDefaultSort = false;
+ Assert.AreEqual(false, dv.ApplyDefaultSort , "DV26");
+ }
+
+ [Test] public void CopyTo()
+ {
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ DataRowView[] drvExpected = null;
+ DataRowView[] drvResult = null;
+
+ // ------- Copy from Index=0
+ drvExpected = new DataRowView[dv.Count];
+ for (int i=0; i < dv.Count ;i++)
+ {
+ drvExpected[i] = dv[i];
+ }
+
+ drvResult = new DataRowView[dv.Count];
+ // CopyTo from index 0
+ dv.CopyTo(drvResult,0);
+ Assert.AreEqual(drvResult, drvExpected , "DV27");
+
+ // ------- Copy from Index=3
+ drvExpected = new DataRowView[dv.Count+3];
+ for (int i=0; i < dv.Count ;i++)
+ {
+ drvExpected[i+3] = dv[i];
+ }
+
+ drvResult = new DataRowView[dv.Count+3];
+ // CopyTo from index 3
+ dv.CopyTo(drvResult,3);
+ Assert.AreEqual(drvResult , drvExpected , "DV28");
+
+ // ------- Copy from Index=3,larger array
+ drvExpected = new DataRowView[dv.Count+9];
+ for (int i=0; i < dv.Count ;i++)
+ {
+ drvExpected[i+3] = dv[i];
+ }
+
+ drvResult = new DataRowView[dv.Count+9];
+ // CopyTo from index 3,larger array
+ dv.CopyTo(drvResult,3);
+ Assert.AreEqual(drvResult, drvExpected , "DV29");
+
+ // ------- CopyTo smaller array, check exception
+ drvResult = new DataRowView[dv.Count-1];
+
+ // CopyTo smaller array, check exception
+ try
+ {
+ dv.CopyTo(drvResult,0);
+ Assert.Fail("DV30: CopyTo Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV31: CopyTo. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void Delete()
+ {
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ int CountView = dv.Count ;
+ int CountTable= dt.Rows.Count ;
+
+ DataRowView drv = dv[0];
+
+ // Delete - DataView Row Count
+ dv.Delete(0);
+ Assert.AreEqual(dv.Count , CountView-1, "DV32");
+
+ // Delete - Table Row Count
+ Assert.AreEqual(dt.Rows.Count , CountTable, "DV33");
+
+ // Delete - check table
+ Assert.AreEqual(dt, drv.Row.Table, "DV34");
+ }
+
+ [Test] public void FindRows_ByKey()
+ {
+ DataRowView[] dvArr = null;
+
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ // FindRows ,no sort - exception
+ try
+ {
+ dvArr = dv.FindRows(3);
+ Assert.Fail("DV35: FindRows Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV36: FindRows. Wrong exception type. Got:" + exc);
+ }
+
+ dv.Sort = "String1";
+ // Find = wrong sort, can not find
+ dvArr = dv.FindRows(3);
+ Assert.AreEqual(0, dvArr.Length , "DV37");
+
+ dv.Sort = "ChildId";
+
+ //get expected results
+ DataRow[] drExpected = dt.Select("ChildId=3");
+
+ // FindRows - check count
+ dvArr = dv.FindRows(3);
+ Assert.AreEqual(drExpected.Length , dvArr.Length, "DV38");
+
+ // FindRows - check data
+
+ //check that result is ok
+ bool Succeed = true;
+ for (int i=0; i<dvArr.Length ; i++)
+ {
+ Succeed = (int)dvArr[i]["ChildId"] == (int)drExpected [i]["ChildId"];
+ if (!Succeed) break;
+ }
+ Assert.AreEqual(true, Succeed , "DV39");
+ }
+
+ [Test] public void FindRows_ByKeys()
+ {
+ DataRowView[] dvArr = null;
+
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ // FindRows ,no sort - exception
+ try
+ {
+ dvArr = dv.FindRows(new object[] {"3","3-String1"});
+ Assert.Fail("DV40: FindRows Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV41: FindRows. Wrong exception type. Got:" + exc);
+ }
+
+ dv.Sort = "String1,ChildId";
+ // Find = wrong sort, can not find
+ dvArr = dv.FindRows(new object[] {"3","3-String1"});
+ Assert.AreEqual(0, dvArr.Length , "DV42");
+
+ dv.Sort = "ChildId,String1";
+
+ //get expected results
+ DataRow[] drExpected = dt.Select("ChildId=3 and String1='3-String1'");
+
+ // FindRows - check count
+ dvArr = dv.FindRows(new object[] {"3","3-String1"});
+ Assert.AreEqual(drExpected.Length , dvArr.Length, "DV43");
+
+ // FindRows - check data
+
+ //check that result is ok
+ bool Succeed = true;
+ for (int i=0; i<dvArr.Length ; i++)
+ {
+ Succeed = (int)dvArr[i]["ChildId"] == (int)drExpected [i]["ChildId"];
+ if (!Succeed) break;
+ }
+ Assert.AreEqual(true, Succeed , "DV44");
+ }
+
+ //Activate This Construntor to log All To Standard output
+ //public TestClass():base(true){}
+
+ //Activate this constructor to log Failures to a log file
+ //public TestClass(System.IO.TextWriter tw):base(tw, false){}
+
+ //Activate this constructor to log All to a log file
+ //public TestClass(System.IO.TextWriter tw):base(tw, true){}
+
+ //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
+
+ [Test] public void Find_ByObject()
+ {
+ int FindResult,ExpectedResult=-1;
+
+ //create the source datatable
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ for (int i=0; i<dt.Rows.Count ; i++)
+ {
+ if ((int)dt.Rows[i]["ParentId"] == 3)
+ {
+ ExpectedResult = i;
+ break;
+ }
+ }
+
+ // Find ,no sort - exception
+ try
+ {
+ FindResult = dv.Find("3");
+ Assert.Fail("DV45: Find Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV46: Find. Wrong exception type. Got:" + exc);
+ }
+
+ dv.Sort = "String1";
+ // Find = wrong sort, can not find
+ FindResult = dv.Find("3");
+ Assert.AreEqual(-1, FindResult , "DV47");
+
+ dv.Sort = "ParentId";
+ // Find
+ FindResult = dv.Find("3");
+ Assert.AreEqual(ExpectedResult, FindResult , "DV48");
+ }
+
+ [Test] public void Find_ByArray()
+ {
+ int FindResult,ExpectedResult=-1;
+
+ //create the source datatable
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ for (int i=0; i<dt.Rows.Count ; i++)
+ {
+ if ((int)dt.Rows[i]["ParentId"] == 3 && dt.Rows[i]["String1"].ToString() == "3-String1")
+ {
+ ExpectedResult = i;
+ break;
+ }
+ }
+
+ // Find ,no sort - exception
+ try
+ {
+ FindResult = dv.Find(new object[] {"3","3-String1"});
+ Assert.Fail("DV49: Find Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV50: Find. Wrong exception type. Got:" + exc);
+ }
+
+ dv.Sort = "String1,ParentId";
+ // Find = wrong sort, can not find
+ FindResult = dv.Find(new object[] {"3","3-String1"});
+ Assert.AreEqual(-1, FindResult , "DV51");
+
+ dv.Sort = "ParentId,String1";
+ // Find
+ FindResult = dv.Find(new object[] {"3","3-String1"});
+ Assert.AreEqual(ExpectedResult, FindResult , "DV52");
+ }
+
+ //Activate This Construntor to log All To Standard output
+ //public TestClass():base(true){}
+
+ //Activate this constructor to log Failures to a log file
+ //public TestClass(System.IO.TextWriter tw):base(tw, false){}
+
+ //Activate this constructor to log All to a log file
+ //public TestClass(System.IO.TextWriter tw):base(tw, true){}
+
+ //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
+
+ [Test] public void GetEnumerator()
+ {
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ System.Collections.IEnumerator ienm = null;
+
+ // GetEnumerator != null
+ ienm = dv.GetEnumerator();
+ Assert.AreEqual(true, ienm != null, "DV53");
+
+ int i=0;
+ while (ienm.MoveNext() )
+ {
+ // Check item i
+ Assert.AreEqual(dv[i], (DataRowView)ienm.Current , "DV54");
+ i++;
+ }
+ }
+
+ [Test] public void Item()
+ {
+ //create the source datatable
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ // DataView Item 0
+ Assert.AreEqual(dv[0].Row, dt.Rows[0] , "DV55");
+
+ // DataView Item 4
+ Assert.AreEqual(dv[4].Row, dt.Rows[4] , "DV56");
+
+ dv.RowFilter="ParentId in (1,3,6)";
+
+ // DataView Item 0,DataTable with filter
+ Assert.AreEqual(dv[1].Row, dt.Rows[2] , "DV57");
+ }
+
+ [Test] public void ListChanged()
+ {
+ DataTable dt = DataProvider.CreateParentDataTable();
+ DataView dv = new DataView(dt);
+
+ //add event handler
+ dv.ListChanged +=new System.ComponentModel.ListChangedEventHandler(dv_ListChanged);
+
+ // ----- Change Value ---------
+ evProp = null;
+ // change value - Event raised
+ dv[1]["String1"] = "something";
+ Assert.AreEqual(true , evProp!=null , "DV58");
+ // change value - ListChangedType
+ Assert.AreEqual(System.ComponentModel.ListChangedType.ItemChanged, evProp.lstType , "DV59");
+ // change value - NewIndex
+ Assert.AreEqual(1, evProp.NewIndex, "DV60");
+ // change value - OldIndex
+ Assert.AreEqual(-1, evProp.OldIndex , "DV61");
+
+ // ----- Add New ---------
+ evProp = null;
+ // Add New - Event raised
+ dv.AddNew();
+ Assert.AreEqual(true , evProp!=null , "DV62");
+ // Add New - ListChangedType
+ Assert.AreEqual(System.ComponentModel.ListChangedType.ItemAdded , evProp.lstType , "DV63");
+ // Add New - NewIndex
+ Assert.AreEqual(6, evProp.NewIndex, "DV64");
+ // Add New - OldIndex
+ Assert.AreEqual(-1, evProp.OldIndex , "DV65");
+
+ // ----- Sort ---------
+ evProp = null;
+ // sort - Event raised
+ dv.Sort = "ParentId Desc";
+ Assert.AreEqual(true , evProp!=null , "DV66");
+ // sort - ListChangedType
+ Assert.AreEqual(System.ComponentModel.ListChangedType.Reset , evProp.lstType , "DV67");
+ // sort - NewIndex
+ Assert.AreEqual(-1, evProp.NewIndex, "DV68");
+ // sort - OldIndex
+ Assert.AreEqual(-1, evProp.OldIndex , "DV69");
+
+ //ListChangedType - this was not checked
+ //Move
+ //PropertyDescriptorAdded - A PropertyDescriptor was added, which changed the schema.
+ //PropertyDescriptorChanged - A PropertyDescriptor was changed, which changed the schema.
+ //PropertyDescriptorDeleted
+ }
+
+ private void dv_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
+ {
+ evProp = new EventProperties();
+ evProp.lstType = e.ListChangedType;
+ evProp.NewIndex = e.NewIndex;
+ evProp.OldIndex = e.OldIndex;
+ }
+
+ [Test] public void RowFilter()
+ {
+ //note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
+ // this test also check DataView.Count property
+
+ DataRowView[] drvResult = null;
+ System.Collections.ArrayList al = new System.Collections.ArrayList();
+
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ //-------------------------------------------------------------
+ //Get excpected result
+ al.Clear();
+ foreach (DataRow dr in dt.Rows )
+ {
+ if ((int)dr["ChildId"] == 1)
+ {
+ al.Add(dr);
+ }
+ }
+
+ // RowFilter = 'ChildId=1', check count
+ dv.RowFilter = "ChildId=1";
+ Assert.AreEqual(al.Count , dv.Count , "DV70");
+
+ // RowFilter = 'ChildId=1', check rows
+ drvResult = new DataRowView[dv.Count];
+ dv.CopyTo(drvResult,0);
+ //check that the filterd rows exists
+ bool Succeed = true;
+ for (int i=0; i<drvResult.Length ; i++)
+ {
+ Succeed = al.Contains(drvResult[i].Row);
+ if (!Succeed) break;
+ }
+ Assert.AreEqual(true, Succeed , "DV71");
+ //-------------------------------------------------------------
+
+ //-------------------------------------------------------------
+ //Get excpected result
+ al.Clear();
+ foreach (DataRow dr in dt.Rows )
+ if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1" )
+ al.Add(dr);
+
+ // RowFilter - ChildId=1 and String1='1-String1'
+ dv.RowFilter = "ChildId=1 and String1='1-String1'";
+ Assert.AreEqual(al.Count , dv.Count , "DV72");
+
+ // RowFilter = ChildId=1 and String1='1-String1', check rows
+ drvResult = new DataRowView[dv.Count];
+ dv.CopyTo(drvResult,0);
+ //check that the filterd rows exists
+ Succeed = true;
+ for (int i=0; i<drvResult.Length ; i++)
+ {
+ Succeed = al.Contains(drvResult[i].Row);
+ if (!Succeed) break;
+ }
+ Assert.AreEqual(true, Succeed , "DV73");
+ //-------------------------------------------------------------
+
+ //EvaluateException
+ // RowFilter - check EvaluateException
+ try
+ {
+ dv.RowFilter = "Col=1";
+ Assert.Fail("DV74: RowFilter Failed to throw EvaluateException");
+ }
+ catch (EvaluateException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV75: RowFilter. Wrong exception type. Got:" + exc);
+ }
+
+ //SyntaxErrorException 1
+ // RowFilter - check SyntaxErrorException 1
+ try
+ {
+ dv.RowFilter = "sum('something')";
+ Assert.Fail("DV76: RowFilter Failed to throw SyntaxErrorException");
+ }
+ catch (SyntaxErrorException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV77: RowFilter. Wrong exception type. Got:" + exc);
+ }
+
+ //SyntaxErrorException 2
+ // RowFilter - check SyntaxErrorException 2
+ try
+ {
+ dv.RowFilter = "HH**!";
+ Assert.Fail("DV78: RowFilter Failed to throw SyntaxErrorException");
+ }
+ catch (SyntaxErrorException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV79: RowFilter. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void RowStateFilter()
+ {
+ /*
+ Added A new row. 4
+ CurrentRows Current rows including unchanged, new, and modified rows. 22
+ Deleted A deleted row. 8
+ ModifiedCurrent A current version, which is a modified version of original data (see ModifiedOriginal). 16
+ ModifiedOriginal The original version (although it has since been modified and is available as ModifiedCurrent). 32
+ None None. 0
+ OriginalRows Original rows including unchanged and deleted rows. 42
+ Unchanged An unchanged row. 2
+ */
+
+ //DataRowView[] drvResult = null;
+ System.Collections.ArrayList al = new System.Collections.ArrayList();
+
+ DataTable dt = DataProvider.CreateParentDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ DataRow[] drResult;
+
+ dt.Rows[0].Delete();
+ dt.Rows[1]["ParentId"] = 1;
+ dt.Rows[2]["ParentId"] = 1;
+ dt.Rows[3].Delete();
+ dt.Rows.Add(new object[] {1,"A","B"});
+ dt.Rows.Add(new object[] {1,"C","D"});
+ dt.Rows.Add(new object[] {1,"E","F"});
+
+ //---------- Added --------
+ dv.RowStateFilter = DataViewRowState.Added ;
+ drResult = GetResultRows(dt,DataRowState.Added);
+ // Added
+ Assert.AreEqual(true , CompareSortedRowsByParentId(dv,drResult), "DV80");
+
+ //---------- CurrentRows --------
+ dv.RowStateFilter = DataViewRowState.CurrentRows ;
+ drResult = GetResultRows(dt,DataRowState.Unchanged | DataRowState.Added | DataRowState.Modified );
+ // CurrentRows
+ Assert.AreEqual(true , CompareSortedRowsByParentId(dv,drResult), "DV81");
+
+ //---------- ModifiedCurrent --------
+ dv.RowStateFilter = DataViewRowState.ModifiedCurrent ;
+ drResult = GetResultRows(dt,DataRowState.Modified );
+ // ModifiedCurrent
+ Assert.AreEqual(true , CompareSortedRowsByParentId(dv,drResult) , "DV82");
+
+ //---------- ModifiedOriginal --------
+ dv.RowStateFilter = DataViewRowState.ModifiedOriginal ;
+ drResult = GetResultRows(dt,DataRowState.Modified );
+ // ModifiedOriginal
+ Assert.AreEqual(true , CompareSortedRowsByParentId(dv,drResult) , "DV83");
+
+ //---------- Deleted --------
+ dv.RowStateFilter = DataViewRowState.Deleted ;
+ drResult = GetResultRows(dt,DataRowState.Deleted );
+ // Deleted
+ Assert.AreEqual(true , CompareSortedRowsByParentId(dv,drResult), "DV84");
+ /*
+ //---------- OriginalRows --------
+ dv.RowStateFilter = DataViewRowState.OriginalRows ;
+ drResult = GetResultRows(dt,DataRowState.Unchanged | DataRowState.Deleted );
+ // OriginalRows
+ Assert.AreEqual(true , CompareSortedRowsByParentId(dv,drResult), "DV85");
+ */
+ }
+
+ private DataRow[] GetResultRows(DataTable dt,DataRowState State)
+ {
+ //get expected rows
+ System.Collections.ArrayList al = new System.Collections.ArrayList();
+ DataRowVersion drVer = DataRowVersion.Current;
+
+ //From MSDN - The row the default version for the current DataRowState.
+ // For a DataRowState value of Added, Modified or Current,
+ // the default version is Current.
+ // For a DataRowState of Deleted, the version is Original.
+ // For a DataRowState value of Detached, the version is Proposed.
+
+ if ( ((State & DataRowState.Added) > 0)
+ | ((State & DataRowState.Modified) > 0)
+ | ((State & DataRowState.Unchanged) > 0) )
+ drVer = DataRowVersion.Current;
+ if ( (State & DataRowState.Deleted) > 0
+ | (State & DataRowState.Detached) > 0 )
+ drVer = DataRowVersion.Original;
+
+ foreach (DataRow dr in dt.Rows )
+ {
+ if ( dr.HasVersion(drVer)
+ //&& ((int)dr["ParentId", drVer] == 1)
+ && ((dr.RowState & State) > 0 )
+ )
+ al.Add(dr);
+ }
+ DataRow[] result = (DataRow[])al.ToArray((typeof(DataRow)));
+ return result;
+ }
+
+ private bool CompareSortedRowsByParentId(DataView dv, DataRow[] drTable)
+ {
+ if (dv.Count != drTable.Length) throw new Exception("DataRows[] length are different");
+
+ //comparing the rows by using columns ParentId and ChildId
+ if ((dv.RowStateFilter & DataViewRowState.Deleted) > 0)
+ {
+ for (int i=0; i<dv.Count ; i++)
+ {
+ if (dv[i].Row["ParentId",DataRowVersion.Original ].ToString() != drTable[i]["ParentId",DataRowVersion.Original].ToString())
+ return false;
+ }
+ }
+ else
+ {
+ for (int i=0; i<dv.Count ; i++)
+ {
+ if (dv[i].Row["ParentId"].ToString() != drTable[i]["ParentId"].ToString())
+ return false;
+ }
+ }
+ return true;
+ }
+
+ [Test] public void Sort()
+ {
+ DataRow[] drArrTable;
+
+ //create the source datatable
+ DataTable dt = DataProvider.CreateChildDataTable();
+
+ //create the dataview for the table
+ DataView dv = new DataView(dt);
+
+ dv.Sort = "ParentId";
+ drArrTable = dt.Select("","ParentId");
+ // sort = ParentId
+ Assert.AreEqual(true, CompareSortedRowsByParentAndChildId(dv,drArrTable), "DV86");
+
+ dv.Sort = "ChildId";
+ drArrTable = dt.Select("","ChildId");
+ // sort = ChildId
+ Assert.AreEqual(true, CompareSortedRowsByParentAndChildId(dv,drArrTable), "DV87");
+
+ dv.Sort = "ParentId Desc, ChildId";
+ drArrTable = dt.Select("","ParentId Desc, ChildId");
+ // sort = ParentId Desc, ChildId
+ Assert.AreEqual(true, CompareSortedRowsByParentAndChildId(dv,drArrTable), "DV88");
+
+ dv.Sort = "ChildId Asc, ParentId";
+ drArrTable = dt.Select("","ChildId Asc, ParentId");
+ // sort = ChildId Asc, ParentId
+ Assert.AreEqual(true, CompareSortedRowsByParentAndChildId(dv,drArrTable), "DV89");
+
+ dv.Sort = "ChildId Asc, ChildId Desc";
+ drArrTable = dt.Select("","ChildId Asc, ChildId Desc");
+ // sort = ChildId Asc, ChildId Desc
+ Assert.AreEqual(true, CompareSortedRowsByParentAndChildId(dv,drArrTable), "DV90");
+
+ // IndexOutOfRangeException - 1
+ try
+ {
+ dv.Sort = "something";
+ Assert.Fail("DV91: Sort Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV92: Sort. Wrong exception type. Got:" + exc);
+ }
+
+ // IndexOutOfRangeException - 2
+ try
+ {
+ dv.Sort = "ColumnId Desc Asc";
+ Assert.Fail("DV93: Sort Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV94: Sort. Wrong exception type. Got:" + exc);
+ }
+
+ // IndexOutOfRangeException - 3
+ try
+ {
+ dv.Sort = "ColumnId blabla";
+ Assert.Fail("DV95: Sort Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV96: Sort. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ private bool CompareSortedRowsByParentAndChildId(DataView dv, DataRow[] drTable)
+ {
+ if (dv.Count != drTable.Length) throw new Exception("DataRows[] length are different");
+
+ //comparing the rows by using columns ParentId and ChildId
+ for (int i=0; i<dv.Count ; i++)
+ {
+ if ( dv[i].Row["ParentId"].ToString() != drTable[i]["ParentId"].ToString()
+ &&
+ dv[i].Row["ChildId"].ToString() != drTable[i]["ChildId"].ToString())
+ return false;
+ }
+ return true;
+ }
+
+ [Test] public void Table()
+ {
+ DataTable dt = new DataTable();
+ DataView dv = new DataView();
+
+ // DataTable=null
+ Assert.AreEqual(null , dv.Table , "DV97");
+
+ // DataException - bind to table with no name
+ try
+ {
+ dv.Table = dt;
+ Assert.Fail("DV98: Table Failed to throw DataException");
+ }
+ catch (DataException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV99: Table. Wrong exception type. Got:" + exc);
+ }
+
+ dt.TableName = "myTable";
+ // DataTable!=null
+ dv.Table = dt;
+ Assert.AreEqual(dt, dv.Table , "DV100");
+
+ // assign null to DataTable
+ dv.Table = null;
+ Assert.AreEqual(null, dv.Table , "DV101");
+ }
+
+ [Test] public void ctor_Empty()
+ {
+ DataView dv;
+ dv = new DataView();
+
+ // ctor
+ Assert.AreEqual(false, dv == null, "DV102");
+ }
+
+ [Test] public void ctor_DataTable()
+ {
+ DataView dv = null;
+ DataTable dt = new DataTable("myTable");
+
+ // ctor
+ dv = new DataView(dt);
+ Assert.AreEqual(false, dv == null, "DV103");
+
+ // ctor - table
+ Assert.AreEqual(dt , dv.Table , "DV104");
+ }
+
+ [Test] public void ctor_ExpectedExceptions()
+ {
+ DataView dv = null;
+ DataTable dt = new DataTable("myTable");
+
+ // ctor - missing column CutomerID Exception
+ try
+ {
+ //exception: System.Data.EvaluateException: Cannot find column [CustomerId]
+ dv = new DataView(dt,"CustomerId > 100","Age",DataViewRowState.Added );
+ Assert.Fail("DV105: DataView ctor Failed to throw EvaluateException or IndexOutOfRangeException");
+ }
+ catch (EvaluateException) {}
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV106: DataView ctor. Wrong exception type. Got:" + exc);
+ }
+
+ dt.Columns.Add(new DataColumn("CustomerId"));
+
+ // ctor - missing column Age Exception
+ try
+ {
+ //exception: System.Data.EvaluateException: Cannot find column [Age]
+ dv = new DataView(dt,"CustomerId > 100","Age",DataViewRowState.Added );
+ Assert.Fail("DV107: DataView ctor Failed to throw IndexOutOfRangeException");
+ }
+ catch (IndexOutOfRangeException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DV108: DataView ctor. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void ctor_Complex()
+ {
+ DataView dv = null;
+ DataTable dt = new DataTable("myTable");
+
+ dt.Columns.Add(new DataColumn("CustomerId"));
+ dt.Columns.Add(new DataColumn("Age"));
+
+ // ctor
+ dv = new DataView(dt,"CustomerId > 100","Age",DataViewRowState.Added );
+ Assert.AreEqual(false , dv == null , "DV109");
+
+ // ctor - table
+ Assert.AreEqual(dt , dv.Table , "DV110");
+
+ // ctor - RowFilter
+ Assert.AreEqual("CustomerId > 100" , dv.RowFilter , "DV111");
+
+ // ctor - Sort
+ Assert.AreEqual("Age" , dv.Sort, "DV112");
+
+ // ctor - RowStateFilter
+ Assert.AreEqual(DataViewRowState.Added , dv.RowStateFilter , "DV113");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests_System.Data
+{
+ [TestFixture] public class ForeignKeyConstraintTest2
+ {
+ [Test] public void Columns()
+ {
+ //int RowCount;
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ // Columns
+ Assert.AreEqual(dtChild.Columns[0] , fc.Columns[0] , "FKC");
+
+ // Columns count
+ Assert.AreEqual(1 , fc.Columns.Length , "FKC");
+ }
+
+ [Test] public void Equals()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
+ ds.EnforceConstraints = true;
+
+ ForeignKeyConstraint fc1,fc2;
+ fc1 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[1]);
+ // different columnn
+ Assert.AreEqual(false, fc1.Equals(fc2), "FKC");
+
+ //Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
+ // same column
+ fc2 = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+ Assert.AreEqual(true, fc1.Equals(fc2), "FKC");
+ }
+
+ [Test] public void RelatedColumns()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ // RelatedColumns
+ Assert.AreEqual(new DataColumn[] {dtParent.Columns[0]}, fc.RelatedColumns , "FKC");
+ }
+
+ [Test] public void RelatedTable()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ // RelatedTable
+ Assert.AreEqual(dtParent, fc.RelatedTable , "FKC");
+ }
+
+ [Test] public void Table()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ // Table
+ Assert.AreEqual(dtChild , fc.Table , "FKC");
+ }
+
+ [Test] public new void ToString()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ // ToString - default
+ Assert.AreEqual(string.Empty , fc.ToString(), "FKC");
+
+ fc = new ForeignKeyConstraint("myConstraint",dtParent.Columns[0],dtChild.Columns[0]);
+ // Tostring - Constraint name
+ Assert.AreEqual("myConstraint", fc.ToString(), "FKC");
+ }
+
+ [Test] public void acceptRejectRule()
+ {
+ DataSet ds = getNewDataSet();
+
+ ForeignKeyConstraint fc = new ForeignKeyConstraint(ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]);
+ fc.AcceptRejectRule= AcceptRejectRule.Cascade;
+ ds.Tables[1].Constraints.Add(fc);
+
+ //Update the parent
+
+ ds.Tables[0].Rows[0]["ParentId"] = 777;
+ Assert.AreEqual(true, ds.Tables[1].Select("ParentId=777").Length > 0 , "FKC");
+ ds.Tables[0].RejectChanges();
+ Assert.AreEqual(0, ds.Tables[1].Select("ParentId=777").Length , "FKC");
+ }
+ private DataSet getNewDataSet()
+ {
+ DataSet ds1 = new DataSet();
+ ds1.Tables.Add(DataProvider.CreateParentDataTable());
+ ds1.Tables.Add(DataProvider.CreateChildDataTable());
+ // ds1.Tables.Add(DataProvider.CreateChildDataTable());
+ ds1.Tables[0].PrimaryKey= new DataColumn[] {ds1.Tables[0].Columns[0]};
+
+ return ds1;
+ }
+
+ [Test] public void constraintName()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ // default
+ Assert.AreEqual(string.Empty , fc.ConstraintName , "FKC");
+
+ fc.ConstraintName = "myConstraint";
+
+ // set/get
+ Assert.AreEqual("myConstraint" , fc.ConstraintName , "FKC");
+ }
+
+ [Test] public void ctor_ParentColChildCol()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ DataSet ds = new DataSet();
+ ds.Tables.Add(dtChild);
+ ds.Tables.Add(dtParent);
+
+ ForeignKeyConstraint fc = null;
+
+ // Ctor ArgumentException
+ try
+ {
+ fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0],dtChild.Columns[1]});
+ Assert.Fail("DS333: ctor Indexer Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: ctor. Wrong exception type. Got:" + exc);
+ }
+
+ fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0],dtParent.Columns[1]} ,new DataColumn[] {dtChild.Columns[0],dtChild.Columns[2]});
+
+ // Add constraint to table - ArgumentException
+ try
+ {
+ dtChild.Constraints.Add(fc);
+ Assert.Fail("DS333: ctor Indexer Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: ctor. Wrong exception type. Got:" + exc);
+ }
+
+ // Child Table Constraints Count - two columnns
+ Assert.AreEqual(0, dtChild.Constraints.Count , "FKC");
+
+ // Parent Table Constraints Count - two columnns
+ Assert.AreEqual(1, dtParent.Constraints.Count , "FKC");
+
+ // DataSet relations Count
+ Assert.AreEqual(0, ds.Relations.Count , "FKC");
+
+ dtParent.Constraints.Clear();
+ dtChild.Constraints.Clear();
+
+ fc = new ForeignKeyConstraint(new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0]});
+ // Ctor
+ Assert.AreEqual(false , fc == null , "FKC");
+
+ // Child Table Constraints Count
+ Assert.AreEqual(0, dtChild.Constraints.Count , "FKC");
+
+ // Parent Table Constraints Count
+ Assert.AreEqual(0, dtParent.Constraints.Count , "FKC");
+
+ // DataSet relations Count
+ Assert.AreEqual(0, ds.Relations.Count , "FKC");
+
+ dtChild.Constraints.Add(fc);
+
+ // Child Table Constraints Count, Add
+ Assert.AreEqual(1, dtChild.Constraints.Count , "FKC");
+
+ // Parent Table Constraints Count, Add
+ Assert.AreEqual(1, dtParent.Constraints.Count , "FKC");
+
+ // DataSet relations Count, Add
+ Assert.AreEqual(0, ds.Relations.Count , "FKC");
+
+ // Parent Table Constraints type
+ Assert.AreEqual(typeof(UniqueConstraint), dtParent.Constraints[0].GetType() , "FKC");
+
+ // Parent Table Constraints type
+ Assert.AreEqual(typeof(ForeignKeyConstraint), dtChild.Constraints[0].GetType() , "FKC");
+
+ // Parent Table Primary key
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "FKC");
+
+ dtChild.Constraints.Clear();
+ dtParent.Constraints.Clear();
+ ds.Relations.Add(new DataRelation("myRelation",dtParent.Columns[0],dtChild.Columns[0]));
+
+ // Relation - Child Table Constraints Count
+ Assert.AreEqual(1, dtChild.Constraints.Count , "FKC");
+
+ // Relation - Parent Table Constraints Count
+ Assert.AreEqual(1, dtParent.Constraints.Count , "FKC");
+
+ // Relation - Parent Table Constraints type
+ Assert.AreEqual(typeof(UniqueConstraint), dtParent.Constraints[0].GetType() , "FKC");
+
+ // Relation - Parent Table Constraints type
+ Assert.AreEqual(typeof(ForeignKeyConstraint), dtChild.Constraints[0].GetType() , "FKC");
+
+ // Relation - Parent Table Primary key
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "FKC");
+ }
+
+ [Test] public void ctor_NameParentColChildCol()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint("myForeignKey",dtParent.Columns[0],dtChild.Columns[0]);
+
+ // Ctor
+ Assert.AreEqual(false , fc == null , "FKC");
+
+ // Ctor - name
+ Assert.AreEqual("myForeignKey" , fc.ConstraintName , "FKC");
+ }
+
+ [Test] public void ctor_NameParentColsChildCols()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint("myForeignKey",new DataColumn[] {dtParent.Columns[0]} ,new DataColumn[] {dtChild.Columns[0]});
+
+ // Ctor
+ Assert.AreEqual(false , fc == null , "FKC");
+
+ // Ctor - name
+ Assert.AreEqual("myForeignKey" , fc.ConstraintName , "FKC");
+ }
+
+ [Test] public void deleteRule()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ ds.Tables.Add(dtParent);
+ ds.Tables.Add(dtChild);
+ dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
+ ds.EnforceConstraints = true;
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ //checking default
+ // Default
+ Assert.AreEqual(Rule.Cascade , fc.DeleteRule , "FKC");
+
+ //checking set/get
+ foreach (Rule rule in Enum.GetValues(typeof(Rule)))
+ {
+ // Set/Get - rule
+ fc.DeleteRule = rule;
+ Assert.AreEqual(rule, fc.DeleteRule , "FKC");
+ }
+
+ dtChild.Constraints.Add(fc);
+
+ //checking delete rule
+
+ // Rule = None, Delete Exception
+ fc.DeleteRule = Rule.None;
+ //Exception = "Cannot delete this row because constraints are enforced on relation Constraint1, and deleting this row will strand child rows."
+ try
+ {
+ dtParent.Rows.Find(1).Delete();
+ Assert.Fail("DS333: Find Indexer Failed to throw InvalidConstraintException");
+ }
+ catch (InvalidConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: Find. Wrong exception type. Got:" + exc);
+ }
+
+ // Rule = None, Delete succeed
+ fc.DeleteRule = Rule.None;
+ foreach (DataRow dr in dtChild.Select("ParentId = 1"))
+ dr.Delete();
+ dtParent.Rows.Find(1).Delete();
+ Assert.AreEqual(0, dtParent.Select("ParentId=1").Length , "FKC");
+
+ // Rule = Cascade
+ fc.DeleteRule = Rule.Cascade;
+ dtParent.Rows.Find(2).Delete();
+ Assert.AreEqual(0, dtChild.Select("ParentId=2").Length , "FKC");
+
+ // Rule = SetNull
+ DataSet ds1 = new DataSet();
+ ds1.Tables.Add(DataProvider.CreateParentDataTable());
+ ds1.Tables.Add(DataProvider.CreateChildDataTable());
+
+ ForeignKeyConstraint fc1 = new ForeignKeyConstraint(ds1.Tables[0].Columns[0],ds1.Tables[1].Columns[1]);
+ fc1.DeleteRule = Rule.SetNull;
+ ds1.Tables[1].Constraints.Add(fc1);
+
+ Assert.AreEqual(0, ds1.Tables[1].Select("ChildId is null").Length, "FKC");
+
+ ds1.Tables[0].PrimaryKey= new DataColumn[] {ds1.Tables[0].Columns[0]};
+ ds1.Tables[0].Rows.Find(3).Delete();
+
+ ds1.Tables[0].AcceptChanges();
+ ds1.Tables[1].AcceptChanges();
+
+ DataRow[] arr = ds1.Tables[1].Select("ChildId is null");
+
+ /*foreach (DataRow dr in arr)
+ {
+ Assert.AreEqual(null, dr["ChildId"], "FKC");
+ }*/
+
+ Assert.AreEqual(4, arr.Length , "FKC");
+
+ // Rule = SetDefault
+ //fc.DeleteRule = Rule.SetDefault;
+ ds1 = new DataSet();
+ ds1.Tables.Add(DataProvider.CreateParentDataTable());
+ ds1.Tables.Add(DataProvider.CreateChildDataTable());
+
+ fc1 = new ForeignKeyConstraint(ds1.Tables[0].Columns[0],ds1.Tables[1].Columns[1]);
+ fc1.DeleteRule = Rule.SetDefault;
+ ds1.Tables[1].Constraints.Add(fc1);
+ ds1.Tables[1].Columns[1].DefaultValue="777";
+
+ //Add new row --> in order to apply the forigen key rules
+ DataRow dr2 = ds1.Tables[0].NewRow();
+ dr2["ParentId"] = 777;
+ ds1.Tables[0].Rows.Add(dr2);
+
+ ds1.Tables[0].PrimaryKey= new DataColumn[] {ds1.Tables[0].Columns[0]};
+ ds1.Tables[0].Rows.Find(3).Delete();
+ Assert.AreEqual(4, ds1.Tables[1].Select("ChildId=777").Length , "FKC");
+ }
+
+ [Test] public void extendedProperties()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ DataTable dtChild = DataProvider.CreateParentDataTable();
+
+ ForeignKeyConstraint fc = null;
+ fc = new ForeignKeyConstraint(dtParent.Columns[0],dtChild.Columns[0]);
+
+ PropertyCollection pc = fc.ExtendedProperties ;
+
+ // Checking ExtendedProperties default
+ Assert.AreEqual(true, fc != null, "FKC");
+
+ // Checking ExtendedProperties count
+ Assert.AreEqual(0, pc.Count , "FKC");
+ }
+ }
+}
--- /dev/null
+// Authors:
+// Rafael Mizrahi <rafim@mainsoft.com>
+// Erez Lotan <erezl@mainsoft.com>
+// Oren Gurfinkel <oreng@mainsoft.com>
+// Ofer Borstein
+//
+// Copyright (c) 2004 Mainsoft Co.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.Data;
+using MonoTests.System.Data.Test.Utils;
+
+namespace MonoTests_System.Data
+{
+ [TestFixture] public class UniqueConstraintTest2
+ {
+ [Test] public void Columns()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0]);
+
+ // Columns 1
+ Assert.AreEqual(1, uc.Columns.Length , "UC1");
+
+ // Columns 2
+ Assert.AreEqual(dtParent.Columns[0], uc.Columns[0], "UC2");
+ }
+
+ [Test] public void Equals_O()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+
+ UniqueConstraint uc1,uc2;
+ uc1 = new UniqueConstraint(dtParent.Columns[0]);
+
+ uc2 = new UniqueConstraint(dtParent.Columns[1]);
+ // different columnn
+ Assert.AreEqual(false, uc1.Equals(uc2), "UC3");
+
+ //Two System.Data.ForeignKeyConstraint are equal if they constrain the same columns.
+ // same column
+ uc2 = new UniqueConstraint(dtParent.Columns[0]);
+ Assert.AreEqual(true, uc1.Equals(uc2), "UC4");
+ }
+
+ [Test] public void IsPrimaryKey()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0],false);
+ dtParent.Constraints.Add(uc);
+
+ // primary key 1
+ Assert.AreEqual(false, uc.IsPrimaryKey , "UC5");
+
+ dtParent.Constraints.Remove(uc);
+ uc = new UniqueConstraint(dtParent.Columns[0],true);
+ dtParent.Constraints.Add(uc);
+
+ // primary key 2
+ Assert.AreEqual(true, uc.IsPrimaryKey , "UC6");
+ }
+
+ [Test] public void Table()
+ {
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0]);
+
+ // Table
+ Assert.AreEqual(dtParent , uc.Table , "UC7");
+ }
+
+ [Test] public new void ToString()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0],false);
+
+ // ToString - default
+ Assert.AreEqual(string.Empty , uc.ToString(), "UC8");
+
+ uc = new UniqueConstraint("myConstraint",dtParent.Columns[0],false);
+ // Tostring - Constraint name
+ Assert.AreEqual("myConstraint", uc.ToString(), "UC9");
+ }
+
+ [Test] public void constraintName()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0]);
+
+ // default
+ Assert.AreEqual(string.Empty , uc.ConstraintName , "UC10");
+
+ uc.ConstraintName = "myConstraint";
+
+ // set/get
+ Assert.AreEqual("myConstraint" , uc.ConstraintName , "UC11");
+ }
+
+ [Test] public void ctor_DataColumn()
+ {
+ Exception tmpEx = new Exception();
+
+ DataSet ds = new DataSet();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+ ds.Tables.Add(dtParent);
+ ds.EnforceConstraints = true;
+
+ UniqueConstraint uc = null;
+
+ // DataColumn.Unique - without constraint
+ Assert.AreEqual(false, dtParent.Columns[0].Unique , "UC12");
+
+ uc = new UniqueConstraint(dtParent.Columns[0]);
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC13");
+
+ // DataColumn.Unique - with constraint
+ Assert.AreEqual(false, dtParent.Columns[0].Unique , "UC14");
+
+ // Ctor - add exisiting column
+ dtParent.Rows.Add(new object[] {99,"str1","str2"});
+ dtParent.Constraints.Add(uc);
+ try
+ {
+ dtParent.Rows.Add(new object[] {99,"str1","str2"});
+ Assert.Fail("DS333: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ uc = new UniqueConstraint(dtChild.Columns[1]);
+
+ //Column[1] is not unique, will throw exception
+ // ArgumentException
+ try
+ {
+ dtChild.Constraints.Add(uc);
+ Assert.Fail("DS333: Constraints.Add Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: Constraints.Add. Wrong exception type. Got:" + exc);
+ }
+
+ //reset the table
+ dtParent = DataProvider.CreateParentDataTable();
+
+ // DataColumn.Unique = true, will add UniqueConstraint
+ dtParent.Columns[0].Unique = true;
+ Assert.AreEqual(1, dtParent.Constraints.Count , "UC15");
+
+ // Check the created UniqueConstraint
+ dtParent.Columns[0].Unique = true;
+ Assert.AreEqual(typeof(UniqueConstraint).FullName, dtParent.Constraints[0].GetType().FullName , "UC16");
+
+ // add UniqueConstarint that don't belong to the table
+ try
+ {
+ dtParent.Constraints.Add(uc);
+ Assert.Fail("DS333: Constraints.Add Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: Constraints.Add. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void ctor_DataColumnNoPrimary()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0],false);
+ dtParent.Constraints.Add(uc);
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC17");
+
+ // primary key 1
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "UC18");
+
+ dtParent.Constraints.Remove(uc);
+ uc = new UniqueConstraint(dtParent.Columns[0],true);
+ dtParent.Constraints.Add(uc);
+
+ // primary key 2
+ Assert.AreEqual(1, dtParent.PrimaryKey.Length , "UC19");
+ }
+
+ [Test] public void ctor_DataColumns()
+ {
+ Exception tmpEx = new Exception();
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(new DataColumn[] {dtParent.Columns[0],dtParent.Columns[1]});
+
+ // Ctor - parent
+ Assert.AreEqual(false , uc == null , "UC20");
+
+ // Ctor - add exisiting column
+ dtParent.Rows.Add(new object[] {99,"str1","str2"});
+ dtParent.Constraints.Add(uc);
+ try
+ {
+ dtParent.Rows.Add(new object[] {99,"str1","str2"});
+ Assert.Fail("DS333: Rows.Add Failed to throw ConstraintException");
+ }
+ catch (ConstraintException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: Rows.Add. Wrong exception type. Got:" + exc);
+ }
+
+ DataTable dtChild = DataProvider.CreateChildDataTable();
+ uc = new UniqueConstraint(new DataColumn[] {dtChild.Columns[0],dtChild.Columns[1]});
+ dtChild.Constraints.Add(uc);
+
+ // Ctor - child
+ Assert.AreEqual(false , uc == null , "UC21");
+
+ dtChild.Constraints.Clear();
+ uc = new UniqueConstraint(new DataColumn[] {dtChild.Columns[1],dtChild.Columns[2]});
+
+ //target columnn are not unnique, will throw an exception
+ // ArgumentException - child
+ try
+ {
+ dtChild.Constraints.Add(uc);
+ Assert.Fail("DS333: Constraints.Add Failed to throw ArgumentException");
+ }
+ catch (ArgumentException) {}
+ catch (AssertionException exc) {throw exc;}
+ catch (Exception exc)
+ {
+ Assert.Fail("DS334: Constraints.Add. Wrong exception type. Got:" + exc);
+ }
+ }
+
+ [Test] public void ctor_DataColumnPrimary()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0],false);
+ dtParent.Constraints.Add(uc);
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC22");
+
+ // primary key 1
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "UC23");
+
+ dtParent.Constraints.Remove(uc);
+ uc = new UniqueConstraint(dtParent.Columns[0],true);
+ dtParent.Constraints.Add(uc);
+
+ // primary key 2
+ Assert.AreEqual(1, dtParent.PrimaryKey.Length , "UC24");
+ }
+
+ [Test] public void ctor_NameDataColumn()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint("myConstraint",dtParent.Columns[0]);
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC25");
+
+ // Ctor name
+ Assert.AreEqual("myConstraint", uc.ConstraintName , "UC26");
+ }
+
+ [Test] public void ctor_NameDataColumnPrimary()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint("myConstraint",dtParent.Columns[0],false);
+ dtParent.Constraints.Add(uc);
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC27");
+
+ // primary key 1
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "UC28");
+
+ // Ctor name 1
+ Assert.AreEqual("myConstraint", uc.ConstraintName , "UC29");
+
+ dtParent.Constraints.Remove(uc);
+ uc = new UniqueConstraint("myConstraint",dtParent.Columns[0],true);
+ dtParent.Constraints.Add(uc);
+
+ // primary key 2
+ Assert.AreEqual(1, dtParent.PrimaryKey.Length , "UC30");
+
+ // Ctor name 2
+ Assert.AreEqual("myConstraint", uc.ConstraintName , "UC31");
+ }
+
+ [Test] public void ctor_NameDataColumns()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint("myConstraint",new DataColumn[] {dtParent.Columns[0],dtParent.Columns[1]});
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC32");
+
+ // Ctor name
+ Assert.AreEqual("myConstraint", uc.ConstraintName , "UC33");
+ }
+
+ [Test] public void ctor_NameDataColumnsPrimary()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint("myConstraint",new DataColumn[] {dtParent.Columns[0]},false);
+ dtParent.Constraints.Add(uc);
+
+ // Ctor
+ Assert.AreEqual(false , uc == null , "UC34");
+
+ // primary key 1
+ Assert.AreEqual(0, dtParent.PrimaryKey.Length , "UC35");
+
+ // Ctor name 1
+ Assert.AreEqual("myConstraint", uc.ConstraintName , "UC36");
+
+ dtParent.Constraints.Remove(uc);
+ uc = new UniqueConstraint("myConstraint",new DataColumn[] {dtParent.Columns[0]},true);
+ dtParent.Constraints.Add(uc);
+
+ // primary key 2
+ Assert.AreEqual(1, dtParent.PrimaryKey.Length , "UC37");
+
+ // Ctor name 2
+ Assert.AreEqual("myConstraint", uc.ConstraintName , "UC38");
+ }
+
+ [Test] public void extendedProperties()
+ {
+ DataTable dtParent = DataProvider.CreateParentDataTable();
+
+ UniqueConstraint uc = null;
+ uc = new UniqueConstraint(dtParent.Columns[0]);
+ PropertyCollection pc = uc.ExtendedProperties ;
+
+ // Checking ExtendedProperties default
+ Assert.AreEqual(true, pc != null, "UC39");
+
+ // Checking ExtendedProperties count
+ Assert.AreEqual(0, pc.Count , "UC40");
+ }
+ }
+}