2 // SelectionRangeTest.cs
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) 2008 Andy Hume
26 // Andy Hume <andyhume32@yahoo.co.uk>
29 using System.Windows.Forms;
30 using NUnit.Framework;
32 namespace MonoTests.System.Windows.Forms
35 public class SelectionRangeTest : TestHelper
39 public void DefaultConstructor ()
41 SelectionRange sr = new SelectionRange ();
42 Assert.AreEqual (DateTime.MinValue, sr.Start, "Start");
43 // "9999-12-31 00:00:00", note not 23:59:59.
44 Assert.AreEqual (DateTime.MaxValue.Date, sr.End, "End");
47 Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
48 Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
53 public void DefaultConstructor_ToString ()
55 SelectionRange sr = new SelectionRange ();
56 // "9999-12-31 00:00:00", note not 23:59:59.
57 Assert.AreEqual (string.Format ("SelectionRange: Start: {0}, End: {1}", new DateTime (1, 1, 1).ToString (), new DateTime (9999, 12, 31).ToString ()),
58 sr.ToString (), "ToString");
62 public void TwoDatesConstructor ()
64 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17));
65 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
66 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
70 public void TwoDatesConstructor_Backwards () // start > end
72 SelectionRange sr = new SelectionRange (new DateTime (2008, 2, 17), new DateTime (2001, 1, 11));
73 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
74 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
78 public void TwoDatesConstructor_WithTime ()
80 // Apparenly any time value is stripped, found while testing PropertyGrid.
81 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15), new DateTime (2008, 2, 17));
82 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
83 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
87 public void TwoDatesConstructor_WithTime2 ()
89 // Apparenly any time value is stripped, found while testing PropertyGrid.
90 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3));
91 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
92 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
94 Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
95 Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
101 public void TwoDatesConstructor_WithTimeWithKindLocal ()
103 // Apparenly any time value is stripped, found while testing PropertyGrid.
104 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15, DateTimeKind.Local), new DateTime (2008, 2, 17));
105 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
106 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
108 Assert.AreEqual (DateTimeKind.Local, sr.Start.Kind, "Start Kind");
109 Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
113 public void TwoDatesConstructor_WithTime2WithKindUtc ()
115 // Apparenly any time value is stripped, found while testing PropertyGrid.
116 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Utc));
117 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
118 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
120 Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
121 Assert.AreEqual (DateTimeKind.Utc, sr.End.Kind, "End Kind");
125 public void TwoDatesConstructor_WithTwoTimeWithTwoKinds ()
127 // Apparenly any time value is stripped, found while testing PropertyGrid.
128 SelectionRange sr = new SelectionRange (
129 new DateTime (2001, 1, 11, 1, 2, 3, DateTimeKind.Utc),
130 new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Local));
131 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
132 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
134 Assert.AreEqual (DateTimeKind.Utc, sr.Start.Kind, "Start Kind");
135 Assert.AreEqual (DateTimeKind.Local, sr.End.Kind, "End Kind");