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 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 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 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] ); }