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");
46 Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
47 Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
51 public void DefaultConstructor_ToString ()
53 SelectionRange sr = new SelectionRange ();
54 // "9999-12-31 00:00:00", note not 23:59:59.
55 Assert.AreEqual (string.Format ("SelectionRange: Start: {0}, End: {1}", new DateTime (1, 1, 1).ToString (), new DateTime (9999, 12, 31).ToString ()),
56 sr.ToString (), "ToString");
60 public void TwoDatesConstructor ()
62 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17));
63 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
64 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
68 public void TwoDatesConstructor_Backwards () // start > end
70 SelectionRange sr = new SelectionRange (new DateTime (2008, 2, 17), new DateTime (2001, 1, 11));
71 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
72 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
76 public void TwoDatesConstructor_WithTime ()
78 // Apparenly any time value is stripped, found while testing PropertyGrid.
79 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15), new DateTime (2008, 2, 17));
80 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
81 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
85 public void TwoDatesConstructor_WithTime2 ()
87 // Apparenly any time value is stripped, found while testing PropertyGrid.
88 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3));
89 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
90 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
91 Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
92 Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
96 public void TwoDatesConstructor_WithTimeWithKindLocal ()
98 // Apparenly any time value is stripped, found while testing PropertyGrid.
99 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11, 13, 14, 15, DateTimeKind.Local), new DateTime (2008, 2, 17));
100 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
101 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
103 Assert.AreEqual (DateTimeKind.Local, sr.Start.Kind, "Start Kind");
104 Assert.AreEqual (DateTimeKind.Unspecified, sr.End.Kind, "End Kind");
108 public void TwoDatesConstructor_WithTime2WithKindUtc ()
110 // Apparenly any time value is stripped, found while testing PropertyGrid.
111 SelectionRange sr = new SelectionRange (new DateTime (2001, 1, 11), new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Utc));
112 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
113 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
115 Assert.AreEqual (DateTimeKind.Unspecified, sr.Start.Kind, "Start Kind");
116 Assert.AreEqual (DateTimeKind.Utc, sr.End.Kind, "End Kind");
120 public void TwoDatesConstructor_WithTwoTimeWithTwoKinds ()
122 // Apparenly any time value is stripped, found while testing PropertyGrid.
123 SelectionRange sr = new SelectionRange (
124 new DateTime (2001, 1, 11, 1, 2, 3, DateTimeKind.Utc),
125 new DateTime (2008, 2, 17, 1, 2, 3, DateTimeKind.Local));
126 Assert.AreEqual (new DateTime (2001, 1, 11), sr.Start, "Start");
127 Assert.AreEqual (new DateTime (2008, 2, 17), sr.End, "End");
129 Assert.AreEqual (DateTimeKind.Utc, sr.Start.Kind, "Start Kind");
130 Assert.AreEqual (DateTimeKind.Local, sr.End.Kind, "End Kind");