Added time format with only offset. Fixes #22558.
[mono.git] / mcs / class / System.Data / Test / System.Data / InvalidConstraintExceptionTest.cs
1 // Authors:
2 //   Rafael Mizrahi   <rafim@mainsoft.com>
3 //   Erez Lotan       <erezl@mainsoft.com>
4 //   Oren Gurfinkel   <oreng@mainsoft.com>
5 //   Ofer Borstein
6 //
7 // Copyright (c) 2004 Mainsoft Co.
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27 //
28
29 using NUnit.Framework;
30 using System;
31 using System.Text;
32 using System.IO;
33 using System.Data;
34 using MonoTests.System.Data.Utils;
35
36 namespace MonoTests_System.Data
37 {
38         [TestFixture] public class InvalidConstraintExceptionTest
39         {
40                 [Test] public void Generate()
41                 {
42                         DataTable dtParent;
43                         dtParent= DataProvider.CreateParentDataTable(); 
44                         Exception tmpEx = new Exception();
45
46                         //------ check ForeignKeyConstraint  ---------
47                         DataTable dtChild = DataProvider.CreateChildDataTable(); 
48                         DataSet ds = new DataSet();
49                         ds.Tables.Add(dtChild);
50                         ds.Tables.Add(dtParent);
51
52                         ds.Relations.Add(new DataRelation("myRelation",dtParent.Columns[0],dtChild.Columns[0],true));
53
54                         //update to value which is not exists in Parent table
55                         // InvalidConstraintException - update child row
56                         try 
57                         {
58                                 dtChild.Rows[0]["ParentId"] = 99;
59                                 Assert.Fail("ICE1: Rows Indexer failed to raise InvalidConstraintException.");
60                         }
61                         catch (InvalidConstraintException) {}
62                         catch (AssertionException) { throw; }
63                         catch (Exception exc)
64                         {
65                                 Assert.Fail("ICE2: Rows Indexer wrong exception type. Got: " + exc);
66                         }
67
68                         //Add another relation to the same column of the existing relation in child table
69                         // InvalidConstraintException - Add Relation Child
70                         try 
71                         {
72                                 ds.Relations.Add(new DataRelation("test",dtParent.Columns[2],dtChild.Columns[0],true));
73                                 Assert.Fail("ICE3: Relations.Add failed to raise InvalidConstraintException.");
74                         }
75                         catch (InvalidConstraintException) {}
76                         catch (AssertionException) { throw; }
77                         catch (Exception exc)
78                         {
79                                 Assert.Fail("ICE4: Relations.Add wrong exception type. Got: " + exc);
80                         }
81
82                         //          ?????????????????? should throw exception - according to MSDN 
83                         //              // InvalidConstraintException - 
84                         //              //ds.Relations.Clear();
85                         //              try {
86                         //                      dtParent.Rows[0].GetParentRows("myRelation");
87                         //                      Assert.Fail("ICE5: Relations failed to raise InvalidConstraintException.");
88                         //              }
89                         //              catch (InvalidConstraintException) {}
90                         //              catch (AssertionException) { throw; }
91                         //              catch (Exception exc)
92                         //              {
93                         //                      Assert.Fail("ICE6: Relations wrong exception type. Got: " + exc);
94                         //              }
95
96                         //Attempt to clear rows from parent table 
97                         // InvalidConstraintException - RowsCollection.Clear
98                         try 
99                         {
100                                 dtParent.Rows.Clear();
101                                 Assert.Fail("ICE7: Rows.Clear failed to raise InvalidConstraintException.");
102                         }
103                         catch (InvalidConstraintException) {}
104                         catch (AssertionException) { throw; }
105                         catch (Exception exc)
106                         {
107                                 Assert.Fail("ICE8: Rows.Clear wrong exception type. Got: " + exc);
108                         }
109
110                         //try to run commands on two different datasets
111                         DataSet ds1 = new DataSet();
112                         ds1.Tables.Add(dtParent.Copy());
113
114                         // InvalidConstraintException - Add relation with two DataSets
115                         try 
116                         {
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.");
119                         }
120                         catch (InvalidConstraintException) {}
121                         catch (AssertionException) { throw; }
122                         catch (Exception exc)
123                         {
124                                 Assert.Fail("ICE10: Relations.Add wrong exception type. Got: " + exc);
125                         }
126                 }
127         }
128 }