public void ToStringShouldLeverageCustomFormatterWhenSupplied()
 {
     var provider = new DateTimeFormatProvider();
     var target = new DateTime( 2010, 9, 30 );
     var actual = target.ToString( provider, "%q" );
     Assert.Equal( "3", actual );
 }
        public void FormatShouldReturnCorrectCustomStringFormatContainingEscapeSequence()
        {
            // arrange
            var provider = new DateTimeFormatProvider( new GregorianFiscalCalendar( 7 ) );
            var date = new DateTime( 2010, 9, 29 );
            var expected = "FY'11";

            // act
            var actual = provider.Format( "'FY'\\'yy", date, null );

            Assert.Equal( expected, actual );
        }
        public void FormatShouldReturnCorrectCustomFormatStringWithCustomCalendar( Func<DateTime, DateTimeFormatProvider, string> test, string expected )
        {
            // arrange
            var date = new DateTime( 2010, 9, 29 );
            var provider = new DateTimeFormatProvider( new GregorianFiscalCalendar( 7 ) );

            // act
            var actual = test( date, provider );

            // assert
            Assert.Equal( expected, actual );
        }
        public void StringFormatShouldReturnCorrectCustomFormatStringWithMultipleFormatParameters( DateTimeFormatProvider provider, string format, object arg, string expected )
        {
            // arrange
            var date = new DateTime( 2010, 9, 29 );
            var args = new object[] { date, arg };

            // act
            var actual = string.Format( provider, format, args );

            // assert
            Assert.Equal( expected, actual );
        }
        public void FormatShouldReturnCorrectBuiltInCustomFormatString( DateTimeFormatProvider provider, string format )
        {
            // arrange
            var date = new DateTime( 2010, 9, 29 );
            var expected = date.ToString( format );

            // act
            var actual = provider.Format( format, date, null );

            // assert
            Assert.Equal( expected, actual );
        }
        public void FormatShouldReturnCorrectQuarterFormatString( DateTimeFormatProvider provider, string format, string expected )
        {
            // arrange
            var date = new DateTime( 2010, 9, 29 );

            // act
            var actual = provider.Format( format, date, null );

            // assert
            Assert.Equal( expected, actual );
        }
        public void FormatShouldNotAllowMalformedLiteralStrings( DateTimeFormatProvider provider, string format )
        {
            // arrange
            var date = new DateTime( 2010, 9, 29 );

            // act and assert
            Assert.Throws<FormatException>( () => provider.Format( format, date, null ) );
        }
        public void FormatShouldReturnOriginalStringFormatWhenArgumentCannotBeFormatted( DateTimeFormatProvider provider )
        {
            // arrange
            var expected = new string[] { "d", new object().ToString() };
            var actual = new string[2];
            var culture = CultureInfo.CurrentCulture;

            // act
            actual[0] = provider.Format( "d", null, culture );
            actual[1] = provider.Format( "d", new object(), culture );

            // assert
            Assert.Equal( expected[0], actual[0] );
            Assert.Equal( expected[1], actual[1] );
        }
        public void FormatShouldAllowNullOrEmptyFormatString( DateTimeFormatProvider provider )
        {
            // arrange
            var date = new DateTime( 2010, 9, 29 );
            var culture = CultureInfo.CurrentCulture;
            var expected = date.ToString( culture );
            var actual = new string[2];

            // act
            actual[0] = provider.Format( null, date, culture );
            actual[1] = provider.Format( string.Empty, date, culture );

            // assert
            Assert.Equal( expected, actual[0] );
            Assert.Equal( expected, actual[1] );
        }
        public void GetFormatShouldReturnCorrectFormatProvider( DateTimeFormatProvider provider, Type formatType, object expected )
        {
            // arrange

            // act
            var actual = provider.GetFormat( formatType );

            // assert
            Assert.Same( expected, actual );
        }
        public void GetFormatShouldReturnNullForUnsupportedFormatTypes( DateTimeFormatProvider provider, Type formatType )
        {
            // arrange

            // act
            var actual = provider.GetFormat( formatType );

            // assert
            Assert.Null( actual );
        }