예제 #1
0
        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 )
            {
            }
        }
예제 #2
0
        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 ) );
        }
예제 #3
0
        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 ) );
        }
예제 #4
0
        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 ) );
        }
예제 #5
0
        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 ) );
        }
예제 #6
0
        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 ){}
        }
예제 #7
0
        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 )
            {
            }
        }
예제 #8
0
        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 )
            {
            }
        }
예제 #9
0
        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 ){}
        }