1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
#if NET_2_0
namespace MonoTests.System
{
public class TimeZoneInfo_AdjustmentRuleTest
{
[TestFixture]
public class CreateAdjustmentRuleException
{
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DateTimeKindNotUnspecified ()
{
DateTime dateStart = new DateTime (2007,01,01, 0,0,0,DateTimeKind.Utc);
DateTime dateEnd = new DateTime (2008,01,01);
TimeZoneInfo.TransitionTime daylightTransitionStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.TransitionTime daylightTransitionEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 10, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, new TimeSpan (1,0,0), daylightTransitionStart, daylightTransitionEnd);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TransitionEndEqualStart ()
{
DateTime dateStart = new DateTime (2007,01,01);
DateTime dateEnd = new DateTime (2008,01,01);
TimeZoneInfo.TransitionTime daylightTransition = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, new TimeSpan (1,0,0), daylightTransition, daylightTransition);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void DateIncludesTimeOfDay ()
{
DateTime dateStart = new DateTime (2007,01,01, 0,1,0);
DateTime dateEnd = new DateTime (2008,01,01);
TimeZoneInfo.TransitionTime daylightTransitionStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.TransitionTime daylightTransitionEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 10, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, new TimeSpan (1,0,0), daylightTransitionStart, daylightTransitionEnd);
}
[Test]
public void DatesMaxMinValid ()
{
try {
TimeZoneInfo.TransitionTime daylightTransitionStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.TransitionTime daylightTransitionEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 10, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), daylightTransitionStart, daylightTransitionEnd);
} catch {
Assert.Fail ("DateTime.MinValue and MaxValue are not valid...");
}
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void EndBeforeStart ()
{
if (Environment.OSVersion.Platform != PlatformID.Unix)
throw new ArgumentOutOfRangeException ();;
DateTime dateStart = new DateTime (2007,01,01);
DateTime dateEnd = new DateTime (2006,01,01);
TimeZoneInfo.TransitionTime daylightTransitionStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.TransitionTime daylightTransitionEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 10, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, new TimeSpan (1,0,0), daylightTransitionStart, daylightTransitionEnd);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void DeltaOutOfRange ()
{
DateTime dateStart = new DateTime (2007,01,01);
DateTime dateEnd = new DateTime (2008,01,01);
TimeZoneInfo.TransitionTime daylightTransitionStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.TransitionTime daylightTransitionEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 10, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, new TimeSpan (14,1,0), daylightTransitionStart, daylightTransitionEnd);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void DeltaNotInSeconds ()
{
if (Environment.OSVersion.Platform != PlatformID.Unix)
throw new ArgumentOutOfRangeException ();;
DateTime dateStart = new DateTime (2007,01,01);
DateTime dateEnd = new DateTime (2008,01,01);
TimeZoneInfo.TransitionTime daylightTransitionStart = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 03, 11);
TimeZoneInfo.TransitionTime daylightTransitionEnd = TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1,1,1,2,0,0), 10, 11);
TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (dateStart, dateEnd, new TimeSpan (55), daylightTransitionStart, daylightTransitionEnd);
}
}
[TestFixture]
public class NonExceptional
{
[Test]
public void Serialization_Deserialization ()
{
TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,1,0,0), 3, 5, DayOfWeek.Sunday);
TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1,1,1,2,0,0), 10, 5, DayOfWeek.Sunday);
TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule (DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan (1,0,0), start, end);
MemoryStream stream = new MemoryStream ();
BinaryFormatter formatter = new BinaryFormatter ();
formatter.Serialize (stream, rule);
stream.Position = 0;
TimeZoneInfo.AdjustmentRule deserialized = (TimeZoneInfo.AdjustmentRule) formatter.Deserialize (stream);
stream.Close ();
stream.Dispose ();
Assert.IsTrue (rule.Equals (deserialized));
}
}
}
}
#endif
|