public void SmtpDate_TryParseTimeZoneString_WithValidShortHand_ShouldReturnCorrectOffset()
        {
            TimeSpan span;

            Assert.True(SmtpDateTime.TryParseTimeZoneString("GMT", out span));
            Assert.Equal(TimeSpan.Zero, span);
        }
Beispiel #2
0
        public void SmtpDate_TryParseTimeZoneString_WithUnknownShortHand_ShouldReturnFalse()
        {
            var      smtpDt = new SmtpDateTime(DateTime.Now);
            TimeSpan span;

            Assert.False(smtpDt.TryParseTimeZoneString("ABCD", out span));
        }
Beispiel #3
0
        public void SmtpDate_TryParseTimeZoneString_WithInvalidShortHand_ShouldThrowException()
        {
            var      smtpDt = new SmtpDateTime(DateTime.Now);
            TimeSpan span;

            Assert.Throws <FormatException>(() => smtpDt.TryParseTimeZoneString("7mGTE", out span));
        }
 public void SmtpDate_TimeSpanToOffset_WithNonGmtOffset_ShouldConvertCorrectly()
 {
     Assert.Equal("-0800", SmtpDateTime.TimeSpanToOffset(new TimeSpan(-8, 0, 0)));
     Assert.Equal("-1000", SmtpDateTime.TimeSpanToOffset(new TimeSpan(-10, 0, 0)));
     Assert.Equal("+1000", SmtpDateTime.TimeSpanToOffset(new TimeSpan(10, 0, 0)));
     Assert.Equal("+0400", SmtpDateTime.TimeSpanToOffset(new TimeSpan(4, 0, 0)));
 }
Beispiel #5
0
        public void SmtpDateTime_WithDateThatHasKindSetToLocal_ShouldSetTimeZoneCorrectly()
        {
            var date   = new DateTime(2008, 1, 1, 12, 00, 00, DateTimeKind.Local);
            var smtpDt = new SmtpDateTime(date);

            Assert.Equal(date, smtpDt.Date);
        }
Beispiel #6
0
        public void SmtpDateTime_WithDateThatHasUnspecifiedKind_ShouldSetTimeZoneCorrectly()
        {
            DateTime date = new DateTime(2008, 1, 1, 12, 00, 00, DateTimeKind.Unspecified);
            var smtpDt = new SmtpDateTime(date);

            Assert.Equal(date, smtpDt.Date);
            Assert.Equal(DateTimeKind.Unspecified, smtpDt.Date.Kind);
        }
 public void SmtpDateTime_InvalidInput_ShouldThrowException(string input)
 {
     Assert.Throws <FormatException>(() =>
     {
         string timeZoneOffset;
         DateTime results = SmtpDateTime.ParseValue(input, out timeZoneOffset);
     });
 }
        public void SmtpDateTime_WithInvalidTimeZone_ShouldParseDateCorrectly()
        {
            string   timeZoneOffset;
            DateTime result = SmtpDateTime.ParseValue(InvalidDateStringWithInvalidTimeZone, out timeZoneOffset);

            Assert.Equal("7M-Gte", timeZoneOffset);
            Assert.Equal(new DateTime(2009, 5, 17, 15, 34, 07), result);
        }
        public void SmtpDate_TimeSpanToOffset_ShouldConvertCorrectly()
        {
            TimeSpan timeZone         = TimeZoneInfo.Utc.GetUtcOffset(DateTime.Now);
            string   timeZoneToString = timeZone.ToString();
            string   result           = SmtpDateTime.TimeSpanToOffset(timeZone);

            Assert.Equal("+0000", result);
        }
Beispiel #10
0
        public void SmtpDateTime_WithDateThatHasUnspecifiedKind_ShouldSetTimeZoneCorrectly()
        {
            DateTime date   = new DateTime(2008, 1, 1, 12, 00, 00, DateTimeKind.Unspecified);
            var      smtpDt = new SmtpDateTime(date);

            Assert.Equal(date, smtpDt.Date);
            Assert.Equal(DateTimeKind.Unspecified, smtpDt.Date.Kind);
        }
Beispiel #11
0
        public void SmtpDateTime_WithInvalidTimeZone_ShouldParseDateCorrectly()
        {
            var smtpDt = new SmtpDateTime(DateTime.Now);
            string timeZoneOffset;
            DateTime result = smtpDt.ParseValue(InvalidDateStringWithInvalidTimeZone, out timeZoneOffset);

            Assert.Equal("7M-Gte", timeZoneOffset);
            Assert.Equal(new DateTime(2009, 5, 17, 15, 34, 07), result);
        }
Beispiel #12
0
 public void SmtpDateTime_InvalidInput_ShouldThrowException(string input)
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     Assert.Throws<FormatException>(() =>
     {
         string timeZoneOffset;
         DateTime results = smtpDt.ParseValue(input, out timeZoneOffset);
     });
 }
