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 ConvertToStringTest() { var converter = new DateTimeConverter(); var dateTime = DateTime.Now; // Valid conversions. Assert.AreEqual( dateTime.ToString(), converter.ConvertToString( dateTime ) ); // Invalid conversions. Assert.AreEqual( "1", converter.ConvertToString( 1 ) ); Assert.AreEqual( "", converter.ConvertToString( null ) ); }
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 ConvertToStringTest() { var converter = new DateTimeConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; var dateTime = DateTime.Now; // Valid conversions. Assert.AreEqual( dateTime.ToString(), converter.ConvertToString( typeConverterOptions, dateTime ) ); // Invalid conversions. Assert.AreEqual( "1", converter.ConvertToString( typeConverterOptions, 1 ) ); Assert.AreEqual( "", converter.ConvertToString( typeConverterOptions, null ) ); }
public void ConvertToStringTest() { var converter = new DateTimeConverter(); var propertyMapData = new CsvPropertyMapData( null ) { TypeConverter = converter, TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture } }; var dateTime = DateTime.Now; // Valid conversions. Assert.AreEqual( dateTime.ToString(), converter.ConvertToString( dateTime, null, propertyMapData ) ); // Invalid conversions. Assert.AreEqual( "1", converter.ConvertToString( 1, null, propertyMapData ) ); Assert.AreEqual( "", converter.ConvertToString( null, null, propertyMapData ) ); }
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 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 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 ){} }