2 // ComboBoxTest.cs: Test cases for ComboBox.
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
26 // Ritvik Mayank <mritvik@novell.com>
27 // Jordi Mas i Hernandez <jordi@ximian.com>
31 using System.Collections;
32 using System.ComponentModel;
34 using System.Reflection;
35 using System.Windows.Forms;
37 using NUnit.Framework;
39 namespace MonoTests.System.Windows.Forms
42 public class ListBoxTest : TestHelper
48 protected override void SetUp ()
50 listBox = new ListBox();
52 form.ShowInTaskbar = false;
57 protected override void TearDown ()
64 public void RemoveLast ()
66 listBox.Items.Clear ();
68 for (int i = 0; i < 3; i++)
69 listBox.Items.Add (i.ToString ());
71 // need to create control to actually test the invalidation
72 listBox.CreateControl ();
74 // select last - then remove an item that is *not* the last,
75 // so basically the selection is invalidated implicitly
76 listBox.SelectedIndex = 2;
77 listBox.Items.RemoveAt (1);
78 Assert.AreEqual (1, listBox.SelectedIndex, "#A1");
80 listBox.SelectedIndex = 0;
81 Assert.AreEqual (0, listBox.SelectedIndex, "#B1");
86 listBox.ClearSelected ();
87 listBox.Items.Clear ();
88 for (int i = 0; i < 3; i++)
89 listBox.Items.Add (i.ToString ());
91 listBox.SelectionMode = SelectionMode.MultiSimple;
93 listBox.SetSelected (0, true);
94 listBox.SetSelected (2, true);
96 Assert.AreEqual (true, listBox.GetSelected (0), "#C1");
97 Assert.AreEqual (false, listBox.GetSelected (1), "#C2");
98 Assert.AreEqual (true, listBox.GetSelected (2), "#C3");
100 listBox.Items.RemoveAt (2);
101 Assert.AreEqual (true, listBox.GetSelected (0), "#D1");
102 Assert.AreEqual (false, listBox.GetSelected (1), "#D2");
103 Assert.AreEqual (1, listBox.SelectedIndices.Count, "#D3");
107 public void ListBoxPropertyTest ()
109 Assert.AreEqual (0, listBox.ColumnWidth, "#1");
110 Assert.AreEqual (DrawMode.Normal, listBox.DrawMode, "#2");
111 Assert.AreEqual (0, listBox.HorizontalExtent, "#3");
112 Assert.AreEqual (false, listBox.HorizontalScrollbar, "#4");
113 Assert.AreEqual (true, listBox.IntegralHeight, "#5");
114 //Assert.AreEqual (13, listBox.ItemHeight, "#6"); // Note: Item height depends on the current font.
115 listBox.Items.Add ("a");
116 listBox.Items.Add ("b");
117 listBox.Items.Add ("c");
118 Assert.AreEqual (3, listBox.Items.Count, "#7");
119 Assert.AreEqual (false, listBox.MultiColumn, "#8");
120 //Assert.AreEqual (46, listBox.PreferredHeight, "#9"); // Note: Item height depends on the current font.
121 //Assert.AreEqual (RightToLeft.No , listBox.RightToLeft, "#10"); // Depends on Windows version
122 Assert.AreEqual (false, listBox.ScrollAlwaysVisible, "#11");
123 Assert.AreEqual (-1, listBox.SelectedIndex, "#12");
124 listBox.SetSelected (2,true);
125 Assert.AreEqual (2, listBox.SelectedIndices[0], "#13");
126 Assert.AreEqual ("c", listBox.SelectedItem, "#14");
127 Assert.AreEqual ("c", listBox.SelectedItems[0], "#15");
128 Assert.AreEqual (SelectionMode.One, listBox.SelectionMode, "#16");
129 listBox.SetSelected (2,false);
130 Assert.AreEqual (false, listBox.Sorted, "#17");
131 Assert.AreEqual ("", listBox.Text, "#18");
132 Assert.AreEqual (0, listBox.TopIndex, "#19");
133 Assert.AreEqual (true, listBox.UseTabStops, "#20");
137 public void BeginEndUpdateTest ()
140 listBox.Items.Add ("A");
141 listBox.Visible = true;
142 form.Controls.Add (listBox);
143 listBox.BeginUpdate ();
144 for (int x = 1; x < 5000; x++)
146 listBox.Items.Add ("Item " + x.ToString ());
148 listBox.EndUpdate ();
149 listBox.SetSelected (1, true);
150 listBox.SetSelected (3, true);
151 Assert.AreEqual (true, listBox.SelectedItems.Contains ("Item 3"), "#21");
155 public void ClearSelectedTest ()
158 listBox.Items.Add ("A");
159 listBox.Visible = true;
160 form.Controls.Add (listBox);
161 listBox.SetSelected (0, true);
162 Assert.AreEqual ("A", listBox.SelectedItems [0].ToString (),"#22");
163 listBox.ClearSelected ();
164 Assert.AreEqual (0, listBox.SelectedItems.Count,"#23");
168 [NUnit.Framework.Category ("NotWorking")]
169 public void ClientRectangle_Borders ()
171 // This test is invalid because createcontrol forces .net to resize
172 // the listbox using integralheight, which defaults to true. This
173 // will only hold for most font sizes.
174 listBox.CreateControl ();
175 Assert.AreEqual (listBox.ClientRectangle, new ListBox ().ClientRectangle);
178 [Ignore ("It depends on user system settings")]
179 public void GetItemHeightTest ()
181 listBox.Visible = true;
182 form.Controls.Add (listBox);
183 listBox.Items.Add ("A");
184 Assert.AreEqual (13, listBox.GetItemHeight (0) , "#28");
187 [Ignore ("It depends on user system settings")]
188 public void GetItemRectangleTest ()
191 listBox.Visible = true;
192 form.Controls.Add (listBox);
193 listBox.Items.Add ("A");
194 Assert.AreEqual (new Rectangle(0,0,116,13), listBox.GetItemRectangle (0), "#29");
198 public void GetSelectedTest ()
200 listBox.Items.Add ("A");
201 listBox.Items.Add ("B");
202 listBox.Items.Add ("C");
203 listBox.Items.Add ("D");
204 listBox.SelectionMode = SelectionMode.MultiSimple;
205 listBox.Sorted = true;
206 listBox.SetSelected (0,true);
207 listBox.SetSelected (2,true);
209 Assert.AreEqual (true, listBox.GetSelected (0), "#30");
210 listBox.SetSelected (2,false);
211 Assert.AreEqual (false, listBox.GetSelected (2), "#31");
215 public void IndexFromPointTest ()
217 listBox.Items.Add ("A");
218 Point pt = new Point (100,100);
219 listBox.IndexFromPoint (pt);
220 Assert.AreEqual (-1, listBox.IndexFromPoint (100,100), "#32");
224 public void FindStringTest ()
226 listBox.FindString ("Hola", -5); // No exception, it's empty
227 int x = listBox.FindString ("Hello");
228 Assert.AreEqual (-1, x, "#19");
229 listBox.Items.AddRange(new object[] {"ACBD", "ABDC", "ACBD", "ABCD"});
230 String myString = "ABC";
231 x = listBox.FindString (myString);
232 Assert.AreEqual (3, x, "#191");
233 x = listBox.FindString (string.Empty);
234 Assert.AreEqual (0, x, "#192");
235 x = listBox.FindString ("NonExistant");
236 Assert.AreEqual (-1, x, "#193");
238 x = listBox.FindString ("A", -1);
239 Assert.AreEqual (0, x, "#194");
240 x = listBox.FindString ("A", 0);
241 Assert.AreEqual (1, x, "#195");
242 x = listBox.FindString ("A", listBox.Items.Count - 1);
243 Assert.AreEqual (0, x, "#196");
244 x = listBox.FindString ("a", listBox.Items.Count - 1);
245 Assert.AreEqual (0, x, "#197");
249 public void FindStringExactTest ()
251 listBox.FindStringExact ("Hola", -5); // No exception, it's empty
252 int x = listBox.FindStringExact ("Hello");
253 Assert.AreEqual (-1, x, "#20");
254 listBox.Items.AddRange (new object[] {"ABCD","ABC","ABDC"});
255 String myString = "ABC";
256 x = listBox.FindStringExact (myString);
257 Assert.AreEqual (1, x, "#201");
258 x = listBox.FindStringExact (string.Empty);
259 Assert.AreEqual (-1, x, "#202");
260 x = listBox.FindStringExact ("NonExistant");
261 Assert.AreEqual (-1, x, "#203");
263 x = listBox.FindStringExact ("ABCD", -1);
264 Assert.AreEqual (0, x, "#204");
265 x = listBox.FindStringExact ("ABC", 0);
266 Assert.AreEqual (1, x, "#205");
267 x = listBox.FindStringExact ("ABC", listBox.Items.Count - 1);
268 Assert.AreEqual (1, x, "#206");
269 x = listBox.FindStringExact ("abcd", listBox.Items.Count - 1);
270 Assert.AreEqual (0, x, "#207");
275 public void AllowSelection ()
277 MockListBox lb = new MockListBox ();
278 lb.SelectionMode = SelectionMode.None;
279 Assert.IsFalse (lb.allow_selection, "#1");
280 lb.SelectionMode = SelectionMode.One;
281 Assert.IsTrue (lb.allow_selection, "#2");
290 [ExpectedException (typeof (InvalidEnumArgumentException))]
291 public void BorderStyleException ()
293 listBox.BorderStyle = (BorderStyle) 10;
297 [ExpectedException (typeof (ArgumentException))]
298 public void ColumnWidthException ()
300 listBox.ColumnWidth = -1;
304 [ExpectedException (typeof (InvalidEnumArgumentException))]
305 public void DrawModeException ()
307 listBox.DrawMode = (DrawMode) 10;
311 [ExpectedException (typeof (ArgumentException))]
312 public void DrawModeAndMultiColumnException ()
314 listBox.MultiColumn = true;
315 listBox.DrawMode = DrawMode.OwnerDrawVariable;
319 [ExpectedException (typeof (ArgumentOutOfRangeException))]
320 public void ItemHeightException ()
322 listBox.ItemHeight = 256;
326 public void SelectedIndex_Created ()
328 Form form = new Form ();
329 ListBox listBox = new ListBox ();
330 listBox.Items.Add ("A");
331 listBox.Items.Add ("B");
332 form.Controls.Add (listBox);
335 Assert.AreEqual (-1, listBox.SelectedIndex, "#1");
336 listBox.SelectedIndex = 0;
337 Assert.AreEqual (0, listBox.SelectedIndex, "#2");
338 listBox.SelectedIndex = -1;
339 Assert.AreEqual (-1, listBox.SelectedIndex, "#3");
340 listBox.SelectedIndex = 1;
341 Assert.AreEqual (1, listBox.SelectedIndex, "#4");
347 public void SelectedIndex_NotCreated ()
349 ListBox listBox = new ListBox ();
350 listBox.Items.Add ("A");
351 listBox.Items.Add ("B");
352 Assert.AreEqual (-1, listBox.SelectedIndex, "#1");
353 listBox.SelectedIndex = 0;
354 Assert.AreEqual (0, listBox.SelectedIndex, "#2");
355 listBox.SelectedIndex = -1;
356 Assert.AreEqual (-1, listBox.SelectedIndex, "#3");
357 listBox.SelectedIndex = 1;
358 Assert.AreEqual (1, listBox.SelectedIndex, "#4");
363 public void SelectedIndex_Removed ()
365 ListBox listBox = new ListBox ();
366 listBox.Items.Add ("A");
367 listBox.Items.Add ("B");
368 listBox.Items.Add ("C");
370 Assert.AreEqual (-1, listBox.SelectedIndex, "#1");
371 listBox.SelectedIndex = 2;
372 Assert.AreEqual (2, listBox.SelectedIndex, "#2");
373 listBox.Items.RemoveAt (2);
374 Assert.AreEqual (-1, listBox.SelectedIndex, "#3");
376 listBox.SelectedIndex = 0;
377 Assert.AreEqual (0, listBox.SelectedIndex, "#4");
378 listBox.Items.RemoveAt (0);
379 Assert.AreEqual (-1, listBox.SelectedIndex, "#5");
382 // This should also apply to MultiSimple selection mode
384 public void Selection_MultiExtended ()
386 listBox.Items.Add ("A");
387 listBox.Items.Add ("B");
388 listBox.Items.Add ("C");
389 listBox.Items.Add ("D");
390 listBox.SelectionMode = SelectionMode.MultiExtended;
393 // First part: test the order of SelectedItems as well
394 // as SelectedIndex when more than one item is selected
396 listBox.SelectedItems.Add ("D");
397 listBox.SelectedItems.Add ("B");
398 Assert.AreEqual (1, listBox.SelectedIndex, "#A1");
399 Assert.AreEqual (2, listBox.SelectedItems.Count, "#A2");
400 Assert.AreEqual ("B", listBox.SelectedItems [0], "#A3");
401 Assert.AreEqual ("D", listBox.SelectedItems [1], "#A4");
403 listBox.SelectedItems.Add ("C");
404 Assert.AreEqual (1, listBox.SelectedIndex, "#B1");
405 Assert.AreEqual (3, listBox.SelectedItems.Count, "#B2");
406 Assert.AreEqual ("B", listBox.SelectedItems [0], "#B3");
407 Assert.AreEqual ("C", listBox.SelectedItems [1], "#B4");
408 Assert.AreEqual ("D", listBox.SelectedItems [2], "#B5");
410 listBox.SelectedItems.Add ("A");
411 Assert.AreEqual (0, listBox.SelectedIndex, "#C1");
412 Assert.AreEqual (4, listBox.SelectedItems.Count, "#C2");
413 Assert.AreEqual ("A", listBox.SelectedItems [0], "#C3");
414 Assert.AreEqual ("B", listBox.SelectedItems [1], "#C4");
415 Assert.AreEqual ("C", listBox.SelectedItems [2], "#C5");
416 Assert.AreEqual ("D", listBox.SelectedItems [3], "#C6");
419 // Second part: how does SelectedIndex setter work related
422 listBox.SelectedIndex = -1;
423 Assert.AreEqual (-1, listBox.SelectedIndex, "#D1");
424 Assert.AreEqual (0, listBox.SelectedItems.Count, "#D2");
426 listBox.SelectedIndex = 3; // "D"
427 Assert.AreEqual (3, listBox.SelectedIndex, "#E1");
428 Assert.AreEqual (1, listBox.SelectedItems.Count, "#E2");
429 Assert.AreEqual ("D", listBox.SelectedItems [0], "#E3");
431 listBox.SelectedItems.Add ("B"); // index = 1
432 Assert.AreEqual (1, listBox.SelectedIndex, "#F1");
433 Assert.AreEqual (2, listBox.SelectedItems.Count, "#E3");
434 Assert.AreEqual ("B", listBox.SelectedItems [0], "#E4");
435 Assert.AreEqual ("D", listBox.SelectedItems [1], "#E5");
437 listBox.SelectedIndex = 2;
438 Assert.AreEqual (1, listBox.SelectedIndex, "#G1");
439 Assert.AreEqual (3, listBox.SelectedItems.Count, "#G2");
440 Assert.AreEqual ("B", listBox.SelectedItems [0], "#G3");
441 Assert.AreEqual ("C", listBox.SelectedItems [1], "#G4");
442 Assert.AreEqual ("D", listBox.SelectedItems [2], "#G5");
444 listBox.SelectedIndex = 1; // already selected
445 Assert.AreEqual (1, listBox.SelectedIndex, "#H1");
446 Assert.AreEqual (3, listBox.SelectedItems.Count, "#H2");
448 // NOTE: It seems that passing -1 does not affect the collection
449 // in anyway (other wrong values generate an exception, however)
450 listBox.SelectedIndices.Add (-1);
451 Assert.AreEqual (3, listBox.SelectedItems.Count, "#J1");
455 public void Selection_One ()
457 listBox.Items.Add ("A");
458 listBox.Items.Add ("B");
459 listBox.Items.Add ("C");
460 listBox.SelectionMode = SelectionMode.One;
462 listBox.SelectedItems.Add ("B");
463 Assert.AreEqual (1, listBox.SelectedIndex, "#A1");
464 Assert.AreEqual (1, listBox.SelectedItems.Count, "#A2");
465 Assert.AreEqual ("B", listBox.SelectedItems [0], "#A3");
467 listBox.SelectedIndex = 2;
468 Assert.AreEqual (2, listBox.SelectedIndex, "#B1");
469 Assert.AreEqual (1, listBox.SelectedItems.Count, "#B2");
470 Assert.AreEqual ("C", listBox.SelectedItems [0], "#B3");
472 listBox.SelectedItems.Add ("A");
473 Assert.AreEqual (0, listBox.SelectedIndex, "#C1");
474 Assert.AreEqual (1, listBox.SelectedItems.Count, "#C2");
475 Assert.AreEqual ("A", listBox.SelectedItems [0], "#C3");
479 public void Selection_None ()
481 listBox.Items.Add ("A");
482 listBox.Items.Add ("B");
483 listBox.SelectionMode = SelectionMode.None;
486 listBox.SelectedIndex = 0;
488 } catch (ArgumentException) {
492 listBox.SelectedIndices.Add (0);
494 } catch (InvalidOperationException e) {
495 Console.WriteLine (e.Message);
499 listBox.SelectedItems.Add ("A");
501 } catch (ArgumentException) {
507 [ExpectedException (typeof (ArgumentOutOfRangeException))]
508 public void SelectedIndexException ()
510 listBox.SelectedIndex = -2;
514 [ExpectedException (typeof (ArgumentOutOfRangeException))]
515 public void SelectedIndexException2 ()
517 listBox.SelectedIndex = listBox.Items.Count;
521 [ExpectedException (typeof (ArgumentException))]
522 public void SelectedIndexModeNoneException ()
524 listBox.SelectionMode = SelectionMode.None;
525 listBox.SelectedIndex = -1;
529 [ExpectedException (typeof (InvalidEnumArgumentException))]
530 public void SelectionModeException ()
532 listBox.SelectionMode = (SelectionMode) 10;
536 public void SelectedValueNull()
538 listBox.Items.Clear ();
540 listBox.Items.Add ("A");
541 listBox.Items.Add ("B");
542 listBox.Items.Add ("C");
543 listBox.Items.Add ("D");
545 listBox.SelectedIndex = 2;
546 listBox.SelectedValue = null;
547 Assert.AreEqual (listBox.SelectedIndex, 2);
551 public void SelectedValueEmptyString()
553 listBox.Items.Clear ();
555 listBox.Items.Add ("A");
556 listBox.Items.Add ("B");
557 listBox.Items.Add ("C");
558 listBox.Items.Add ("D");
560 listBox.SelectedIndex = 2;
561 listBox.SelectedValue = null;
562 Assert.AreEqual (listBox.SelectedIndex, 2);
566 public void SetItemsCore ()
568 MockListBox l = new MockListBox ();
569 l.InvokeSetItemsCore (new object [] { "A", "B", "C" });
570 Assert.AreEqual (3, l.Items.Count, "#1");
571 Assert.AreEqual ("A", l.Items [0], "#2");
572 Assert.AreEqual ("B", l.Items [1], "#3");
573 Assert.AreEqual ("C", l.Items [2], "#4");
577 public void SetItemsCore_Item_Null ()
579 MockListBox l = new MockListBox ();
581 l.InvokeSetItemsCore (new object [] { "A", null, "B" });
583 } catch (ArgumentNullException ex) {
584 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
585 Assert.IsNull (ex.InnerException, "#3");
586 Assert.IsNotNull (ex.Message, "#4");
587 Assert.AreEqual ("item", ex.ParamName, "#5");
591 Assert.AreEqual (1, l.Items.Count, "#6");
592 Assert.AreEqual ("A", l.Items [0], "#7");
594 Assert.AreEqual (0, l.Items.Count, "#6");
599 public void SetItemsCore_Value_Null ()
601 MockListBox l = new MockListBox ();
603 l.InvokeSetItemsCore ((IList) null);
605 } catch (ArgumentNullException ex) {
606 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
607 Assert.IsNull (ex.InnerException, "#3");
608 Assert.IsNotNull (ex.Message, "#4");
609 Assert.AreEqual ("items", ex.ParamName, "#5");
614 public void ListBoxHeight ()
616 ListBox l = new ListBox ();
618 for (int h = 0; h < 100; h++) {
622 Assert.Fail ("Set ListBox height of {0}, got back {1}. Should be the same.", h, l.Height);
628 public void GetScaledBoundsTest ()
630 ScaleListBox c = new ScaleListBox ();
632 Rectangle r = new Rectangle (100, 200, 300, 400);
634 Assert.AreEqual (new Rectangle (200, 100, 596, 50), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.All), "A1");
635 Assert.AreEqual (new Rectangle (200, 100, 300, 96), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Location), "A2");
636 Assert.AreEqual (new Rectangle (100, 200, 596, 50), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Size), "A3");
637 Assert.AreEqual (new Rectangle (100, 200, 300, 50), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.Height), "A4");
638 Assert.AreEqual (new Rectangle (200, 200, 300, 96), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.X), "A5");
639 Assert.AreEqual (new Rectangle (100, 200, 300, 96), c.PublicGetScaledBounds (r, new SizeF (2f, .5f), BoundsSpecified.None), "A6");
641 Assert.AreEqual (new Rectangle (100, 200, 300, 96), c.PublicGetScaledBounds (r, new SizeF (1f, 1f), BoundsSpecified.All), "A6-2");
642 Assert.AreEqual (new Rectangle (200, 400, 596, 188), c.PublicGetScaledBounds (r, new SizeF (2f, 2f), BoundsSpecified.All), "A7");
643 Assert.AreEqual (new Rectangle (300, 600, 892, 280), c.PublicGetScaledBounds (r, new SizeF (3f, 3f), BoundsSpecified.All), "A8");
644 Assert.AreEqual (new Rectangle (400, 800, 1188, 372), c.PublicGetScaledBounds (r, new SizeF (4f, 4f), BoundsSpecified.All), "A9");
645 Assert.AreEqual (new Rectangle (50, 100, 152, 50), c.PublicGetScaledBounds (r, new SizeF (.5f, .5f), BoundsSpecified.All), "A10");
649 [NUnit.Framework.Category ("NotWorking")]
650 public void MethodScaleControl ()
652 Form f = new Form ();
653 f.ShowInTaskbar = false;
657 ScaleListBox gb = new ScaleListBox ();
658 gb.Location = new Point (5, 10);
661 Assert.AreEqual (new Rectangle (5, 10, 120, 95), gb.Bounds, "A1");
663 gb.PublicScaleControl (new SizeF (2.0f, 2.0f), BoundsSpecified.All);
664 Assert.AreEqual (new Rectangle (10, 20, 236, 186), gb.Bounds, "A2");
666 gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Location);
667 Assert.AreEqual (new Rectangle (5, 10, 236, 186), gb.Bounds, "A3");
669 gb.PublicScaleControl (new SizeF (.5f, .5f), BoundsSpecified.Size);
670 Assert.AreEqual (new Rectangle (5, 10, 120, 95), gb.Bounds, "A4");
672 gb.PublicScaleControl (new SizeF (3.5f, 3.5f), BoundsSpecified.Size);
673 Assert.AreEqual (new Rectangle (5, 10, 410, 316), gb.Bounds, "A5");
675 gb.PublicScaleControl (new SizeF (2.5f, 2.5f), BoundsSpecified.Size);
676 Assert.AreEqual (new Rectangle (5, 10, 1019, 797), gb.Bounds, "A6");
678 gb.PublicScaleControl (new SizeF (.2f, .2f), BoundsSpecified.Size);
679 Assert.AreEqual (new Rectangle (5, 10, 207, 160), gb.Bounds, "A7");
684 private class ScaleListBox : ListBox
686 public Rectangle PublicGetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
688 return base.GetScaledBounds (bounds, factor, specified);
691 public void PublicScaleControl (SizeF factor, BoundsSpecified specified)
693 base.ScaleControl (factor, specified);
699 public void MethodIsInputChar ()
701 // Basically, show that this method always returns true
702 InputCharControl m = new InputCharControl ();
705 for (int i = 0; i < 256; i++)
706 result &= m.PublicIsInputChar ((char)i);
708 Assert.AreEqual (true, result, "I1");
711 private class InputCharControl : ListBox
713 public bool PublicIsInputChar (char charCode)
715 return base.IsInputChar (charCode);
720 public void HeightAndIntegralHeight ()
722 ListBox a = new ListBox();
723 Size defaultSize = new Size(120, 96);
724 Assert.AreEqual (defaultSize, a.Size, "A1");
726 Assert.AreEqual (0, (a.ClientSize.Height % a.ItemHeight), "A2");
727 a.IntegralHeight = false;
728 Assert.AreEqual (a.Size, defaultSize, "A3");
729 a.IntegralHeight = true;
730 Assert.AreEqual (0, (a.ClientSize.Height % a.ItemHeight), "A4");
732 Size clientSizeI = new Size(200, a.ItemHeight * 5);
733 Size clientSize = clientSizeI + new Size(0, a.ItemHeight / 2);
734 Size borderSize = new Size(a.Width - a.ClientSize.Width, a.Height - a.ClientSize.Height);
735 Size totalSizeI = clientSizeI + borderSize;
736 Size totalSize = clientSize + borderSize;
739 a.ClientSize = clientSize;
740 Assert.AreEqual (clientSize, a.ClientSize, "A5");
741 Assert.AreEqual (totalSize, a.Size, "A6");
742 a.IntegralHeight = false;
743 a.IntegralHeight = true;
744 Assert.AreEqual (clientSize, a.ClientSize, "A7");
746 Assert.AreEqual (clientSizeI, a.ClientSize, "A8");
747 Assert.AreEqual (totalSizeI, a.Size, "A9");
748 a.IntegralHeight = false;
749 Assert.AreEqual (clientSize, a.ClientSize, "A10");
750 a.IntegralHeight = true;
751 Assert.AreEqual (totalSizeI, a.Size, "A11");
756 Assert.AreEqual (totalSizeI, a.Size, "A12");
757 Assert.AreEqual (clientSizeI, a.ClientSize, "A13");
758 a.IntegralHeight = false;
759 Assert.AreEqual (totalSize, a.Size, "A14");
760 Assert.AreEqual (clientSize, a.ClientSize, "A15");
763 a.IntegralHeight = false;
764 Assert.AreEqual (defaultSize, a.Size, "A16");
766 Assert.AreEqual (defaultSize, a.Size, "A17");
769 a.ClientSize = clientSize;
770 a.IntegralHeight = false;
771 Assert.AreEqual (clientSize, a.ClientSize, "A18");
773 Assert.AreEqual (clientSize, a.ClientSize, "A19");
777 public void PropertyTopIndex ()
779 Form f = new Form ();
780 f.ShowInTaskbar = false;
783 ListBox l = new ListBox ();
787 l.Items.AddRange (new string[] { "A", "B", "C"});
789 Assert.AreEqual (0, l.TopIndex, "A1");
792 Assert.AreEqual (0, l.TopIndex, "A2");
794 l.Items.AddRange (new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M" });
795 Assert.AreEqual (0, l.TopIndex, "A3");
798 Assert.AreEqual (2, l.TopIndex, "A4");
800 // There aren't items enough for 12 to be the top index, but
801 // the actual value is font height dependent.
803 Assert.IsTrue (l.TopIndex < 12, "A5");
812 //private bool eventFired;
814 //private void GenericHandler (object sender, EventArgs e)
816 // eventFired = true;
819 public class MockListBox : ListBox
822 public bool allow_selection {
823 get { return base.AllowSelection; }
827 public void InvokeSetItemsCore (IList value)
829 base.SetItemsCore (value);
834 public void AddToSorted ()
836 AddItems (true, CheckedListBoxTest.Items, CheckedListBoxTest.ExpectedAddPositionsSorted);
840 public void AddToUnsorted ()
842 AddItems (false, CheckedListBoxTest.Items, CheckedListBoxTest.ExpectedAddPositionsUnsorted);
845 void AddItems (bool sorted, object[] items, int[] expectedAddPositions)
847 ListBox clb = new ListBox ();
849 ArrayList addedAtList = new ArrayList ();
850 foreach (object cur in items)
852 int idx = clb.Items.Add (cur);
853 addedAtList.Add (idx);
855 Assert.AreEqual ((Array)expectedAddPositions, (Array)addedAtList.ToArray (typeof (int)), "addedAtList");
859 public void SelectedIndexUpdated () // Xamarin bug 4921
861 using (Form f = new Form ()) {
862 f.ShowInTaskbar = false;
864 ListBox l = new ListBox ();
871 Assert.AreEqual (0, l.SelectedIndex);
874 Assert.AreEqual (1, l.SelectedIndex);
879 public void SelectedIndexUpdated_MultiSelect () // Xamarin bug 4921
881 using (Form f = new Form ()) {
882 f.ShowInTaskbar = false;
884 ListBox l = new ListBox ();
886 l.SelectionMode = SelectionMode.MultiSimple;
894 Assert.AreEqual (2, l.SelectedIndices.Count);
895 Assert.AreEqual (0, l.SelectedIndices [0]);
896 Assert.AreEqual (1, l.SelectedIndices [1]);
897 Assert.AreEqual (2, l.SelectedItems.Count);
898 Assert.AreEqual ("B", l.SelectedItems [0]);
899 Assert.AreEqual ("C", l.SelectedItems [1]);
902 Assert.AreEqual (2, l.SelectedIndices.Count);
903 Assert.AreEqual (1, l.SelectedIndices[0]);
904 Assert.AreEqual (2, l.SelectedIndices[1]);
905 Assert.AreEqual (2, l.SelectedItems.Count);
906 Assert.AreEqual ("B", l.SelectedItems [0]);
907 Assert.AreEqual ("C", l.SelectedItems [1]);
913 public class ListBoxObjectCollectionTest : TestHelper
915 ListBox.ObjectCollection col;
918 protected override void SetUp ()
920 col = new ListBox.ObjectCollection (new ListBox ());
924 public void DefaultProperties ()
926 Assert.AreEqual (false, col.IsReadOnly, "#B1");
927 Assert.AreEqual (false, ((ICollection)col).IsSynchronized, "#B2");
928 Assert.AreEqual (col, ((ICollection)col).SyncRoot, "#B3");
929 Assert.AreEqual (false, ((IList)col).IsFixedSize, "#B4");
930 Assert.AreEqual (0, col.Count);
938 Assert.AreEqual (2, col.Count, "#1");
939 Assert.AreEqual ("Item1", col [0], "#2");
940 Assert.AreEqual ("Item2", col [1], "#3");
944 public void Add_Item_Null ()
949 } catch (ArgumentNullException ex) {
950 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
951 Assert.IsNull (ex.InnerException, "#3");
952 Assert.IsNotNull (ex.Message, "#4");
953 Assert.AreEqual ("item", ex.ParamName, "#5");
957 [Test] // AddRange (Object [])
958 public void AddRange1_Items_Null ()
961 col.AddRange ((object []) null);
963 } catch (ArgumentNullException ex) {
964 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
965 Assert.IsNull (ex.InnerException, "#3");
966 Assert.IsNotNull (ex.Message, "#4");
967 Assert.AreEqual ("items", ex.ParamName, "#5");
971 [Test] // AddRange (ListBox.ObjectCollection)
972 public void AddRange2_Value_Null ()
975 col.AddRange ((ListBox.ObjectCollection) null);
977 } catch (ArgumentNullException ex) {
978 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
979 Assert.IsNull (ex.InnerException, "#3");
980 Assert.IsNotNull (ex.Message, "#4");
981 Assert.AreEqual ("items", ex.ParamName, "#5");
991 Assert.AreEqual (0, col.Count, "#D1");
995 public void Contains ()
997 object obj = "Item1";
999 Assert.IsTrue (col.Contains ("Item1"), "#1");
1000 Assert.IsFalse (col.Contains ("Item2"), "#2");
1004 public void Contains_Value_Null ()
1007 col.Contains (null);
1009 } catch (ArgumentNullException ex) {
1010 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1011 Assert.IsNull (ex.InnerException, "#3");
1012 Assert.IsNotNull (ex.Message, "#4");
1014 Assert.AreEqual ("value", ex.ParamName, "#5");
1016 Assert.IsNotNull (ex.ParamName, "#5");
1022 public void Indexer_Value_Null ()
1028 } catch (ArgumentNullException ex) {
1029 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1030 Assert.IsNull (ex.InnerException, "#3");
1031 Assert.IsNotNull (ex.Message, "#4");
1032 Assert.AreEqual ("value", ex.ParamName, "#5");
1037 public void IndexOf ()
1041 Assert.AreEqual (1, col.IndexOf ("Item2"), "#1");
1042 Assert.AreEqual (0, col.IndexOf ("Item1"), "#2");
1043 Assert.AreEqual (-1, col.IndexOf ("Item3"), "#3");
1047 public void IndexOf_Value_Null ()
1052 } catch (ArgumentNullException ex) {
1053 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1054 Assert.IsNull (ex.InnerException, "#3");
1055 Assert.IsNotNull (ex.Message, "#4");
1057 Assert.AreEqual ("value", ex.ParamName, "#5");
1059 Assert.IsNotNull (ex.ParamName, "#5");
1066 [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363285
1068 public void Insert_Item_Null ()
1072 col.Insert (0, null);
1074 } catch (ArgumentNullException ex) {
1075 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1076 Assert.IsNull (ex.InnerException, "#3");
1077 Assert.IsNotNull (ex.Message, "#4");
1078 Assert.AreEqual ("item", ex.ParamName, "#5");
1083 public void Remove ()
1087 col.Remove ("Item1");
1088 Assert.AreEqual (1, col.Count, "#A1");
1089 Assert.AreEqual (-1, col.IndexOf ("Item1"), "#A2");
1090 Assert.AreEqual (0, col.IndexOf ("Item2"), "#A3");
1092 Assert.AreEqual (1, col.Count, "#B1");
1093 Assert.AreEqual (-1, col.IndexOf ("Item1"), "#B2");
1094 Assert.AreEqual (0, col.IndexOf ("Item2"), "#B3");
1095 col.Remove ("Item3");
1096 Assert.AreEqual (1, col.Count, "#C1");
1097 Assert.AreEqual (-1, col.IndexOf ("Item1"), "#C2");
1098 Assert.AreEqual (0, col.IndexOf ("Item2"), "#C3");
1099 col.Remove ("Item2");
1100 Assert.AreEqual (0, col.Count, "#D1");
1101 Assert.AreEqual (-1, col.IndexOf ("Item1"), "#D2");
1102 Assert.AreEqual (-1, col.IndexOf ("Item2"), "#D3");
1106 public void RemoveAt ()
1111 Assert.AreEqual (1, col.Count, "#1");
1112 Assert.AreEqual (-1, col.IndexOf ("Item1"), "#2");
1113 Assert.AreEqual (0, col.IndexOf ("Item2"), "#3");
1119 public class ListBoxIntegerCollectionTest : TestHelper
1121 ListBox.IntegerCollection col;
1125 protected override void SetUp ()
1127 listBox = new ListBox ();
1128 col = new ListBox.IntegerCollection (listBox);
1135 Assert.AreEqual (1, col.Count, "#1");
1137 Assert.AreEqual (2, col.Count, "#2");
1139 Assert.AreEqual (2, col.Count, "#3");
1141 Assert.AreEqual (3, col.Count, "#4");
1144 [Test] // AddRange (Int32 [])
1145 public void AddRange1 ()
1149 col.AddRange (new int [] { 3, 7, 9, 5, 4 });
1150 Assert.AreEqual (5, col.Count, "#1");
1151 Assert.AreEqual (3, col [0], "#2");
1152 Assert.AreEqual (4, col [1], "#3");
1153 Assert.AreEqual (5, col [2], "#4");
1154 Assert.AreEqual (7, col [3], "#5");
1155 Assert.AreEqual (9, col [4], "#6");
1158 [Test] // AddRange (Int32 [])
1159 public void AddRange1_Items_Null ()
1162 col.AddRange ((int []) null);
1164 } catch (ArgumentNullException ex) {
1165 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1166 Assert.IsNull (ex.InnerException, "#3");
1167 Assert.IsNotNull (ex.Message, "#4");
1168 Assert.AreEqual ("items", ex.ParamName, "#5");
1172 [Test] // AddRange (ListBox.IntegerCollection)
1173 public void AddRange2 ()
1175 ListBox.IntegerCollection ints = new ListBox.IntegerCollection (
1186 col.AddRange (ints);
1188 Assert.AreEqual (7, col.Count, "#1");
1189 Assert.AreEqual (-5, col [0], "#2");
1190 Assert.AreEqual (1, col [1], "#3");
1191 Assert.AreEqual (2, col [2], "#4");
1192 Assert.AreEqual (3, col [3], "#5");
1193 Assert.AreEqual (4, col [4], "#6");
1194 Assert.AreEqual (5, col [5], "#7");
1197 [Test] // AddRange (ListBox.IntegerCollection)
1198 public void AddRange2_Items_Null ()
1201 col.AddRange ((ListBox.IntegerCollection) null);
1203 } catch (ArgumentNullException ex) {
1204 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1205 Assert.IsNull (ex.InnerException, "#3");
1206 Assert.IsNotNull (ex.Message, "#4");
1207 Assert.AreEqual ("items", ex.ParamName, "#5");
1212 [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363278
1213 public void Clear ()
1219 Assert.AreEqual (0, col.Count, "#1");
1220 Assert.AreEqual (-1, col.IndexOf (5), "#2");
1221 Assert.AreEqual (-1, col.IndexOf (3), "#3");
1225 public void Contains ()
1229 Assert.IsTrue (col.Contains (5), "#1");
1230 Assert.IsFalse (col.Contains (3), "#2");
1231 Assert.IsTrue (col.Contains (7), "#3");
1232 Assert.IsFalse (col.Contains (-5), "#4");
1236 public void CopyTo ()
1238 int [] copy = new int [5] { 9, 4, 6, 2, 8 };
1243 col.CopyTo (copy, 1);
1245 Assert.AreEqual (9, copy [0], "#1");
1246 Assert.AreEqual (3, copy [1], "#2");
1247 Assert.AreEqual (5, copy [2], "#3");
1248 Assert.AreEqual (7, copy [3], "#4");
1249 Assert.AreEqual (8, copy [4], "#5");
1253 public void CopyTo_Destination_Invalid ()
1255 string [] copy = new string [3] { "A", "B", "C" };
1257 col.CopyTo (copy, 1);
1261 col.CopyTo (copy, 1);
1263 } catch (InvalidCastException) {
1268 public void CopyTo_Destination_Null ()
1270 col.CopyTo ((Array) null, 1);
1274 col.CopyTo ((Array) null, 1);
1276 } catch (NullReferenceException) {
1281 public void CopyTo_Index_Negative ()
1283 int [] copy = new int [5] { 9, 4, 6, 2, 8 };
1285 col.CopyTo (copy, -5);
1289 col.CopyTo (copy, -5);
1291 } catch (IndexOutOfRangeException ex) {
1292 // Index was outside the bounds of the array
1293 Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#2");
1294 Assert.IsNull (ex.InnerException, "#3");
1295 Assert.IsNotNull (ex.Message, "#4");
1300 public void Count ()
1302 Assert.AreEqual (0, col.Count, "#1");
1304 Assert.AreEqual (1, col.Count, "#2");
1306 Assert.AreEqual (2, col.Count, "#3");
1308 Assert.AreEqual (1, col.Count, "#4");
1312 public void Indexer ()
1316 Assert.AreEqual (7, col [1], "#1");
1317 Assert.AreEqual (5, col [0], "#2");
1319 Assert.AreEqual (7, col [1], "#3");
1320 Assert.AreEqual (3, col [0], "#4");
1324 public void IndexOf ()
1328 Assert.AreEqual (0, col.IndexOf (5), "#1");
1329 Assert.AreEqual (-1, col.IndexOf (3), "#2");
1330 Assert.AreEqual (1, col.IndexOf (7), "#3");
1331 Assert.AreEqual (-1, col.IndexOf (-5), "#4");
1335 public void Remove ()
1342 Assert.AreEqual (1, col.Count, "#1");
1343 Assert.AreEqual (3, col [0], "#2");
1345 Assert.AreEqual (0, col.Count, "#3");
1347 // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363280
1348 //Assert.AreEqual (0, col.Count, "#4");
1352 public void RemoveAt ()
1358 Assert.AreEqual (2, col.Count, "#A1");
1359 Assert.AreEqual (3, col [0], "#A2");
1360 Assert.AreEqual (7, col [1], "#A3");
1362 Assert.AreEqual (1, col.Count, "#B1");
1363 Assert.AreEqual (7, col [0], "#B2");
1365 Assert.AreEqual (0, col.Count, "#C1");
1366 Assert.AreEqual (-1, col.IndexOf (5), "#C2");
1367 Assert.AreEqual (-1, col.IndexOf (3), "#C3");
1368 // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363280
1369 //Assert.AreEqual (-1, col.IndexOf (7), "#C4");
1373 [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
1374 public void RemoveAt_Index_Negative ()
1381 } catch (IndexOutOfRangeException ex) {
1382 // Index was outside the bounds of the array
1383 Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#2");
1384 Assert.IsNull (ex.InnerException, "#3");
1385 Assert.IsNotNull (ex.Message, "#4");
1388 Assert.AreEqual (1, col.Count, "#5");
1392 [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
1393 public void RemoveAt_Index_Overflow ()
1400 } catch (ArgumentOutOfRangeException ex) {
1401 // Index was outside the bounds of the array
1402 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1403 Assert.IsNull (ex.InnerException, "#3");
1404 Assert.IsNotNull (ex.Message, "#4");
1405 Assert.AreEqual ("index", ex.ParamName, "#5");
1408 Assert.AreEqual (1, col.Count, "#6");
1412 public void ICollection_IsSynchronized ()
1414 ICollection collection = (ICollection) col;
1415 Assert.IsTrue (collection.IsSynchronized);
1419 public void ICollection_SyncRoot ()
1421 ICollection collection = (ICollection) col;
1422 Assert.AreSame (collection, collection.SyncRoot);
1426 public void IList_Add ()
1428 IList list = (IList) col;
1430 Assert.AreEqual (1, list.Count, "#1");
1432 Assert.AreEqual (2, list.Count, "#2");
1434 Assert.AreEqual (2, list.Count, "#3");
1436 Assert.AreEqual (3, list.Count, "#4");
1440 public void IList_Add_Item_Invalid ()
1442 IList list = (IList) col;
1446 Assert.Fail ("#A1");
1447 } catch (ArgumentException ex) {
1448 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1449 Assert.IsNull (ex.InnerException, "#A3");
1450 Assert.AreEqual ("item", ex.Message, "#A4");
1451 Assert.IsNull (ex.ParamName, "#A5");
1456 Assert.Fail ("#B1");
1457 } catch (ArgumentException ex) {
1458 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1459 Assert.IsNull (ex.InnerException, "#B3");
1460 Assert.AreEqual ("item", ex.Message, "#B4");
1461 Assert.IsNull (ex.ParamName, "#B5");
1466 public void IList_Clear ()
1468 IList list = (IList) col;
1472 Assert.AreEqual (0, list.Count);
1476 public void IList_Contains ()
1478 IList list = (IList) col;
1481 Assert.IsTrue (list.Contains (5), "#1");
1482 Assert.IsFalse (list.Contains (3), "#2");
1483 Assert.IsTrue (list.Contains (7), "#3");
1484 Assert.IsFalse (list.Contains (null), "#4");
1485 Assert.IsFalse (list.Contains ("x"), "#5");
1489 public void IList_Indexer ()
1491 IList list = (IList) col;
1494 Assert.AreEqual (7, list [1], "#1");
1495 Assert.AreEqual (5, list [0], "#2");
1497 Assert.AreEqual (7, list [1], "#3");
1498 Assert.AreEqual (3, list [0], "#4");
1502 public void IList_IndexOf ()
1504 IList list = (IList) col;
1507 Assert.AreEqual (0, list.IndexOf (5), "#1");
1508 Assert.AreEqual (-1, list.IndexOf (3), "#2");
1509 Assert.AreEqual (1, list.IndexOf (7), "#3");
1510 Assert.AreEqual (-1, list.IndexOf (null), "#4");
1511 Assert.AreEqual (-1, list.IndexOf ("x"), "#5");
1515 public void IList_Insert ()
1517 IList list = (IList) col;
1522 Assert.Fail ("#A1");
1523 } catch (NotSupportedException ex) {
1524 // ListBox.IntegerCollection is sorted, and
1525 // items cannot be inserted into it
1526 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
1527 Assert.IsNull (ex.InnerException, "#A3");
1528 Assert.IsNotNull (ex.Message, "#A4");
1532 list.Insert (-5, null);
1533 Assert.Fail ("#B1");
1534 } catch (NotSupportedException ex) {
1535 // ListBox.IntegerCollection is sorted, and
1536 // items cannot be inserted into it
1537 Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
1538 Assert.IsNull (ex.InnerException, "#B3");
1539 Assert.IsNotNull (ex.Message, "#B4");
1544 public void IList_IsFixedSize ()
1546 IList list = (IList) col;
1547 Assert.IsFalse (list.IsFixedSize);
1551 public void IList_IsReadOnly ()
1553 IList list = (IList) col;
1554 Assert.IsFalse (list.IsReadOnly);
1558 public void IList_Remove ()
1560 IList list = (IList) col;
1565 list.Remove (int.MinValue);
1566 list.Remove (int.MaxValue);
1568 Assert.AreEqual (1, list.Count, "#1");
1569 Assert.AreEqual (3, list [0], "#2");
1571 Assert.AreEqual (0, list.Count, "#3");
1575 public void IList_Remove_Value_Invalid ()
1577 IList list = (IList) col;
1582 Assert.Fail ("#A1");
1583 } catch (ArgumentException ex) {
1584 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
1585 Assert.IsNull (ex.InnerException, "#A3");
1586 Assert.AreEqual ("value", ex.Message, "#A4");
1587 Assert.IsNull (ex.ParamName, "#A5");
1592 Assert.Fail ("#B1");
1593 } catch (ArgumentException ex) {
1594 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
1595 Assert.IsNull (ex.InnerException, "#B3");
1596 Assert.AreEqual ("value", ex.Message, "#B4");
1597 Assert.IsNull (ex.ParamName, "#B5");
1602 public void IList_RemoveAt ()
1604 IList list = (IList) col;
1609 Assert.AreEqual (2, list.Count, "#A1");
1610 Assert.AreEqual (3, list [0], "#A2");
1611 Assert.AreEqual (7, list [1], "#A3");
1613 Assert.AreEqual (1, list.Count, "#B1");
1614 Assert.AreEqual (7, list [0], "#B2");
1616 Assert.AreEqual (0, list.Count, "#C");
1620 public void IList_RemoveAt_Index_Negative ()
1622 IList list = (IList) col;
1628 } catch (IndexOutOfRangeException ex) {
1629 // Index was outside the bounds of the array
1630 Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#2");
1631 Assert.IsNull (ex.InnerException, "#3");
1632 Assert.IsNotNull (ex.Message, "#4");
1635 // // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
1636 //Assert.AreEqual (1, list.Count, "#5");
1640 [NUnit.Framework.Category ("NotDotNet")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=363276
1641 public void IList_RemoveAt_Index_Overflow ()
1643 IList list = (IList) col;
1649 } catch (ArgumentOutOfRangeException ex) {
1650 // Index was outside the bounds of the array
1651 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1652 Assert.IsNull (ex.InnerException, "#3");
1653 Assert.IsNotNull (ex.Message, "#4");
1654 Assert.AreEqual ("index", ex.ParamName, "#5");
1657 Assert.AreEqual (1, list.Count, "#6");