public void ConvertFromStringTest() { var converter = new BooleanConverter(); Assert.True( (bool)converter.ConvertFromString( "true" ) ); Assert.True( (bool)converter.ConvertFromString( "True" ) ); Assert.True( (bool)converter.ConvertFromString( "TRUE" ) ); Assert.True( (bool)converter.ConvertFromString( "1" ) ); Assert.True( (bool)converter.ConvertFromString( "yes" ) ); Assert.True( (bool)converter.ConvertFromString( "YES" ) ); Assert.True( (bool)converter.ConvertFromString( "y" ) ); Assert.True( (bool)converter.ConvertFromString( "Y" ) ); Assert.True( (bool)converter.ConvertFromString( " true " ) ); Assert.True( (bool)converter.ConvertFromString( " yes " ) ); Assert.True( (bool)converter.ConvertFromString( " y " ) ); Assert.False( (bool)converter.ConvertFromString( "false" ) ); Assert.False( (bool)converter.ConvertFromString( "False" ) ); Assert.False( (bool)converter.ConvertFromString( "FALSE" ) ); Assert.False( (bool)converter.ConvertFromString( "0" ) ); Assert.True( (bool)converter.ConvertFromString( "no" ) ); Assert.True( (bool)converter.ConvertFromString( "NO" ) ); Assert.True( (bool)converter.ConvertFromString( "n" ) ); Assert.True( (bool)converter.ConvertFromString( "N" ) ); Assert.False( (bool)converter.ConvertFromString( " false " ) ); Assert.False( (bool)converter.ConvertFromString( " 0 " ) ); Assert.True( (bool)converter.ConvertFromString( " no " ) ); Assert.True( (bool)converter.ConvertFromString( " n " ) ); Assert.Throws<NotSupportedException>( () => converter.ConvertFromString( null ) ); }
public void ConvertToStringTest() { var converter = new BooleanConverter(); Assert.Equal( "True", converter.ConvertToString( true ) ); Assert.Equal( "False", converter.ConvertToString( false ) ); Assert.Equal( "", converter.ConvertToString( null ) ); Assert.Equal( "1", converter.ConvertToString( 1 ) ); }
public void ConvertToStringTest() { var converter = new BooleanConverter(); Assert.AreEqual( "True", converter.ConvertToString( CultureInfo.CurrentCulture, true ) ); Assert.AreEqual( "False", converter.ConvertToString( CultureInfo.CurrentCulture, false ) ); Assert.AreEqual( "", converter.ConvertToString( CultureInfo.CurrentCulture, null ) ); Assert.AreEqual( "1", converter.ConvertToString( CultureInfo.CurrentCulture, 1 ) ); }
public void ConvertToStringTest() { var converter = new BooleanConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; Assert.AreEqual( "True", converter.ConvertToString( typeConverterOptions, true ) ); Assert.AreEqual( "False", converter.ConvertToString( typeConverterOptions, false ) ); Assert.AreEqual( "", converter.ConvertToString( typeConverterOptions, null ) ); Assert.AreEqual( "1", converter.ConvertToString( typeConverterOptions, 1 ) ); }
public void ConvertToStringTest() { var converter = new BooleanConverter(); var propertyMapData = new CsvPropertyMapData( null ) { TypeConverter = converter, TypeConverterOptions = { CultureInfo = CultureInfo.CurrentCulture } }; Assert.AreEqual( "True", converter.ConvertToString( true, null, propertyMapData ) ); Assert.AreEqual( "False", converter.ConvertToString( false, null, propertyMapData ) ); Assert.AreEqual( "", converter.ConvertToString( null, null, propertyMapData ) ); Assert.AreEqual( "1", converter.ConvertToString( 1, null, propertyMapData ) ); }
public void ConvertFromStringTest() { var converter = new BooleanConverter(); var typeConverterOptions = new TypeConverterOptions { CultureInfo = CultureInfo.CurrentCulture }; Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "true" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "True" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "TRUE" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "1" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "yes" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "YES" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "y" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, "Y" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, " true " ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, " yes " ) ); Assert.IsTrue( (bool)converter.ConvertFromString( typeConverterOptions, " y " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "false" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "False" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "FALSE" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "0" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "no" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "NO" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "n" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, "N" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, " false " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, " 0 " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, " no " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( typeConverterOptions, " n " ) ); try { converter.ConvertFromString( typeConverterOptions, null ); Assert.Fail(); } catch( CsvTypeConverterException ) { } }
public void ConvertFromStringTest() { var converter = new BooleanConverter(); var propertyMapData = new CsvPropertyMapData( null ); propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture; Assert.IsTrue( (bool)converter.ConvertFromString( "true", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "True", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "TRUE", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "1", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "yes", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "YES", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "y", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "Y", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( " true ", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( " yes ", null, propertyMapData ) ); Assert.IsTrue( (bool)converter.ConvertFromString( " y ", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "false", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "False", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "FALSE", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "0", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "no", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "NO", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "n", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "N", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " false ", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " 0 ", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " no ", null, propertyMapData ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " n ", null, propertyMapData ) ); try { converter.ConvertFromString( null, null, propertyMapData ); Assert.Fail(); } catch( CsvTypeConverterException ) { } }
public void ConvertFromStringTest() { var converter = new BooleanConverter(); Assert.IsTrue( (bool)converter.ConvertFromString( "true" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "True" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "TRUE" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "1" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "yes" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "YES" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "y" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( "Y" ) ); Assert.IsTrue( (bool)converter.ConvertFromString( " true " ) ); Assert.IsTrue( (bool)converter.ConvertFromString( " yes " ) ); Assert.IsTrue( (bool)converter.ConvertFromString( " y " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "false" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "False" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "FALSE" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "0" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "no" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "NO" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "n" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( "N" ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " false " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " 0 " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " no " ) ); Assert.IsFalse( (bool)converter.ConvertFromString( " n " ) ); try { converter.ConvertFromString( null ); Assert.Fail(); } catch( NotSupportedException ) { } }