* DataGridViewRowTest.cs: Comment out more asserts that probably are
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridViewRowTest.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
21 //
22 // Author:
23 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using NUnit.Framework;
30 using System;
31 using System.Drawing;
32 using System.Windows.Forms;
33 using System.Collections;
34
35 namespace MonoTests.System.Windows.Forms {
36
37         [TestFixture]
38         public class DataGridViewRowTest {
39                 
40                 [SetUp]
41                 public void GetReady() {}
42
43                 [TearDown]
44                 public void Clean() {}
45
46                 [Test]
47                 public void TestDefaultValues () {
48                 }
49
50                 [Test]
51                 [ExpectedException(typeof(InvalidOperationException))]
52                 public void TestVisibleInvalidOperationException () {
53                         DataGridView grid = new DataGridView();
54                         DataGridViewRow row = new DataGridViewRow();
55                         grid.Rows.Add(row);
56                         row.Visible = false;
57                 }
58
59                 [Test]
60                 public void Height ()
61                 {
62                         DataGridViewRow row = new DataGridViewRow();
63                         Assert.IsTrue (row.Height > 5, "#1");
64                         row.Height = 70;
65                         Assert.AreEqual (70, row.Height, "#2");
66                         row.Height = 40;
67                         Assert.AreEqual (40, row.Height, "#3");
68                 }
69
70                 [Test]
71                 [Category ("NotWorking")]
72                 public void MinimumHeight ()
73                 {
74                         DataGridViewRow row = new DataGridViewRow();
75                         Assert.IsTrue (row.MinimumHeight > 0, "#A1");
76                         Assert.IsFalse (row.Height > row.MinimumHeight, "#A2");
77                         row.MinimumHeight = 40;
78                         row.Height = 50;
79                         Assert.AreEqual (40, row.MinimumHeight, "#B1");
80                         Assert.AreEqual (50, row.Height, "#B2");
81                         row.MinimumHeight = 20;
82                         Assert.AreEqual (20, row.MinimumHeight, "#C1");
83                         Assert.AreEqual (20, row.Height, "#C2");
84                         row.MinimumHeight = 40;
85                         Assert.AreEqual (40, row.MinimumHeight, "#D1");
86                         Assert.AreEqual (40, row.Height, "#D2");
87                 }
88                 
89                 
90                 
91
92                 [Test]
93                 public void AddRow_Changes ()
94                 {
95
96                         using (DataGridView dgv = new DataGridView ()) {
97                                 DataGridViewColumn col = new DataGridViewComboBoxColumn ();
98                                 DataGridViewRow row = new DataGridViewRow ();
99                                 DataGridViewCell cell = new DataGridViewComboBoxCell ();
100                                 
101                                 Assert.IsNotNull (row.AccessibilityObject, "#A row.AccessibilityObject");
102                                 Assert.IsNotNull (row.Cells, "#A row.Cells");
103                                 Assert.IsNull (row.ContextMenuStrip, "#A row.ContextMenuStrip");
104                                 Assert.IsNull (row.DataBoundItem, "#A row.DataBoundItem");
105                                 Assert.IsNull (row.DataGridView, "#A row.DataGridView");
106                                 Assert.IsNotNull (row.DefaultCellStyle, "#A row.DefaultCellStyle");
107                                 Assert.IsNotNull (row.DefaultHeaderCellType, "#A row.DefaultHeaderCellType");
108                                 Assert.AreEqual (false, row.Displayed, "#A row.Displayed");
109                                 Assert.AreEqual (0, row.DividerHeight, "#A row.DividerHeight");
110                                 Assert.AreEqual (@"", row.ErrorText, "#A row.ErrorText");
111                                 Assert.AreEqual (false, row.Frozen, "#A row.Frozen");
112                                 Assert.AreEqual (true, row.HasDefaultCellStyle, "#A row.HasDefaultCellStyle");
113                                 Assert.IsNotNull (row.HeaderCell, "#A row.HeaderCell");
114                                 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#A row.Height");
115                                 Assert.AreEqual (-1, row.Index, "#A row.Index");
116                                 try {
117                                         object zxf = row.InheritedStyle;
118                                         TestHelper.RemoveWarning (zxf);
119                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A row.InheritedStyle");
120                                 } catch (InvalidOperationException ex) {
121                                         Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
122                                 } catch (Exception ex) {
123                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A row.InheritedStyle");
124                                 }
125                                 Assert.AreEqual (false, row.IsNewRow, "#A row.IsNewRow");
126                                 Assert.AreEqual (3, row.MinimumHeight, "#A row.MinimumHeight");
127                                 Assert.AreEqual (false, row.ReadOnly, "#A row.ReadOnly");
128                                 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#A row.Resizable");
129                                 Assert.AreEqual (false, row.Selected, "#A row.Selected");
130                                 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#A row.State");
131                                 Assert.IsNull (row.Tag, "#A row.Tag");
132                                 Assert.AreEqual (true, row.Visible, "#A row.Visible");
133
134                                 row.Cells.Add (cell);
135
136                                 Assert.IsNotNull (row.AccessibilityObject, "#B row.AccessibilityObject");
137                                 Assert.IsNotNull (row.Cells, "#B row.Cells");
138                                 Assert.IsNull (row.ContextMenuStrip, "#B row.ContextMenuStrip");
139                                 Assert.IsNull (row.DataBoundItem, "#B row.DataBoundItem");
140                                 Assert.IsNull (row.DataGridView, "#B row.DataGridView");
141                                 Assert.IsNotNull (row.DefaultCellStyle, "#B row.DefaultCellStyle");
142                                 Assert.IsNotNull (row.DefaultHeaderCellType, "#B row.DefaultHeaderCellType");
143                                 Assert.AreEqual (false, row.Displayed, "#B row.Displayed");
144                                 Assert.AreEqual (0, row.DividerHeight, "#B row.DividerHeight");
145                                 Assert.AreEqual (@"", row.ErrorText, "#B row.ErrorText");
146                                 Assert.AreEqual (false, row.Frozen, "#B row.Frozen");
147                                 Assert.AreEqual (true, row.HasDefaultCellStyle, "#B row.HasDefaultCellStyle");
148                                 Assert.IsNotNull (row.HeaderCell, "#B row.HeaderCell");
149                                 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#B row.Height");
150                                 Assert.AreEqual (-1, row.Index, "#B row.Index");
151                                 try {
152                                         object zxf = row.InheritedStyle;
153                                         TestHelper.RemoveWarning (zxf);
154                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#B row.InheritedStyle");
155                                 } catch (InvalidOperationException ex) {
156                                         Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
157                                 } catch (Exception ex) {
158                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#B row.InheritedStyle");
159                                 }
160                                 Assert.AreEqual (false, row.IsNewRow, "#B row.IsNewRow");
161                                 Assert.AreEqual (3, row.MinimumHeight, "#B row.MinimumHeight");
162                                 Assert.AreEqual (false, row.ReadOnly, "#B row.ReadOnly");
163                                 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#B row.Resizable");
164                                 Assert.AreEqual (false, row.Selected, "#B row.Selected");
165                                 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#B row.State");
166                                 Assert.IsNull (row.Tag, "#B row.Tag");
167                                 Assert.AreEqual (true, row.Visible, "#B row.Visible");
168                                 
169                                 dgv.Columns.Add (col);
170                                 
171                                 Assert.IsNotNull (row.AccessibilityObject, "#C row.AccessibilityObject");
172                                 Assert.IsNotNull (row.Cells, "#C row.Cells");
173                                 Assert.IsNull (row.ContextMenuStrip, "#C row.ContextMenuStrip");
174                                 Assert.IsNull (row.DataBoundItem, "#C row.DataBoundItem");
175                                 Assert.IsNull (row.DataGridView, "#C row.DataGridView");
176                                 Assert.IsNotNull (row.DefaultCellStyle, "#C row.DefaultCellStyle");
177                                 Assert.IsNotNull (row.DefaultHeaderCellType, "#C row.DefaultHeaderCellType");
178                                 Assert.AreEqual (false, row.Displayed, "#C row.Displayed");
179                                 Assert.AreEqual (0, row.DividerHeight, "#C row.DividerHeight");
180                                 Assert.AreEqual (@"", row.ErrorText, "#C row.ErrorText");
181                                 Assert.AreEqual (false, row.Frozen, "#C row.Frozen");
182                                 Assert.AreEqual (true, row.HasDefaultCellStyle, "#C row.HasDefaultCellStyle");
183                                 Assert.IsNotNull (row.HeaderCell, "#C row.HeaderCell");
184                                 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#C row.Height");
185                                 Assert.AreEqual (-1, row.Index, "#C row.Index");
186                                 try {
187                                         object zxf = row.InheritedStyle;
188                                         TestHelper.RemoveWarning (zxf);
189                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#C row.InheritedStyle");
190                                 } catch (InvalidOperationException ex) {
191                                         Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
192                                 } catch (Exception ex) {
193                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#C row.InheritedStyle");
194                                 }
195                                 Assert.AreEqual (false, row.IsNewRow, "#C row.IsNewRow");
196                                 Assert.AreEqual (3, row.MinimumHeight, "#C row.MinimumHeight");
197                                 Assert.AreEqual (false, row.ReadOnly, "#C row.ReadOnly");
198                                 Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#C row.Resizable");
199                                 Assert.AreEqual (false, row.Selected, "#C row.Selected");
200                                 Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#C row.State");
201                                 Assert.IsNull (row.Tag, "#C row.Tag");
202                                 Assert.AreEqual (true, row.Visible, "#C row.Visible");
203                                 
204                                 dgv.Rows.Add (row);
205
206                                 Assert.IsNotNull (row.AccessibilityObject, "#D row.AccessibilityObject");
207                                 Assert.IsNotNull (row.Cells, "#D row.Cells");
208                                 try {
209                                         object zxf = row.ContextMenuStrip;
210                                         TestHelper.RemoveWarning (zxf);
211                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ContextMenuStrip");
212                                 } catch (InvalidOperationException ex) {
213                                         Assert.AreEqual (@"Operation cannot be performed on a shared row.", ex.Message);
214                                 } catch (Exception ex) {
215                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.ContextMenuStrip");
216                                 }
217                                 Assert.IsNull (row.DataBoundItem, "#D row.DataBoundItem");
218                                 Assert.IsNotNull (row.DataGridView, "#D row.DataGridView");
219                                 Assert.IsNotNull (row.DefaultCellStyle, "#D row.DefaultCellStyle");
220                                 Assert.IsNotNull (row.DefaultHeaderCellType, "#D row.DefaultHeaderCellType");
221                                 try {
222                                         object zxf = row.Displayed;
223                                         TestHelper.RemoveWarning (zxf);
224                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Displayed");
225                                 } catch (InvalidOperationException ex) {
226                                         Assert.AreEqual (@"Getting the Displayed property of a shared row is not a valid operation.", ex.Message);
227                                 } catch (Exception ex) {
228                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Displayed");
229                                 }
230                                 Assert.AreEqual (0, row.DividerHeight, "#D row.DividerHeight");
231                                 try {
232                                         object zxf = row.ErrorText;
233                                         TestHelper.RemoveWarning (zxf);
234                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ErrorText");
235                                 } catch (InvalidOperationException ex) {
236                                         Assert.AreEqual (@"Operation cannot be performed on a shared row.", ex.Message);
237                                 } catch (Exception ex) {
238                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.ErrorText");
239                                 }
240                                 try {
241                                         object zxf = row.Frozen;
242                                         TestHelper.RemoveWarning (zxf);
243                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Frozen");
244                                 } catch (InvalidOperationException ex) {
245                                         Assert.AreEqual (@"Getting the Frozen property of a shared row is not a valid operation.", ex.Message);
246                                 } catch (Exception ex) {
247                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Frozen");
248                                 }
249                                 Assert.AreEqual (true, row.HasDefaultCellStyle, "#D row.HasDefaultCellStyle");
250                                 Assert.IsNotNull (row.HeaderCell, "#D row.HeaderCell");
251                                 // DPI Dependent? // Assert.AreEqual (22, row.Height, "#D row.Height");
252                                 Assert.AreEqual (-1, row.Index, "#D row.Index");
253                                 try {
254                                         object zxf = row.InheritedStyle;
255                                         TestHelper.RemoveWarning (zxf);
256                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.InheritedStyle");
257                                 } catch (InvalidOperationException ex) {
258                                         Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
259                                 } catch (Exception ex) {
260                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.InheritedStyle");
261                                 }
262                                 Assert.AreEqual (false, row.IsNewRow, "#D row.IsNewRow");
263                                 Assert.AreEqual (3, row.MinimumHeight, "#D row.MinimumHeight");
264                                 try {
265                                         object zxf = row.ReadOnly;
266                                         TestHelper.RemoveWarning (zxf);
267                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.ReadOnly");
268                                 } catch (InvalidOperationException ex) {
269                                         Assert.AreEqual (@"Getting the ReadOnly property of a shared row is not a valid operation.", ex.Message);
270                                 } catch (Exception ex) {
271                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.ReadOnly");
272                                 }
273                                 try {
274                                         object zxf = row.Resizable;
275                                         TestHelper.RemoveWarning (zxf);
276                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Resizable");
277                                 } catch (InvalidOperationException ex) {
278                                         Assert.AreEqual (@"Getting the Resizable property of a shared row is not a valid operation.", ex.Message);
279                                 } catch (Exception ex) {
280                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Resizable");
281                                 }
282                                 try {
283                                         object zxf = row.Selected;
284                                         TestHelper.RemoveWarning (zxf);
285                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Selected");
286                                 } catch (InvalidOperationException ex) {
287                                         Assert.AreEqual (@"Getting the Selected property of a shared row is not a valid operation.", ex.Message);
288                                 } catch (Exception ex) {
289                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Selected");
290                                 }
291                                 try {
292                                         object zxf = row.State;
293                                         TestHelper.RemoveWarning (zxf);
294                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.State");
295                                 } catch (InvalidOperationException ex) {
296                                         Assert.AreEqual (@"Getting the State property of a shared row is not a valid operation.", ex.Message);
297                                 } catch (Exception ex) {
298                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.State");
299                                 }
300                                 Assert.IsNull (row.Tag, "#D row.Tag");
301                                 try {
302                                         object zxf = row.Visible;
303                                         TestHelper.RemoveWarning (zxf);
304                                         Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#D row.Visible");
305                                 } catch (InvalidOperationException ex) {
306                                         Assert.AreEqual (@"Getting the Visible property of a shared row is not a valid operation.", ex.Message);
307                                 } catch (Exception ex) {
308                                         Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#D row.Visible");
309                                 }
310                         }
311                 }
312                 
313                 [Test]
314                 public void InitialValues ()
315                 {
316                         DataGridViewRow row = new DataGridViewRow ();
317
318                         Assert.IsNotNull (row.AccessibilityObject, "#A row.AccessibilityObject");
319                         Assert.IsNotNull (row.Cells, "#A row.Cells");
320                         Assert.IsNull (row.ContextMenuStrip, "#A row.ContextMenuStrip");
321                         Assert.IsNull (row.DataBoundItem, "#A row.DataBoundItem");
322                         Assert.IsNull (row.DataGridView, "#A row.DataGridView");
323                         Assert.IsNotNull (row.DefaultCellStyle, "#A row.DefaultCellStyle");
324                         Assert.IsNotNull (row.DefaultHeaderCellType, "#A row.DefaultHeaderCellType");
325                         Assert.AreEqual (false, row.Displayed, "#A row.Displayed");
326                         Assert.AreEqual (0, row.DividerHeight, "#A row.DividerHeight");
327                         Assert.AreEqual (@"", row.ErrorText, "#A row.ErrorText");
328                         Assert.AreEqual (false, row.Frozen, "#A row.Frozen");
329                         Assert.AreEqual (true, row.HasDefaultCellStyle, "#A row.HasDefaultCellStyle");
330                         Assert.IsNotNull (row.HeaderCell, "#A row.HeaderCell");
331                         // DPI Dependent? // Assert.AreEqual (22, row.Height, "#A row.Height");
332                         Assert.AreEqual (-1, row.Index, "#A row.Index");
333                         try {
334                                 object zxf = row.InheritedStyle;
335                                 TestHelper.RemoveWarning (zxf);
336                                 Assert.Fail ("Expected 'System.InvalidOperationException', but no exception was thrown.", "#A row.InheritedStyle");
337                         } catch (InvalidOperationException ex) {
338                                 Assert.AreEqual (@"Getting the InheritedStyle property of a shared row is not a valid operation.", ex.Message);
339                         } catch (Exception ex) {
340                                 Assert.Fail ("Expected 'System.InvalidOperationException', got '" + ex.GetType ().FullName + "'.", "#A row.InheritedStyle");
341                         }
342                         Assert.AreEqual (false, row.IsNewRow, "#A row.IsNewRow");
343                         Assert.AreEqual (3, row.MinimumHeight, "#A row.MinimumHeight");
344                         Assert.AreEqual (false, row.ReadOnly, "#A row.ReadOnly");
345                         Assert.AreEqual (DataGridViewTriState.NotSet, row.Resizable, "#A row.Resizable");
346                         Assert.AreEqual (false, row.Selected, "#A row.Selected");
347                         Assert.AreEqual (DataGridViewElementStates.Visible, row.State, "#A row.State");
348                         Assert.IsNull (row.Tag, "#A row.Tag");
349                         Assert.AreEqual (true, row.Visible, "#A row.Visible");
350                 }
351         }
352 }
353 #endif