예제 #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 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 ) );
        }
예제 #3
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 )
            {
            }
        }
예제 #4
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 )
            {
            }
        }
예제 #5
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 ){}
		}
예제 #6
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 ){}
        }