ComboBoxTests.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // ComboBoxTests.cs: Test cases for ComboBox.
  3. //
  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:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  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.
  22. //
  23. // Copyright (c) 2006 Matt Hargett
  24. //
  25. // Authors:
  26. // Matt Hargett <[email protected]>
  27. //
  28. using System.Windows.Forms;
  29. using System;
  30. using NUnit.Framework;
  31. [TestFixture]
  32. public class ComboBoxTests
  33. {
  34. ComboBox comboBox;
  35. bool textChanged, layoutUpdated;
  36. [SetUp]
  37. public void SetUp()
  38. {
  39. comboBox = new ComboBox();
  40. textChanged = false;
  41. layoutUpdated = false;
  42. comboBox.TextChanged += new EventHandler(textChangedEventHandler);
  43. comboBox.Layout += new LayoutEventHandler(layoutEventHandler);
  44. }
  45. private void textChangedEventHandler(object sender, EventArgs e)
  46. {
  47. textChanged = true;
  48. }
  49. private void layoutEventHandler(object sender, LayoutEventArgs e)
  50. {
  51. layoutUpdated = true;
  52. }
  53. [Test]
  54. public void InitialPropertyValues()
  55. {
  56. Assert.AreEqual(String.Empty, comboBox.Text);
  57. Assert.AreEqual(-1, comboBox.SelectedIndex);
  58. Assert.IsNull(comboBox.SelectedItem);
  59. Assert.AreEqual(121, comboBox.Size.Width);
  60. //Note: it is environment dependent
  61. //Assert.AreEqual(20, comboBox.Size.Height);
  62. Assert.IsFalse(textChanged);
  63. Assert.IsFalse(layoutUpdated);
  64. }
  65. [Test]
  66. public void SetNegativeOneSelectedIndex()
  67. {
  68. comboBox.SelectedIndex = -1;
  69. Assert.AreEqual(String.Empty, comboBox.Text);
  70. Assert.IsFalse(textChanged);
  71. }
  72. [Test]
  73. public void SetDifferentText()
  74. {
  75. comboBox.Text = "foooooooooooooooooooooooooo";
  76. Assert.IsTrue(textChanged);
  77. Assert.IsFalse(layoutUpdated);
  78. }
  79. [Test]
  80. public void SetSameText()
  81. {
  82. comboBox.Text = String.Empty;
  83. Assert.IsFalse(textChanged);
  84. Assert.IsFalse(layoutUpdated);
  85. }
  86. }