public void ConvertFromStringTest() { var converter = new DateTimeConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; var dateTime = DateTime.Now; // Valid conversions. Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( typeConverterOptions, dateTime.ToString() ).ToString() ); Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( typeConverterOptions, dateTime.ToString( "o" ) ).ToString() ); Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( typeConverterOptions, " " + dateTime + " " ).ToString() ); // Invalid conversions. try { converter.ConvertFromString( typeConverterOptions, null ); Assert.Fail(); } catch( CsvTypeConverterException ) { } }
public void ConvertFromStringTest() { var converter = new DateTimeConverter(); var dateTime = DateTime.Now; // Valid conversions. Assert.Equal( dateTime.ToString(), converter.ConvertFromString( dateTime.ToString() ).ToString() ); Assert.Equal( dateTime.ToString(), converter.ConvertFromString( dateTime.ToString( "o" ) ).ToString() ); Assert.Equal( dateTime.ToString(), converter.ConvertFromString( " " + dateTime + " " ).ToString() ); // Invalid conversions. Assert.Throws<NotSupportedException>( () => converter.ConvertFromString( null ) ); }
public void ConvertFromStringTest() { var converter = new DateTimeConverter(); var dateTime = DateTime.Now; // Valid conversions. Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( dateTime.ToString() ).ToString() ); Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( dateTime.ToString( "o" ) ).ToString() ); Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( " " + dateTime + " " ).ToString() ); // Invalid conversions. try { converter.ConvertFromString( null ); Assert.Fail(); } catch( NotSupportedException ) { } }
public void ConvertFromStringTest() { var converter = new DateTimeConverter(); var propertyMapData = new CsvPropertyMapData( null ); propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture; var dateTime = DateTime.Now; // Valid conversions. Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( dateTime.ToString(), null, propertyMapData ).ToString() ); Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( dateTime.ToString( "o" ), null, propertyMapData ).ToString() ); Assert.AreEqual( dateTime.ToString(), converter.ConvertFromString( " " + dateTime + " ", null, propertyMapData ).ToString() ); // Invalid conversions. try { converter.ConvertFromString( null, null, propertyMapData ); Assert.Fail(); } catch( CsvTypeConverterException ) { } }
public void ComponentModelCompatibilityTest() { var converter = new DateTimeConverter(); var cmConverter = new System.ComponentModel.DateTimeConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; var val = (DateTime)cmConverter.ConvertFromString( "" ); Assert.AreEqual( DateTime.MinValue, val ); val = (DateTime)converter.ConvertFromString( typeConverterOptions, "" ); Assert.AreEqual( DateTime.MinValue, val ); try { cmConverter.ConvertFromString( null ); Assert.Fail(); } catch( NotSupportedException ){} try { converter.ConvertFromString( typeConverterOptions, null ); Assert.Fail(); } catch( CsvTypeConverterException ) { } try { cmConverter.ConvertFromString( "blah" ); Assert.Fail(); } catch( FormatException ){} try { converter.ConvertFromString( typeConverterOptions, "blah" ); } catch( FormatException ){} }
public void ComponentModelCompatibilityTest() { var converter = new DateTimeConverter(); var cmConverter = new System.ComponentModel.DateTimeConverter(); var propertyMapData = new CsvPropertyMapData( null ); propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture; try { cmConverter.ConvertFromString( null ); Assert.Fail(); } catch( NotSupportedException ){} try { converter.ConvertFromString( null, null, propertyMapData ); Assert.Fail(); } catch( CsvTypeConverterException ) { } try { cmConverter.ConvertFromString( "blah" ); Assert.Fail(); } catch( FormatException ){} try { converter.ConvertFromString( "blah", null, propertyMapData ); } catch( FormatException ){} }