0867a3bc76d062885104f5aa60391162f2e18a25
[mono.git] / mcs / class / System.Data / Test / System.Data / DataSetAssertion.cs
1 //
2 // DataSetAssertion.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // (C)2004 Novell Inc.
8 //
9
10 using System;
11 using System.IO;
12 using System.Data;
13 using System.Text;
14 using System.Xml;
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Data
18 {
19         public class DataSetAssertion : Assertion
20         {
21                 public void AssertDataSet (string label, DataSet ds, string name, int tableCount, int relCount)
22                 {
23                         AssertEquals (label + ".DataSetName", name, ds.DataSetName);
24                         AssertEquals (label + ".TableCount", tableCount, ds.Tables.Count);
25                         if (relCount >= 0)
26                                 AssertEquals (label + ".RelationCount", relCount, ds.Relations.Count);
27                 }
28
29                 public void AssertDataTable (string label, DataTable dt, string name, int columnCount, int rowCount, int parentRelationCount, int childRelationCount, int constraintCount, int primaryKeyLength)
30                 {
31                         AssertEquals (label + ".TableName", name, dt.TableName);
32                         AssertEquals (label + ".ColumnCount", columnCount, dt.Columns.Count);
33                         AssertEquals (label + ".RowCount", rowCount, dt.Rows.Count);
34                         AssertEquals (label + ".ParentRelCount", parentRelationCount, dt.ParentRelations.Count);
35                         AssertEquals (label + ".ChildRelCount", childRelationCount, dt.ChildRelations.Count);
36                         AssertEquals (label + ".ConstraintCount", constraintCount, dt.Constraints.Count);
37                         AssertEquals (label + ".PrimaryKeyLength", primaryKeyLength, dt.PrimaryKey.Length);
38                 }
39
40                 public void AssertReadXml (DataSet ds, string label, string xml, XmlReadMode readMode, XmlReadMode resultMode, string datasetName, int tableCount)
41                 {
42                         AssertReadXml (ds, label, xml, readMode, resultMode, datasetName, tableCount, ReadState.EndOfFile);
43                 }
44
45                 // a bit detailed version
46                 public void AssertReadXml (DataSet ds, string label, string xml, XmlReadMode readMode, XmlReadMode resultMode, string datasetName, int tableCount, ReadState state)
47                 {
48                         XmlReader xtr = new XmlTextReader (xml, XmlNodeType.Element, null);
49                         AssertEquals (label + ".return", resultMode, ds.ReadXml (xtr, readMode));
50                         AssertDataSet (label + ".dataset", ds, datasetName, tableCount, -1);
51                         AssertEquals (label + ".readstate", state, xtr.ReadState);
52                 }
53
54                 public void AssertDataRelation (string label, DataRelation rel, string name, bool nested,
55                         string [] parentColNames, string [] childColNames,
56                         bool existsUK, bool existsFK)
57                 {
58                         AssertEquals (label + ".Name", name, rel.RelationName);
59                         AssertEquals (label + ".Nested", nested, rel.Nested);
60                         for (int i = 0; i < parentColNames.Length; i++)
61                                 AssertEquals (label + ".parentColumn_" + i, parentColNames [i], rel.ParentColumns [i].ColumnName);
62                         AssertEquals (label + ".ParentColCount", parentColNames.Length, rel.ParentColumns.Length);
63                         for (int i = 0; i < childColNames.Length; i++)
64                                 AssertEquals (label + ".childColumn_" + i, childColNames [i], rel.ChildColumns [i].ColumnName);
65                         AssertEquals (label + ".ChildColCount", childColNames.Length, rel.ChildColumns.Length);
66                         if (existsUK)
67                                 AssertNotNull (label + ".uniqKeyExists", rel.ParentKeyConstraint);
68                         else
69                                 AssertNull (label + ".uniqKeyNotExists", rel.ParentKeyConstraint);
70                         if (existsFK)
71                                 AssertNotNull (label + ".fkExists", rel.ChildKeyConstraint);
72                         else
73                                 AssertNull (label + ".fkNotExists", rel.ChildKeyConstraint);
74                 }
75
76                 public void AssertUniqueConstraint (string label, UniqueConstraint uc, 
77                         string name, bool isPrimaryKey, string [] colNames)
78                 {
79                         AssertEquals (label + ".name", name, uc.ConstraintName);
80                         AssertEquals (label + ".pkey", isPrimaryKey, uc.IsPrimaryKey);
81                         for (int i = 0; i < colNames.Length; i++)
82                                 AssertEquals (label + ".column_" + i, colNames [i], uc.Columns [i].ColumnName);
83                         AssertEquals (label + ".colCount", colNames.Length, uc.Columns.Length);
84                 }
85
86                 public void AssertForeignKeyConstraint (string label,
87                         ForeignKeyConstraint fk, string name, 
88                         AcceptRejectRule acceptRejectRule, Rule delRule, Rule updateRule,
89                         string [] colNames, string [] relColNames)
90                 {
91                         AssertEquals (label + ".name", name, fk.ConstraintName);
92                         AssertEquals (label + ".acceptRejectRule", acceptRejectRule, fk.AcceptRejectRule);
93                         AssertEquals (label + ".delRule", delRule, fk.DeleteRule);
94                         AssertEquals (label + ".updateRule", updateRule, fk.UpdateRule);
95                         for (int i = 0; i < colNames.Length; i++)
96                                 AssertEquals (label + ".column_" + i, colNames [i], fk.Columns [i].ColumnName);
97                         AssertEquals (label + ".colCount", colNames.Length, fk.Columns.Length);
98                         for (int i = 0; i < relColNames.Length; i++)
99                                 AssertEquals (label + ".relatedColumn_" + i, relColNames [i], fk.RelatedColumns [i].ColumnName);
100                         AssertEquals (label + ".relatedColCount", relColNames.Length, fk.RelatedColumns.Length);
101                 }
102 \r
103                 public void AssertDataColumn (string label, DataColumn col, \r
104                         string colName, bool allowDBNull, \r
105                         bool autoIncr, int autoIncrSeed, int autoIncrStep, \r
106                         string caption, MappingType colMap, \r
107                         Type type, object defaultValue, string expression, \r
108                         int maxLength, string ns, int ordinal, string prefix, \r
109                         bool readOnly, bool unique)\r
110                 {\r
111                         AssertEquals (label + "ColumnName: " , colName, col.ColumnName);\r
112                         AssertEquals (label + "AllowDBNull? " , allowDBNull, col.AllowDBNull);\r
113                         AssertEquals (label + "AutoIncrement? " , autoIncr, col.AutoIncrement);\r
114                         AssertEquals (label + "  Seed: " , autoIncrSeed, col.AutoIncrementSeed);\r
115                         AssertEquals (label + "  Step: " , autoIncrStep, col.AutoIncrementStep);\r
116                         AssertEquals (label + "Caption " , caption, col.Caption);\r
117                         AssertEquals (label + "Mapping: " , colMap, col.ColumnMapping);\r
118                         AssertEquals (label + "Type: " , type, col.DataType);\r
119                         AssertEquals (label + "DefaultValue: " , defaultValue, col.DefaultValue);\r
120                         AssertEquals (label + "Expression: " , expression, col.Expression);\r
121                         AssertEquals (label + "MaxLength: " , maxLength, col.MaxLength);\r
122                         AssertEquals (label + "Namespace: " , ns, col.Namespace);\r
123 //                      AssertEquals (label + "Ordinal: " , ordinal, col.Ordinal);\r
124                         AssertEquals (label + "Prefix: " , prefix, col.Prefix);\r
125                         AssertEquals (label + "ReadOnly: " , readOnly, col.ReadOnly);\r
126                         AssertEquals (label + "Unique: " , unique, col.Unique);\r
127                 }\r
128         }
129 }
130