SelectionRangeTest.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // SelectionRangeTest.cs
  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) 2008 Andy Hume
  24. //
  25. // Authors:
  26. // Andy Hume <[email protected]>
  27. using System;
  28. using System.Windows.Forms;
  29. using NUnit.Framework;
  30. namespace MonoTests.System.Windows.Forms
  31. {
  32. [TestFixture]
  33. public class SelectionRangeTest : TestHelper
  34. {
  35. [Test]
  36. public void DefaultConstructor ()
  37. {
  38. SelectionRange sr = new SelectionRange ();
  39. Assert.AreEqual (DateTime.MinValue, sr.Start, "Start");
  40. // "9999-12-31 00:00:00", note not 23:59:59.
  41. Assert.AreEqual (DateTime.MaxValue.Date, sr.End, "End");
  42. #if NET_2_0
  43. Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
  44. Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
  45. #endif
  46. }
  47. [Test]
  48. public void DefaultConstructor_ToString ()
  49. {
  50. SelectionRange sr = new SelectionRange ();
  51. // "9999-12-31 00:00:00", note not 23:59:59.
  52. Assert.AreEqual (string.Format ("SelectionRange: Start: {0}, End: {1}", new DateTime (1, 1, 1).ToString (), new DateTime (9999, 12, 31).ToString ()),
  53. sr.ToString (), "ToString");
  54. }
  55. [Test]
  56. public void TwoDatesConstructor ()
  57. {
  58. SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17));
  59. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  60. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  61. }
  62. [Test]
  63. public void TwoDatesConstructor_Backwards () // start > end
  64. {
  65. SelectionRange sr = new SelectionRange (new DateTime (2008, 2, 17), new DateTime (2001, 1, 11));
  66. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  67. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  68. }
  69. [Test]
  70. public void TwoDatesConstructor_WithTime ()
  71. {
  72. // Apparenly any time value is stripped, found while testing PropertyGrid.
  73. SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15), new DateTime (2008, 2, 17));
  74. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  75. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  76. }
  77. [Test]
  78. public void TwoDatesConstructor_WithTime2 ()
  79. {
  80. // Apparenly any time value is stripped, found while testing PropertyGrid.
  81. SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3));
  82. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  83. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  84. #if NET_2_0
  85. Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
  86. Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
  87. #endif
  88. }
  89. #if NET_2_0
  90. [Test]
  91. public void TwoDatesConstructor_WithTimeWithKindLocal ()
  92. {
  93. // Apparenly any time value is stripped, found while testing PropertyGrid.
  94. SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15, DateTimeKind.Local), new DateTime (2008, 2, 17));
  95. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  96. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  97. //
  98. Assert.AreEqual (DateTimeKind.Local, sr.Start.Kind, "Start Kind");
  99. Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
  100. }
  101. [Test]
  102. public void TwoDatesConstructor_WithTime2WithKindUtc ()
  103. {
  104. // Apparenly any time value is stripped, found while testing PropertyGrid.
  105. SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Utc));
  106. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  107. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  108. //
  109. Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
  110. Assert.AreEqual (DateTimeKind.Utc, sr.End.Kind, "End Kind");
  111. }
  112. [Test]
  113. public void TwoDatesConstructor_WithTwoTimeWithTwoKinds ()
  114. {
  115. // Apparenly any time value is stripped, found while testing PropertyGrid.
  116. SelectionRange sr = new SelectionRange (
  117. new DateTime (2001, 1, 11, 1, 2, 3, DateTimeKind.Utc),
  118. new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Local));
  119. Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
  120. Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
  121. //
  122. Assert.AreEqual (DateTimeKind.Utc, sr.Start.Kind, "Start Kind");
  123. Assert.AreEqual (DateTimeKind.Local, sr.End.Kind, "End Kind");
  124. }
  125. #endif
  126. }
  127. }