Beispiel #13
0
        public void SmtpDate_ValidateTimeZoneOffsetValue_WithValidAndInvalidOffsets_ShouldReturnCorrectly()
        {
            bool positive;
            int  hours;
            int  minutes;

            SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("+0000", out positive, out hours, out minutes);
            SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("+9959", out positive, out hours, out minutes);
            SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("-9959", out positive, out hours, out minutes);
            SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("+0900", out positive, out hours, out minutes);

            Assert.Throws <FormatException>(() => SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("+0080", out positive, out hours, out minutes));
            Assert.Throws <FormatException>(() => SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("+-0045", out positive, out hours, out minutes));
            Assert.Throws <FormatException>(() => SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("+10000", out positive, out hours, out minutes));
            Assert.Throws <FormatException>(() => SmtpDateTime.ValidateAndGetTimeZoneOffsetValues("-A000", out positive, out hours, out minutes));
        }
Beispiel #14
0
        public void SmtpDateTime_CreatedFromDateTimeString_ShouldParseCorrectly(
            string input,
            int expectedYear, int expectedMonth, int expectedDay,
            int expectedHour, int expectedMinut, int expectedSecond,
            string expectedTimeZoneOffset,
            DateTimeKind expectedKind)
        {
            DateTime result = SmtpDateTime.ParseValue(input, out string timeZoneOffset);

            Assert.Equal(expectedYear, result.Year);
            Assert.Equal(expectedMonth, result.Month);
            Assert.Equal(expectedDay, result.Day);
            Assert.Equal(expectedHour, result.Hour);
            Assert.Equal(expectedMinut, result.Minute);
            Assert.Equal(expectedSecond, result.Second);
            Assert.Equal(expectedKind, result.Kind);
            Assert.Equal(expectedTimeZoneOffset, timeZoneOffset);
        }
Beispiel #15
0
        public void SmtpDateTime_CreatedFromDateTimeString_ShouldParseCorrectly(
            string input,
            int expectedYear, int expectedMonth, int expectedDay,
            int expectedHour, int expectedMinut, int expectedSecond,
            string expectedTimeZoneOffset, DateTimeKind expectedKind)
        {
            var smtpDt = new SmtpDateTime(DateTime.Now);

            string   timeZoneOffset;
            DateTime result = smtpDt.ParseValue(ValidDateStringWithKnownShortHandTimeZone, out timeZoneOffset);

            Assert.Equal(expectedYear, result.Year);
            Assert.Equal(expectedMonth, result.Month);
            Assert.Equal(expectedDay, result.Day);
            Assert.Equal(expectedHour, result.Hour);
            Assert.Equal(expectedMinut, result.Minute);
            Assert.Equal(expectedSecond, result.Second);
            Assert.Equal(expectedTimeZoneOffset, timeZoneOffset);
        }
Beispiel #16
0
        public void SmtpDate_TryParseTimeZoneString_WithUnknownShortHand_ShouldReturnFalse()
        {
            TimeSpan span;

            Assert.False(SmtpDateTime.TryParseTimeZoneString("ABCD", out span));
        }
Beispiel #17
0
 public void SmtpDate_TimeSpanToOffset_WithNonGmtOffset_ShouldConvertCorrectly()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     Assert.Equal("-0800", smtpDt.TimeSpanToOffset(new TimeSpan(-8, 0, 0)));
     Assert.Equal("-1000", smtpDt.TimeSpanToOffset(new TimeSpan(-10, 0, 0)));
     Assert.Equal("+1000", smtpDt.TimeSpanToOffset(new TimeSpan(10, 0, 0)));
     Assert.Equal("+0400", smtpDt.TimeSpanToOffset(new TimeSpan(4, 0, 0)));
 }
Beispiel #18
0
        public void SmtpDate_ValidateTimeZoneShortHandValue_WithInvalidShortHand_ShouldReturnFalse()
        {
            var smtpDt = new SmtpDateTime(DateTime.Now);

            Assert.Throws <FormatException>(() => smtpDt.ValidateTimeZoneShortHandValue("7M-GTE"));
        }
Beispiel #19
0
 public void SmtpDate_ToString_ShouldOutputCorrectDateString()
 {
     var smtpDt = new SmtpDateTime(s_validDateStringDateTimeEquivalent);
     Assert.Equal(ValidDateStringDateTimeEquivalentString, smtpDt.ToString());
 }
Beispiel #20
0
        public void SmtpDate_ToString_ShouldOutputCorrectDateString()
        {
            var smtpDt = new SmtpDateTime(s_validDateStringDateTimeEquivalent);

            Assert.Equal(ValidDateStringDateTimeEquivalentString, smtpDt.ToString());
        }
Beispiel #21
0
        public void SmtpDate_ValidateTimeZoneShortHandValue_WithValidShortHand_ShouldReturnTrue()
        {
            var smtpDt = new SmtpDateTime(DateTime.Now);

            smtpDt.ValidateTimeZoneShortHandValue("GMT");
        }
