1 2 using System; 3 using System.IO; 4 using System.Runtime.Serialization.Formatters.Binary; 5 using NUnit.Framework; 6 7 namespace MonoTests.System 8 { 9 public class TimeZoneInfo_TransitionTimeTest 10 { 11 [TestFixture] 12 public class CreateFixedDateRuleExceptions 13 { 14 [Test] 15 [ExpectedException (typeof (ArgumentException))] DateHasNonDefaultComponent()16 public void DateHasNonDefaultComponent () 17 { 18 TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 10, 2, 0, 0), 3, 15); 19 } 20 21 [Test] 22 [ExpectedException (typeof (ArgumentException))] KindNotUnspecified()23 public void KindNotUnspecified() 24 { 25 TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1, 2, 0, 0, DateTimeKind.Utc), 3, 15); 26 } 27 28 [Test] 29 [ExpectedException (typeof (ArgumentException))] DateNotInMilliSeconds()30 public void DateNotInMilliSeconds () 31 { 32 TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (50), 3, 15); 33 } 34 35 [Test] 36 [ExpectedException (typeof (ArgumentOutOfRangeException))] MonthOutOfRange()37 public void MonthOutOfRange () 38 { 39 TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1, 2, 0, 0), 13, 15); 40 } 41 42 [Test] 43 [ExpectedException (typeof (ArgumentOutOfRangeException))] DayOutOfRange()44 public void DayOutOfRange () 45 { 46 TimeZoneInfo.TransitionTime.CreateFixedDateRule (new DateTime (1, 1, 1, 2, 0, 0), 3, -2); 47 } 48 } 49 50 [TestFixture] 51 public class CreateFloatingDateRuleExceptions 52 { 53 [Test] 54 [ExpectedException (typeof (ArgumentException))] DateHasNonDefaultComponent()55 public void DateHasNonDefaultComponent () 56 { 57 TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 10, 2, 0, 0), 3, 4, DayOfWeek.Sunday); 58 } 59 60 [Test] 61 [ExpectedException (typeof (ArgumentException))] KindNotUnspecified()62 public void KindNotUnspecified() 63 { 64 TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0, DateTimeKind.Utc), 3, 4, DayOfWeek.Sunday); 65 } 66 67 [Test] 68 [ExpectedException (typeof (ArgumentException))] DateNotInSeconds()69 public void DateNotInSeconds () 70 { 71 TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (50), 3, 4, DayOfWeek.Sunday); 72 } 73 74 [Test] 75 [ExpectedException (typeof (ArgumentOutOfRangeException))] MonthOutOfRange()76 public void MonthOutOfRange () 77 { 78 TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 13, 4, DayOfWeek.Sunday); 79 } 80 81 [Test] 82 [ExpectedException (typeof (ArgumentOutOfRangeException))] WeekOutOfRange()83 public void WeekOutOfRange () 84 { 85 TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 3, -2, DayOfWeek.Sunday); 86 } 87 88 [Test] 89 [ExpectedException (typeof (ArgumentOutOfRangeException))] DayOfWeekOutOfRange()90 public void DayOfWeekOutOfRange () 91 { 92 TimeZoneInfo.TransitionTime.CreateFloatingDateRule (new DateTime (1, 1, 1, 2, 0, 0), 3, 4, (DayOfWeek)12); 93 } 94 } 95 96 [TestFixture] 97 public class NonExceptional { 98 99 [Test] EqualsObject()100 public void EqualsObject () 101 { 102 DateTime dt = new DateTime (1, 1, 1, 2, 0, 0, DateTimeKind.Unspecified); 103 TimeZoneInfo.TransitionTime tt1 = TimeZoneInfo.TransitionTime.CreateFixedDateRule (dt, 1, 21); 104 Assert.IsFalse (tt1.Equals (null), "null"); // found using Gendarme :) 105 Assert.IsTrue (tt1.Equals (tt1), "self"); 106 TimeZoneInfo.TransitionTime tt2 = TimeZoneInfo.TransitionTime.CreateFixedDateRule (dt, 2, 12); 107 Assert.IsFalse (tt2.Equals (tt1), "1!=2"); 108 Assert.IsFalse (tt1.Equals (tt2), "2!=1"); 109 } 110 111 [Test] Serialize_Deserialize_FloatingDateRule()112 public void Serialize_Deserialize_FloatingDateRule () 113 { 114 TimeZoneInfo.TransitionTime floatingDateRule = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 1, 0, 0), 3, 5, DayOfWeek.Sunday); 115 MemoryStream stream = new MemoryStream (); 116 BinaryFormatter formatter = new BinaryFormatter (); 117 formatter.Serialize (stream, floatingDateRule); 118 stream.Position = 0; 119 TimeZoneInfo.TransitionTime deserialized = (TimeZoneInfo.TransitionTime) formatter.Deserialize (stream); 120 stream.Close (); 121 stream.Dispose (); 122 Assert.AreEqual (floatingDateRule, deserialized); 123 } 124 125 [Test] Serialize_Deserialize_FixedDateRule()126 public void Serialize_Deserialize_FixedDateRule () 127 { 128 TimeZoneInfo.TransitionTime fixedDateRule = TimeZoneInfo.TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 1, 0, 0), 3, 12); 129 MemoryStream stream = new MemoryStream (); 130 BinaryFormatter formatter = new BinaryFormatter (); 131 formatter.Serialize (stream, fixedDateRule); 132 stream.Position = 0; 133 TimeZoneInfo.TransitionTime deserialized = (TimeZoneInfo.TransitionTime) formatter.Deserialize (stream); 134 stream.Close (); 135 stream.Dispose (); 136 Assert.AreEqual (fixedDateRule, deserialized); 137 } 138 } 139 } 140 } 141