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.Data;
32 using MonoTests.System.Data.Utils;
33 
34 namespace MonoTests.System.Data
35 {
36 	[TestFixture] public class RowNotInTableExceptionTest
37 	{
38 		[Test]
Generate()39 		public void Generate()
40 		{
41 			DataSet ds = new DataSet();
42 			ds.Tables.Add(DataProvider.CreateParentDataTable());
43 			ds.Tables.Add(DataProvider.CreateChildDataTable());
44 			ds.Relations.Add(new DataRelation("myRelation",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));
45 
46 			DataRow drParent = ds.Tables[0].Rows[0];
47 			DataRow drChild = ds.Tables[1].Rows[0];
48 			drParent.Delete();
49 			drChild.Delete();
50 			ds.AcceptChanges();
51 
52 			// RowNotInTableException - AcceptChanges
53 			try
54 			{
55 				drParent.AcceptChanges();
56 				Assert.Fail("RNT1: AcceptChanges failed to raise (RowNotInTableException.");
57 			}
58 			catch (RowNotInTableException) {}
59 			catch (AssertionException) { throw; }
60 			catch (Exception exc)
61 			{
62 				Assert.Fail("RNT2: AcceptChanges wrong exception type. Got: " + exc);
63 			}
64 
65 			// RowNotInTableException - GetChildRows
66 			try
67 			{
68 				drParent.GetChildRows("myRelation");
69 				Assert.Fail("RNT1: GetChildRows failed to raise (RowNotInTableException.");
70 			}
71 			catch (RowNotInTableException) {}
72 			catch (AssertionException) { throw; }
73 			catch (Exception exc)
74 			{
75 				Assert.Fail("RNT2: GetChildRows wrong exception type. Got: " + exc);
76 			}
77 
78 			// RowNotInTableException - ItemArray
79 			object[] o = null;
80 			try
81 			{
82 				o = drParent.ItemArray ;
83 				Assert.Fail("RNT1: ItemArray failed to raise (RowNotInTableException.");
84 			}
85 			catch (RowNotInTableException) {}
86 			catch (AssertionException) { throw; }
87 			catch (Exception exc)
88 			{
89 				Assert.Fail("RNT2: ItemArray wrong exception type. Got: " + exc);
90 			}
91 
92 			// **********	don't throw exception (should be according to MSDN)	***********************
93 			//		// RowNotInTableException - GetParentRow
94 			//		try
95 			//		{
96 			//			DataRow dr = null;
97 			//			dr = drChild.GetParentRow("myRelation");
98 			//			Assert.Fail("RNT1: GetParentRow failed to raise (RowNotInTableException.");
99 			//		}
100 			//		catch (RowNotInTableException) {}
101 			//		catch (AssertionException) { throw; }
102 			//		catch (Exception exc)
103 			//		{
104 			//			Assert.Fail("RNT2: GetParentRow wrong exception type. Got: " + exc);
105 			//		}
106 
107 			// RowNotInTableException - GetParentRows
108 			DataRow[] dr = null;
109 			try
110 			{
111 				dr = drChild.GetParentRows("myRelation");
112 				Assert.Fail("RNT1: GetParentRows failed to raise (RowNotInTableException.");
113 			}
114 			catch (RowNotInTableException) {}
115 			catch (AssertionException) { throw; }
116 			catch (Exception exc)
117 			{
118 				Assert.Fail("RNT2: GetParentRows wrong exception type. Got: " + exc);
119 			}
120 
121 			// RowNotInTableException - RejectChanges
122 			try
123 			{
124 				drParent.RejectChanges();
125 				Assert.Fail("RNT1: RejectChanges failed to raise (RowNotInTableException.");
126 			}
127 			catch (RowNotInTableException) {}
128 			catch (AssertionException) { throw; }
129 			catch (Exception exc)
130 			{
131 				Assert.Fail("RNT2: RejectChanges wrong exception type. Got: " + exc);
132 			}
133 
134 			// RowNotInTableException - SetParentRow
135 			try
136 			{
137 				drChild.SetParentRow(ds.Tables[0].Rows[1]);
138 				Assert.Fail("RNT1: SetParentRow failed to raise (RowNotInTableException.");
139 			}
140 			catch (RowNotInTableException) {}
141 			catch (AssertionException) { throw; }
142 			catch (Exception exc)
143 			{
144 				Assert.Fail("RNT2: SetParentRow wrong exception type. Got: " + exc);
145 			}
146 		}
147 	}
148 }
149