public void ComponentModelCompatibilityTest() { var converter = new TimeSpanConverter(); var cmConverter = new System.ComponentModel.TimeSpanConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; try { cmConverter.ConvertFromString(""); Assert.Fail(); } catch (FormatException) { } try { converter.ConvertFromExcel(typeConverterOptions, ""); Assert.Fail(); } catch (ExcelTypeConverterException) { } try { cmConverter.ConvertFromString(null); Assert.Fail(); } catch (NotSupportedException) { } try { converter.ConvertFromExcel(typeConverterOptions, null); Assert.Fail(); } catch (ExcelTypeConverterException) { } }
public void ConvertFromExcelTest() { var converter = new TimeSpanConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; var dateTime = DateTime.Now; var timeSpan = new TimeSpan(dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond); var timeString = timeSpan.ToString(); // Valid conversions. Assert.AreEqual(timeString, converter.ConvertFromExcel(typeConverterOptions, timeSpan.ToString()).ToString()); Assert.AreEqual(timeString, converter.ConvertFromExcel(typeConverterOptions, " " + timeSpan + " ").ToString()); // Invalid conversions. try { converter.ConvertFromExcel(typeConverterOptions, null); Assert.Fail(); } catch (ExcelTypeConverterException) { } }