public void ConvertFrom()
 {
     var tsc = new TimeSpanConverter();
     var timeSpan = tsc.ConvertFrom("1000");
     Assert.IsNotNull(timeSpan);
     Assert.IsTrue(timeSpan is TimeSpan);
     Assert.AreEqual(TimeSpan.Parse("1000"), (TimeSpan) timeSpan);
 }
 public void BaseConvertFrom()
 {
     var tsc = new TimeSpanConverter();
     var timeSpan = tsc.ConvertFrom("00:00:10");
     Assert.IsNotNull(timeSpan);
     Assert.IsTrue(timeSpan is TimeSpan);
     Assert.AreEqual(TimeSpan.FromSeconds(10), (TimeSpan) timeSpan);
 }
Esempio n. 3
0
 /// <summary>
 /// Registers standard and configured type converters.
 /// </summary>
 static TypeConverterRegistry()
 {
     lock (_syncRoot)
     {
         _converters[typeof(string[])]            = new StringArrayConverter();
         _converters[typeof(Type)]                = new RuntimeTypeConverter();
         _converters[typeof(Uri)]                 = new UriConverter();
         _converters[typeof(FileInfo)]            = new FileInfoConverter();
         _converters[typeof(NameValueCollection)] = new NameValueConverter();
         _converters[typeof(Regex)]               = new RegexConverter();
         _converters[typeof(TimeSpan)]            = new TimeSpanConverter();
     }
 }
 public void ConvertFromNullReference()
 {
     try
     {
         var tsc = new TimeSpanConverter();
         tsc.ConvertFrom(null);
     }
     catch (NotSupportedException)
     {
         //.net throws NotSupportedException
         if (SystemUtils.MonoRuntime)
         {
             Assert.Fail("NotSupportedException not expected on mono");
         }
     }
     catch (NullReferenceException)
     {
         //mono throws NullReferenceException
         if (!SystemUtils.MonoRuntime)
         {
             Assert.Fail("NRE not expected on .net");
         }
     }
 }
 public void ConvertFromStringMalformed()
 {
     var tsc = new TimeSpanConverter();
     tsc.ConvertFrom("15a");
 }
 public void ConvertFromNonSupportedOptionBails()
 {
     var tsc = new TimeSpanConverter();
     tsc.ConvertFrom(12);
 }
 public void ConvertFromStringWithSecondSpecifier()
 {
     var tsc = new TimeSpanConverter();
     var timeSpan = tsc.ConvertFrom("10s");
     Assert.IsNotNull(timeSpan);
     Assert.IsTrue(timeSpan is TimeSpan);
     Assert.AreEqual(TimeSpan.FromSeconds(10), (TimeSpan) timeSpan);
 }
 public void ConvertFromStringWithMinuteSpecifier()
 {
     var tsc = new TimeSpanConverter();
     var timeSpan = tsc.ConvertFrom("2m");
     Assert.IsNotNull(timeSpan);
     Assert.IsTrue(timeSpan is TimeSpan);
     Assert.AreEqual(TimeSpan.FromMinutes(2), (TimeSpan) timeSpan);
 }
        public void ConvertFromStringWithHourSpecifier()
        {
            var tsc = new TimeSpanConverter();

            var timeSpan = tsc.ConvertFrom("1H");
            Assert.IsNotNull(timeSpan);
            Assert.IsTrue(timeSpan is TimeSpan);
            Assert.AreEqual(TimeSpan.FromHours(1), (TimeSpan) timeSpan);

            tsc.ConvertFrom("1h");
            Assert.IsNotNull(timeSpan);
            Assert.IsTrue(timeSpan is TimeSpan);
            Assert.AreEqual(TimeSpan.FromHours(1), (TimeSpan) timeSpan);
        }