public virtual void ShouldParseTextToDateTime()
        {
            // culture is internal, need to test with a known culture.
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();
                Assert.IsTrue(strategy.ActualCulture.Name == "en-US", "This test should run under en-US culture, setting did not work as expected.");

                TimeParserCollection parsers = new TimeParserCollection {
                    new CustomTimeParser()
                };

                Assert.AreEqual(DateTime.Today.Date.AddHours(8).AddMinutes(30), strategy.ParseTime("8:30 AM", new ShortTimeFormat(), parsers));
                Assert.AreEqual(DateTime.Today.Date.AddHours(20).AddMinutes(30), strategy.ParseTime("8:30 PM", new ShortTimeFormat(), parsers));

                Assert.AreEqual(DateTime.Today.Date.AddHours(8).AddMinutes(30).AddSeconds(12), strategy.ParseTime("8:30:12 AM", new LongTimeFormat(), parsers));
                Assert.AreEqual(DateTime.Today.Date.AddHours(20).AddMinutes(30).AddSeconds(12), strategy.ParseTime("8:30:12 PM", new LongTimeFormat(), parsers));

                Assert.AreEqual(DateTime.Today.Date.AddHours(8).AddMinutes(30).AddSeconds(12), strategy.ParseTime("08:30:12", new CustomTimeFormat("hh:mm:ss"), parsers));

                Assert.AreEqual(DateTime.MinValue.Date.AddHours(15).AddMinutes(40), strategy.ParseTime("3 uur 40", new CustomTimeFormat("hh:mm:ss"), parsers));
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }
 public virtual void ShouldThrowExceptionDuringDeterminingTimeUnit()
 {
     OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();
     strategy.ParseTime("4:12:22 AM", null, null);
 }
 public virtual void ShouldThrowExceptionDuringParseIfFormatIsNull()
 {
     OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();
     strategy.ParseTime("4:12 AM", null, null);
 }
 public virtual void ShouldThrowExceptionDuringParse()
 {
     OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();
     strategy.ParseTime("cannot parse this", new LongTimeFormat(), null);
 }
        public virtual void ShouldParseTextToDateTime()
        {
            // culture is internal, need to test with a known culture.
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();
                Assert.IsTrue(strategy.ActualCulture.Name == "en-US", "This test should run under en-US culture, setting did not work as expected.");

                TimeParserCollection parsers = new TimeParserCollection { new CustomTimeParser() };

                Assert.AreEqual(DateTime.Today.Date.AddHours(8).AddMinutes(30), strategy.ParseTime("8:30 AM", new ShortTimeFormat(), parsers));
                Assert.AreEqual(DateTime.Today.Date.AddHours(20).AddMinutes(30), strategy.ParseTime("8:30 PM", new ShortTimeFormat(), parsers));

                Assert.AreEqual(DateTime.Today.Date.AddHours(8).AddMinutes(30).AddSeconds(12), strategy.ParseTime("8:30:12 AM", new LongTimeFormat(), parsers));
                Assert.AreEqual(DateTime.Today.Date.AddHours(20).AddMinutes(30).AddSeconds(12), strategy.ParseTime("8:30:12 PM", new LongTimeFormat(), parsers));

                Assert.AreEqual(DateTime.Today.Date.AddHours(8).AddMinutes(30).AddSeconds(12), strategy.ParseTime("08:30:12", new CustomTimeFormat("hh:mm:ss"), parsers));

                Assert.AreEqual(DateTime.MinValue.Date.AddHours(15).AddMinutes(40), strategy.ParseTime("3 uur 40", new CustomTimeFormat("hh:mm:ss"), parsers));
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }
        public virtual void ShouldThrowExceptionDuringDeterminingTimeUnit()
        {
            OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();

            strategy.ParseTime("4:12:22 AM", null, null);
        }
        public virtual void ShouldThrowExceptionDuringParseIfFormatIsNull()
        {
            OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();

            strategy.ParseTime("4:12 AM", null, null);
        }
        public virtual void ShouldThrowExceptionDuringParse()
        {
            OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo();

            strategy.ParseTime("cannot parse this", new LongTimeFormat(), null);
        }