public void ParseDateAsUtc_with_defaultvalue_returns_defaultValue_when_it_fails_to_parse_a_date_using_a_format_provider() { // Arrange var formatProvider = new CustomDateTimeFormatProvider(); var defaultDateTime = DateTime.Now; var dateTimeString = "Not a datetime string"; // Act var parsedDateTime = dateTimeString.ParseDateAsUtc(formatProvider, defaultDateTime); // Assert parsedDateTime.Kind.ShouldBe(DateTimeKind.Utc); parsedDateTime.Year.ShouldBe(defaultDateTime.Year); parsedDateTime.Month.ShouldBe(defaultDateTime.Month); parsedDateTime.Day.ShouldBe(defaultDateTime.Day); parsedDateTime.Hour.ShouldBe(defaultDateTime.Hour); parsedDateTime.Minute.ShouldBe(defaultDateTime.Minute); parsedDateTime.Second.ShouldBe(defaultDateTime.Second); parsedDateTime.Millisecond.ShouldBe(defaultDateTime.Millisecond); }
public void ParseDateAsUtc_with_defaultvalue_returns_can_parse_a_date_using_a_format_provider() { // Arrange var formatProvider = new CustomDateTimeFormatProvider(); var defaultDateTime = DateTime.Now.Subtract(TimeSpan.FromDays(60)); var theDateTime = DateTime.Now; var dateTimeString = theDateTime.ToString(CustomDateTimeFormatProvider.FormatString); // Act var parsedDateTime = dateTimeString.ParseDateAsUtc(formatProvider, defaultDateTime); // Assert parsedDateTime.Kind.ShouldBe(DateTimeKind.Utc); parsedDateTime.Year.ShouldBe(theDateTime.Year); parsedDateTime.Month.ShouldBe(theDateTime.Month); parsedDateTime.Day.ShouldBe(theDateTime.Day); parsedDateTime.Hour.ShouldBe(theDateTime.Hour); parsedDateTime.Minute.ShouldBe(theDateTime.Minute); parsedDateTime.Second.ShouldBe(theDateTime.Second); parsedDateTime.Millisecond.ShouldBe(0); }
public void ParseDateAsUtc_can_parse_a_date_using_a_format_provider() { // Arrange var formatProvider = new CustomDateTimeFormatProvider(); var theDateTime = DateTime.Now; var dateTimeString = theDateTime.ToString(CustomDateTimeFormatProvider.FormatString); // Act var parsedDateTime = dateTimeString.ParseDateAsUtc(formatProvider); // Assert theDateTime.Kind.ShouldBe(DateTimeKind.Local); parsedDateTime.Kind.ShouldBe(DateTimeKind.Utc); parsedDateTime.Year.ShouldBe(theDateTime.Year); parsedDateTime.Month.ShouldBe(theDateTime.Month); parsedDateTime.Day.ShouldBe(theDateTime.Day); parsedDateTime.Hour.ShouldBe(theDateTime.Hour); parsedDateTime.Minute.ShouldBe(theDateTime.Minute); parsedDateTime.Second.ShouldBe(theDateTime.Second); parsedDateTime.Millisecond.ShouldBe(0); }