2 // Rafael Mizrahi <rafim@mainsoft.com>
3 // Erez Lotan <erezl@mainsoft.com>
4 // Oren Gurfinkel <oreng@mainsoft.com>
7 // Copyright (c) 2004 Mainsoft Co.
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
34 using MonoTests.System.Data.Utils;
36 namespace MonoTests_System.Data
38 [TestFixture] public class InvalidConstraintExceptionTest
40 [Test] public void Generate()
43 dtParent= DataProvider.CreateParentDataTable();
44 Exception tmpEx = new Exception();
46 //------ check ForeignKeyConstraint ---------
47 DataTable dtChild = DataProvider.CreateChildDataTable();
48 DataSet ds = new DataSet();
49 ds.Tables.Add(dtChild);
50 ds.Tables.Add(dtParent);
52 ds.Relations.Add(new DataRelation("myRelation",dtParent.Columns[0],dtChild.Columns[0],true));
54 //update to value which is not exists in Parent table
55 // InvalidConstraintException - update child row
58 dtChild.Rows[0]["ParentId"] = 99;
59 Assert.Fail("ICE1: Rows Indexer failed to raise InvalidConstraintException.");
61 catch (InvalidConstraintException) {}
62 catch (AssertionException) { throw; }
65 Assert.Fail("ICE2: Rows Indexer wrong exception type. Got: " + exc);
68 //Add another relation to the same column of the existing relation in child table
69 // InvalidConstraintException - Add Relation Child
72 ds.Relations.Add(new DataRelation("test",dtParent.Columns[2],dtChild.Columns[0],true));
73 Assert.Fail("ICE3: Relations.Add failed to raise InvalidConstraintException.");
75 catch (InvalidConstraintException) {}
76 catch (AssertionException) { throw; }
79 Assert.Fail("ICE4: Relations.Add wrong exception type. Got: " + exc);
82 // ?????????????????? should throw exception - according to MSDN
83 // // InvalidConstraintException -
84 // //ds.Relations.Clear();
86 // dtParent.Rows[0].GetParentRows("myRelation");
87 // Assert.Fail("ICE5: Relations failed to raise InvalidConstraintException.");
89 // catch (InvalidConstraintException) {}
90 // catch (AssertionException) { throw; }
91 // catch (Exception exc)
93 // Assert.Fail("ICE6: Relations wrong exception type. Got: " + exc);
96 //Attempt to clear rows from parent table
97 // InvalidConstraintException - RowsCollection.Clear
100 dtParent.Rows.Clear();
101 Assert.Fail("ICE7: Rows.Clear failed to raise InvalidConstraintException.");
103 catch (InvalidConstraintException) {}
104 catch (AssertionException) { throw; }
105 catch (Exception exc)
107 Assert.Fail("ICE8: Rows.Clear wrong exception type. Got: " + exc);
110 //try to run commands on two different datasets
111 DataSet ds1 = new DataSet();
112 ds1.Tables.Add(dtParent.Copy());
114 // InvalidConstraintException - Add relation with two DataSets
117 ds.Relations.Add(new DataRelation("myRelation",ds1.Tables[0].Columns[0],dtChild.Columns[0],true));
118 Assert.Fail("ICE9: Relations.Add failed to raise InvalidConstraintException.");
120 catch (InvalidConstraintException) {}
121 catch (AssertionException) { throw; }
122 catch (Exception exc)
124 Assert.Fail("ICE10: Relations.Add wrong exception type. Got: " + exc);