NumericUpDownTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Globalization;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using System.Collections;
  8. using Threading = System.Threading;
  9. using NUnit.Framework;
  10. using CategoryAttribute = NUnit.Framework.CategoryAttribute;
  11. namespace MonoTests.System.Windows.Forms
  12. {
  13. [TestFixture]
  14. public class NumericUpDownTest : TestHelper
  15. {
  16. [Test]
  17. public void DefaultValues ()
  18. {
  19. NumericUpDown n = new NumericUpDown ();
  20. #if NET_2_0
  21. Assert.IsFalse (n.Accelerations.IsReadOnly, "#A1");
  22. #endif
  23. }
  24. #if NET_2_0
  25. [Test]
  26. public void SortedAccelerationsTest ()
  27. {
  28. NumericUpDown numericUpDown1 = new NumericUpDown ();
  29. numericUpDown1.Maximum = 40000;
  30. numericUpDown1.Minimum = -40000;
  31. numericUpDown1.Accelerations.Add (new NumericUpDownAcceleration (9, 100));
  32. numericUpDown1.Accelerations.Add (new NumericUpDownAcceleration (2, 1000));
  33. numericUpDown1.Accelerations.Add (new NumericUpDownAcceleration (10, 2000));
  34. numericUpDown1.Accelerations.Add (new NumericUpDownAcceleration (8, 5000));
  35. Assert.AreEqual (2, numericUpDown1.Accelerations[0].Seconds, "#A1");
  36. Assert.AreEqual (8, numericUpDown1.Accelerations[1].Seconds, "#A2");
  37. Assert.AreEqual (9, numericUpDown1.Accelerations[2].Seconds, "#A3");
  38. Assert.AreEqual (10, numericUpDown1.Accelerations[3].Seconds, "#A4");
  39. }
  40. #endif
  41. [Test]
  42. public void Minimum ()
  43. {
  44. Form f = new Form ();
  45. NumericUpDown nud = new NumericUpDown ();
  46. nud.Value = 0;
  47. nud.Minimum = 2;
  48. nud.Maximum = 4;
  49. f.Controls.Add (nud);
  50. f.Show ();
  51. Assert.AreEqual (2, nud.Value, "#A1");
  52. nud.Minimum = 3;
  53. Assert.AreEqual (3, nud.Value, "#A2");
  54. f.Dispose ();
  55. }
  56. [Test]
  57. public void Maximum ()
  58. {
  59. Form f = new Form ();
  60. NumericUpDown nud = new NumericUpDown ();
  61. nud.BeginInit ();
  62. nud.Value = 1000;
  63. nud.Minimum = 2;
  64. nud.Maximum = 4;
  65. nud.EndInit ();
  66. f.Controls.Add (nud);
  67. f.Show ();
  68. Assert.AreEqual (4, nud.Value, "#A1");
  69. nud.Maximum = 3;
  70. Assert.AreEqual (3, nud.Value, "#A2");
  71. f.Dispose ();
  72. }
  73. [Test]
  74. public void Hexadecimal ()
  75. {
  76. Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
  77. Form f = new Form ();
  78. NumericUpDown nud = new NumericUpDown ();
  79. nud.Maximum = 100000;
  80. f.Controls.Add (nud);
  81. f.Show ();
  82. nud.Value = 56789;
  83. nud.Hexadecimal = true;
  84. Assert.AreEqual ("DDD5", nud.Text, "#A1");
  85. Assert.AreEqual (56789, nud.Value, "#A2");
  86. f.Dispose ();
  87. }
  88. [Test]
  89. public void ThousandsSeparator ()
  90. {
  91. Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
  92. Form f = new Form ();
  93. NumericUpDown nud = new NumericUpDown ();
  94. nud.Maximum = 100000;
  95. f.Controls.Add (nud);
  96. f.Show ();
  97. nud.Value = 12345;
  98. nud.ThousandsSeparator = true;
  99. Assert.AreEqual ("12,345", nud.Text, "#A1");
  100. Assert.AreEqual (12345, nud.Value, "#A2");
  101. f.Dispose ();
  102. }
  103. [Test]
  104. #if NET_2_0
  105. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  106. #else
  107. [ExpectedException (typeof (ArgumentException))]
  108. #endif
  109. public void SetValueThrowsException ()
  110. {
  111. NumericUpDown nud = new NumericUpDown ();
  112. nud.Maximum = 3;
  113. nud.Value = 4;
  114. nud.Dispose ();
  115. }
  116. [Test]
  117. #if NET_2_0
  118. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  119. #else
  120. [ExpectedException (typeof (ArgumentException))]
  121. #endif
  122. public void InitTest ()
  123. {
  124. NumericUpDown nud = new NumericUpDown ();
  125. nud.BeginInit ();
  126. nud.Maximum = 3;
  127. nud.BeginInit ();
  128. nud.EndInit ();
  129. nud.Value = 4;
  130. nud.Dispose ();
  131. }
  132. }
  133. }