Beispiel #22
0
 public void SmtpDateTime_WithDateThatHasKindSetToLocal_ShouldSetTimeZoneCorrectly()
 {
     var date = new DateTime(2008, 1, 1, 12, 00, 00, DateTimeKind.Local);
     var smtpDt = new SmtpDateTime(date);
     Assert.Equal(date, smtpDt.Date);
 }
Beispiel #23
0
        public void SmtpDateTime_CreatedFromDateTimeString_ShouldParseCorrectly(
            string input,
            int expectedYear, int expectedMonth, int expectedDay, 
            int expectedHour, int expectedMinut, int expectedSecond,
            string expectedTimeZoneOffset, DateTimeKind expectedKind)
        {
            var smtpDt = new SmtpDateTime(DateTime.Now);

            string timeZoneOffset;
            DateTime result = smtpDt.ParseValue(ValidDateStringWithKnownShortHandTimeZone, out timeZoneOffset);

            Assert.Equal(expectedYear, result.Year);
            Assert.Equal(expectedMonth, result.Month);
            Assert.Equal(expectedDay, result.Day);
            Assert.Equal(expectedHour, result.Hour);
            Assert.Equal(expectedMinut, result.Minute);
            Assert.Equal(expectedSecond, result.Second);
            Assert.Equal(expectedTimeZoneOffset, timeZoneOffset);
        }
Beispiel #24
0
 public void SmtpDate_ValidateTimeZoneShortHandValue_WithInvalidShortHand_ShouldReturnFalse()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     Assert.Throws<FormatException>(() => smtpDt.ValidateTimeZoneShortHandValue("7M-GTE"));
 }
Beispiel #25
0
 public void SmtpDate_ValidateTimeZoneShortHandValue_WithValidShortHand_ShouldReturnTrue()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     smtpDt.ValidateTimeZoneShortHandValue("GMT");
 }
Beispiel #26
0
        public void SmtpDate_ValidateTimeZoneOffsetValue_WithValidAndInvalidOffsets_ShouldReturnCorrectly()
        {
            var smtpDt = new SmtpDateTime(DateTime.Now);

            bool positive;
            int hours;
            int minutes;

            smtpDt.ValidateAndGetTimeZoneOffsetValues("+0000", out positive, out hours, out minutes);
            smtpDt.ValidateAndGetTimeZoneOffsetValues("+9959", out positive, out hours, out minutes);
            smtpDt.ValidateAndGetTimeZoneOffsetValues("-9959", out positive, out hours, out minutes);
            smtpDt.ValidateAndGetTimeZoneOffsetValues("+0900", out positive, out hours, out minutes);

            Assert.Throws<FormatException>(() => smtpDt.ValidateAndGetTimeZoneOffsetValues("+0080", out positive, out hours, out minutes));
            Assert.Throws<FormatException>(() => smtpDt.ValidateAndGetTimeZoneOffsetValues("+-0045", out positive, out hours, out minutes));
            Assert.Throws<FormatException>(() => smtpDt.ValidateAndGetTimeZoneOffsetValues("+10000", out positive, out hours, out minutes));
            Assert.Throws<FormatException>(() => smtpDt.ValidateAndGetTimeZoneOffsetValues("-A000", out positive, out hours, out minutes));
        }
Beispiel #27
0
 public void SmtpDate_TryParseTimeZoneString_WithInvalidShortHand_ShouldThrowException()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     TimeSpan span;
     Assert.Throws<FormatException>(() => smtpDt.TryParseTimeZoneString("7mGTE", out span));
 }
Beispiel #28
0
 public void SmtpDate_TryParseTimeZoneString_WithUnknownShortHand_ShouldReturnFalse()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     TimeSpan span;
     Assert.False(smtpDt.TryParseTimeZoneString("ABCD", out span));
 }
Beispiel #29
0
 public void SmtpDate_ValidateTimeZoneShortHandValue_WithInvalidShortHand_ShouldReturnFalse()
 {
     Assert.Throws <FormatException>(() => SmtpDateTime.ValidateTimeZoneShortHandValue("7M-GTE"));
 }
Beispiel #30
0
 public void SmtpDate_TimeSpanToOffset_ShouldConvertCorrectly()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     TimeSpan timeZone = TimeZoneInfo.Utc.GetUtcOffset(DateTime.Now);
     string timeZoneToString = timeZone.ToString();
     string result = smtpDt.TimeSpanToOffset(timeZone);
     Assert.Equal("+0000", result);
 }
Beispiel #31
0
 public void SmtpDate_TryParseTimeZoneString_WithValidShortHand_ShouldReturnCorrectOffset()
 {
     var smtpDt = new SmtpDateTime(DateTime.Now);
     TimeSpan span;
     Assert.True(smtpDt.TryParseTimeZoneString("GMT", out span));
     Assert.Equal(TimeSpan.Zero, span);
 }
Beispiel #32
0
 public void SmtpDate_ValidateTimeZoneShortHandValue_WithValidShortHand_ShouldReturnTrue()
 {
     SmtpDateTime.ValidateTimeZoneShortHandValue("GMT");
 }